Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Prefix or nest each style selector in a css string. Useful to create namespaced css for components, themes, applications, modular css etc. Also it is tiny.
const scope = require('scope-css');
scope(`
.my-component {}
.my-component-element {}
`, '.parent');
/*
`
.parent .my-component {}
.parent .my-component-element {}
`
*/
Return css string with each rule prefixed with the parent selector. Note that parent
selector itself will be ignored. Also each :host
keyword will be replaced with parent
value. Example:
scope(`
.panel {}
:host {}
:host .my-element {}
.panel .my-element {}
.my-element {}
`, '.panel');
/*
`
.panel {}
.panel {}
.panel .my-element {}
.panel .my-element {}
.panel .my-element {}
`
*/
Options can scope keyframes via { keyframes: bool|prefixStr }
option, eg.
scope(`
.panel {
animation: infinite loading 4s;
}
@keyframes loading {
from { top: 0; }
to { top: 100px; }
}
`, '.panel', { keyframes: true })
/*
`
.panel {
animation: infinite panel-loading 4s;
}
@keyframes panel-loading {
from { top: 0; }
to { top: 100px; }
`)
*/
Apply replace to css, where $1
is matched selectors and $2
is rules for the selectors. It does not do any self/host detection, so use it for more flexible replacements.
scope.replace(`
.my-component, .my-other-component {
padding: 0;
}
`, '$1');
// `.my-component, my-other-component`
Based on this question.
FAQs
Scope each css rule with a selector, ie. nest into parent
The npm package scope-css receives a total of 2,224 weekly downloads. As such, scope-css popularity was classified as popular.
We found that scope-css 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.