Scope each css rule with a selector, ie. nest into parent
npm install scope-cssPrefix 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.

``js
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:
`js
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.
`js
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.
`js
scope.replace(
.my-component, .my-other-component {
padding: 0;
}, '$1');
// .my-component, .my-other-component``
Based on this question.