
Security News
npm ‘is’ Package Hijacked in Expanding Supply Chain Attack
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
postcss-bem-to-js
Advanced tools
PostCSS plugin generates JavaScript from BEM (including ITCSS / BEMIT) style CSS
Translates CSS classes to a JavaScript file so that you can use typed definitions of styling classes in React / Vue.js etc. It includes support for BEM / ITCSS / BEMIT syntax.
modifiers
into block
and element
strings e.g. my-block--large { ... }
becomes MyBlock.$large === 'my-block my-block--large'
.BEM example (style.css
):
.my-button { /* ... */ }
.my-button--primary { /* ... */ }
.my-button__link { /* ... */ }
.my-button__link--bold { /* ... */ }
.my-button__fancy-icon { /* ... */ }
Outputs style.css.js
(and a .css.json
variant too alongside unmodified input CSS):
module.exports = {
MyButton: {
$primary: 'my-button my-button--primary',
link: {
$bold: 'my-button__link my-button__link--bold',
toString: function () { return 'my-button__link' }
},
fancyIcon: 'my-button__fancy-icon',
toString: function () { return 'my-button' }
},
Grid: {
item: 'grid__item',
toString: function () { return 'grid' }
}
}
Command line example:
postcss --use postcss-bem-to-js ./style.css --config postcss.config.json
And the postcss.config.json
:
{
"postcss-bem-to-js": {
"prefixMap": {
"ln-o-": "o",
"ln-c-": "c",
"ln-u-": "u"
},
"replace": {
"@": "_",
"\\/": "of",
"*": "_x"
}
}
}
A map defining how to replace certain text/symbols in CSS with JavaScript variable naming friendly equivalents e.g.
{
replace: {
'@': '_',
'\\/': 'of',
'*': '_x'
}
}
With this button@wide
becomes button_wide
, grid-1/2
becomes item1of2
, and spacing*2
becomes spacing_x2
.
You can also configure the plugin to accept a prefixMap
to map namespaced (e.g. BEMIT) style naming to some other prefix e.g.
{
prefixMap: {
'o-ns-': 'o',
'c-ns-': 'c',
'u-ns-': 'u'
}
}
Converts o-ns-foo
to oFoo
FAQs
PostCSS plugin generates JavaScript from BEM (including ITCSS / BEMIT) style CSS
The npm package postcss-bem-to-js receives a total of 0 weekly downloads. As such, postcss-bem-to-js popularity was classified as not popular.
We found that postcss-bem-to-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.
Security News
A critical flaw in the popular npm form-data package could allow HTTP parameter pollution, affecting millions of projects until patched versions are adopted.
Security News
Bun 1.2.19 introduces isolated installs for smoother monorepo workflows, along with performance boosts, new tooling, and key compatibility fixes.