@dr/bem-helper
Advanced tools
Comparing version 1.2.4 to 2.0.0-alpha
@@ -1,2 +0,2 @@ | ||
const bem = require("../lib/index"); | ||
import bem from "../index.js"; | ||
@@ -10,3 +10,3 @@ describe("bem", () => { | ||
test("block and element", () => { | ||
expect(bem("block", "element")).toBe("element block__element"); | ||
expect(bem("block", "element")).toBe("block__element"); | ||
}); | ||
@@ -48,17 +48,17 @@ | ||
test("block and element with modifier", () => { | ||
expect(bem("block", "element", {modifier: true})).toBe("element block__element element--modifier block__element--modifier"); | ||
expect(bem("block", "element", {modifier: true})).toBe("block__element block__element--modifier"); | ||
}); | ||
test("block and element with multiple modifiers", () => { | ||
expect(bem("block", "element", {modifier1: true, modifier2: "value"})).toBe("element block__element element--modifier1 block__element--modifier1 element--modifier2-value block__element--modifier2-value"); | ||
expect(bem("block", "element", {modifier1: true, modifier2: "value"})).toBe("block__element block__element--modifier1 block__element--modifier2-value"); | ||
}); | ||
test("block with modifier and element", () => { | ||
expect(bem("block", {modifier: true}, "element")).toBe("element block__element block--modifier__element"); | ||
expect(bem("block", {modifier: true}, "element")).toBe("block__element block--modifier__element"); | ||
}); | ||
test("block with modifier and element with modifier", () => { | ||
expect(bem("block", {modifier: true}, "element", {modifier: true})).toBe("element block__element block--modifier__element element--modifier block__element--modifier block--modifier__element--modifier"); | ||
expect(bem("block", {modifier: true}, "element", {modifier: true})).toBe("block__element block--modifier__element block__element--modifier block--modifier__element--modifier"); | ||
}); | ||
}); |
@@ -8,1 +8,10 @@ # Changelog | ||
* bem.scoped | ||
## v2.0.0 | ||
### Features | ||
* The package is now an ESM module. | ||
* `bem.unscoped` and `bem.single` was deprecated. | ||
* `bem.scoped` is now just `bem` - the default export. | ||
* Added the `bemStyles` function to make BEM classnames from CSS module styles. |
{ | ||
"name": "@dr/bem-helper", | ||
"version": "1.2.4", | ||
"version": "2.0.0-alpha", | ||
"description": "Helper functions to create BEM-style classnames", | ||
"main": "lib/index.js", | ||
"type": "module", | ||
"main": "./index.js", | ||
"scripts": { | ||
"test": "jest --no-watchman", | ||
"build": "babel src -d lib", | ||
"prepublish": "npm run build && npm test", | ||
"flow": "flow check" | ||
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --no-watchman --config=./config.json", | ||
"prepublish": "npm test" | ||
}, | ||
@@ -21,3 +20,6 @@ "repository": { | ||
], | ||
"author": "Rasmus Fløe <rasmusfl0e@gmail.com>", | ||
"author": { | ||
"name": "phloe", | ||
"email": "mail@phloe.industries" | ||
}, | ||
"license": "ISC", | ||
@@ -29,10 +31,4 @@ "bugs": { | ||
"devDependencies": { | ||
"babel-cli": "^6.22.2", | ||
"babel-jest": "^19.0.0", | ||
"babel-plugin-transform-flow-comments": "^6.22.0", | ||
"babel-polyfill": "^6.22.0", | ||
"babel-preset-es2015": "^6.22.0", | ||
"flow-bin": "^0.44.2", | ||
"jest": "^19.0.2" | ||
"jest": "^28.1.0" | ||
} | ||
} |
113
README.md
@@ -17,14 +17,6 @@ # bem-helper | ||
var bem = require("@dr/bem-helper"); | ||
import bem from "@dr/bem-helper"; | ||
var className = bem("block", "element", { modifier: true }); | ||
// className === "element block__element element--modifier block__element--modifier" | ||
// ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// _____/ _____________________/ | ||
// / / | ||
// bem.scoped -> "block__element block__element--modifier" | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
// ___________/ | ||
// / | ||
// bem.single -> "block__element--modifier" | ||
// className = "block__element block__element--modifier" | ||
@@ -38,8 +30,7 @@ ``` | ||
* [bem](#bem) | ||
* [bem.scoped](#bemscoped) | ||
* [bem.single](#bemsingle) | ||
* [bemStyles](#bemstyles) | ||
### bem | ||
A function that creates all applicable combinations of classnames for an element in BEM-style. | ||
A function that creates all applicable combinations of classnames for an element scoped to a block in BEM-style format. | ||
@@ -60,3 +51,3 @@ #### Arguments | ||
var className = bem("block", "element"); | ||
// className === "element block__element" | ||
// className === "block__element" | ||
@@ -69,4 +60,4 @@ ``` | ||
var className = bem("block", "element", { modifier: true }); | ||
// className === "element block__element element--modifier block__element--modifier" | ||
var className = bem("block", { modifier: true }); | ||
// className === "block block--modifier" | ||
@@ -80,3 +71,3 @@ ``` | ||
var className = bem("block", "element", { modifier: "value", modifier2: false }); | ||
// className === "element block__element element--modifier-value block__element--modifier-value" | ||
// className === "block__element block__element--modifier-value" | ||
@@ -92,47 +83,2 @@ ``` | ||
var className = boundBem("element", { modifier: true }); | ||
// className === "element block__element element--modifier block__element--modifier" | ||
``` | ||
### bem.scoped | ||
Same as [bem](#bem) - but it returns a fully scoped classname. | ||
#### Examples | ||
###### Basic | ||
```js | ||
var className = bem.scoped("block", "element"); | ||
// className === "block__element" | ||
``` | ||
###### Elements with modifiers | ||
```js | ||
var className = bem.scoped("block", { modifier: true }); | ||
// className === "block block--modifier" | ||
``` | ||
###### Modifiers with values | ||
```js | ||
var className = bem.scoped("block", "element", { modifier: "value", modifier2: false }); | ||
// className === "block__element block__element--modifier-value" | ||
``` | ||
###### Prebinding helpers | ||
```js | ||
var boundScoped = bem.scoped.bind(null, "block"); | ||
var className = boundScoped("element", { modifier: true }); | ||
// className === "block__element block__element--modifier" | ||
@@ -142,44 +88,3 @@ | ||
### bem.single | ||
### bemStyles | ||
Same as [bem](#bem) - but it only returns a single classname. | ||
#### Examples | ||
###### Basic | ||
```js | ||
var className = bem.single("block", "element"); | ||
// className === "block__element" | ||
``` | ||
###### Elements with modifiers | ||
```js | ||
var className = bem.single("block", "element", { modifier: true }); | ||
// className === "block__element--modifier" | ||
``` | ||
###### Modifiers with values | ||
```js | ||
var className = bem.single("block", "element", { modifier: "value" }); | ||
// className === "block__element--modifier-value" | ||
``` | ||
###### Prebinding helpers | ||
```js | ||
var boundSingle = bem.single.bind(null, "block"); | ||
var className = boundSingle("element", { modifier: true }); | ||
// className === "block__element--modifier" | ||
``` |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1
Yes
7010
6
103
1
84
2