
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
modify-selectors
Advanced tools
Post CSS plugin to modify CSS selectors, you can replace, modify or simply add a prefix and suffix. You can match a selector using a simple string compare, a regular expression and even a function.
$ npm i modify-selectors --save-dev
const postcss = require("postcss");
postcss([
require("modify-selectors")({
enable: true,
replace: [
{
match: 'body',
with: '.replacedBody',
},
{
match: /wrapper|wrapperContainer/,
with: '.container',
}
],
modify: [],
prefix: [],
modify: [],
})
]).process(cssCode).then((result) => {
console.log(result.css);
});
When your CSS file is processed PostCSS loops all selectors in the file so you can modify them. Please take a looks at the examples below to learn how to check for selectors.
/*Imagine you have the following CSS code*/
html {
color: red;
}
body {
font-size: 12px;
}
.container {
max-width: 960px;
}
match: '*', // it matches every single selector
match: 'body', // match the body selector
match: /html|body/, // you can use a regular expression, this will match html and body
match: (selector) => {
// you can use a function to verify the selector, if it returns true, the selector will be processed
return selector.includes(':hover');
},
You can replace selectors completely, for example:
postcss([
require("modify-selectors")({
enable: true,
replace: [
{
match: 'body',
with: '.replacedBody', //body will be replaced with .replacedBody
},
{
match: 'textarea',
with: 'textarea.small', //textarea will be replaced with textarea.small
}
],
})
]).process(cssCode).then((result) => {
console.log(result.css);
});
You can modify selectors, for example:
postcss([
require("modify-selectors")({
enable: true,
modify: [
{
match: '*', // run in every selector
with: (selector) => {
return selector.replace('::before', '::after')
},
},
{
match: (selector) => {
// or run in selectors with :hover
return selector.includes(':hover');
},
with: (selector) => {
return selector.replace('::before', '::after')
},
},
],
})
]).process(cssCode).then((result) => {
console.log(result.css);
});
postcss([
require("modify-selectors")({
enable: true,
prefix: [
{
match: '*',
with: '.myapp', // every selector will be prefixed with .myapp, for example: .myapp h1, .myapp p, etc.
},
],
})
]).process(cssCode).then((result) => {
console.log(result.css);
});
postcss([
require("modify-selectors")({
enable: true,
suffix: [
{
match: '*',
with: ' > *', // every selector will be suffixed with > *, for example: ul li > *
},
],
})
]).process(cssCode).then((result) => {
console.log(result.css);
});
FAQs
PostCSS plugin to modify CSS selectors
We found that modify-selectors 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.