bem-react-helper
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -7,8 +7,13 @@ # Change Log | ||
## [1.1.1] - 2017-06-30 | ||
### Fixed | ||
- Faulty modification of the `props` object. | ||
## [1.1.0] - 2017-06-29 | ||
### Added | ||
- Support for numberic keys & values for modifiers. | ||
- Support for numeric keys & values for modifiers. | ||
## 1.0.0 - 2017-02-16 | ||
[1.1.1]: https://github.com/igoradamenko/bem-react-helper/compare/v1.1.0...v1.1.1 | ||
[1.1.0]: https://github.com/igoradamenko/bem-react-helper/compare/v1.0.0...v1.1.0 |
57
index.js
'use strict'; | ||
module.exports = function(name, props, defaultMods) { | ||
if (!name) return ''; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
module.exports = b; | ||
exports.default = b; | ||
props = props || {}; | ||
defaultMods = defaultMods || {}; | ||
var mods = props.mods || {}; | ||
var mix = props.mix; | ||
function b(name) { | ||
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var defaultMods = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var result = [name]; | ||
var _props$mix = props.mix, | ||
mix = _props$mix === undefined ? [] : _props$mix, | ||
_props$mods = props.mods, | ||
mods = _props$mods === undefined ? {} : _props$mods; | ||
for (var key in defaultMods) { | ||
if (!mods.hasOwnProperty(key)) mods[key] = defaultMods[key]; | ||
} | ||
var addMod = function addMod(key, value) { | ||
var mod = [name, camelToKebab(key)]; | ||
for (var key in mods) { | ||
if (mods[key]) { | ||
var mod = [name, camelToKebab(key)]; | ||
if (typeof value !== 'boolean') { | ||
mod.push(camelToKebab(value)); | ||
} | ||
if (typeof mods[key] !== 'boolean') { | ||
mod.push(camelToKebab(mods[key])); | ||
} | ||
result.push(mod.join('_')); | ||
}; | ||
result.push(mod.join('_')); | ||
Object.keys(defaultMods).forEach(function (key) { | ||
if (!mods.hasOwnProperty(key) && defaultMods[key]) { | ||
addMod(key, defaultMods[key]); | ||
} | ||
} | ||
}); | ||
Object.keys(mods).forEach(function (key) { | ||
if (mods[key]) { | ||
addMod(key, mods[key]); | ||
} | ||
}); | ||
if (mix) { | ||
if (Array.isArray(mix)) { | ||
mix.forEach(function(item) { | ||
result.push(item); | ||
}); | ||
} else { | ||
result.push(mix); | ||
} | ||
result = result.concat(mix); | ||
} | ||
return result.join(' '); | ||
}; | ||
} | ||
@@ -42,0 +49,0 @@ function camelToKebab(str) { |
{ | ||
"name": "bem-react-helper", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Allows you to easily manage BEM mods & mixes in React", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jasmine" | ||
"dev": "nodemon --exec 'npm run test' --watch bem-react-helper.js --watch tests.js", | ||
"build": "babel bem-react-helper.js -o index.js", | ||
"pretest": "npm run build", | ||
"test": "jasmine", | ||
"prepublish": "npm run test && npm run build" | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"env" | ||
], | ||
"plugins": [ | ||
"transform-object-rest-spread" | ||
] | ||
}, | ||
"repository": { | ||
@@ -30,3 +42,7 @@ "type": "git", | ||
"devDependencies": { | ||
"jasmine": "^2.5.3" | ||
"babel-cli": "^6.24.1", | ||
"babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
"babel-preset-env": "^1.5.2", | ||
"jasmine": "^2.5.3", | ||
"nodemon": "^1.11.0" | ||
}, | ||
@@ -33,0 +49,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7004
39
5