Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
postcss-modules-local-by-default
Advanced tools
A CSS Modules transform to make local scope the default
The postcss-modules-local-by-default npm package is a PostCSS plugin that modifies CSS class names to be locally scoped by default. This is part of CSS Modules, which helps avoid class name collisions and ensures styles are encapsulated to specific components only. It rewrites all class names in CSS files to be scoped locally unless explicitly specified otherwise.
Local Scoping of Class Names
Automatically transforms global CSS class names into locally scoped names. This prevents class name collisions across different components or sections of a web application.
/* Input CSS */
.className {
color: red;
}
/* Output CSS after processing with postcss-modules-local-by-default */
._className_xkpkl_1 {
color: red;
}
Selective Global Scoping
Allows developers to selectively keep some class names global. This is useful for overriding styles or for styles that are meant to be consistent across various components.
/* Input CSS */
:global(.globalClassName) {
color: blue;
}
/* Output CSS remains unchanged */
.globalClassName {
color: blue;
}
Similar to postcss-modules-local-by-default, this package helps in scoping CSS class names locally. However, postcss-modules-scope provides more customizable options for generating scoped names, making it more flexible in projects that require a specific naming convention.
This package is part of the CSS Modules ecosystem and allows sharing values between CSS files, such as variables. While it doesn't handle scoping of class names, it complements postcss-modules-local-by-default by managing shared values, enhancing the modularity of CSS.
Transformation examples:
.foo { ... } /* => */ :local(.foo) { ... }
.foo .bar { ... } /* => */ :local(.foo) :local(.bar) { ... }
/* Shorthand global selector */
:global .foo .bar { ... } /* => */ .foo .bar { ... }
.foo :global .bar { ... } /* => */ :local(.foo) .bar { ... }
/* Targeted global selector */
:global(.foo) .bar { ... } /* => */ .foo :local(.bar) { ... }
.foo:global(.bar) { ... } /* => */ :local(.foo).bar { ... }
.foo :global(.bar) .baz { ... } /* => */ :local(.foo) .bar :local(.baz) { ... }
.foo:global(.bar) .baz { ... } /* => */ :local(.foo).bar :local(.baz) { ... }
$ npm install
$ npm test
MIT
FAQs
A CSS Modules transform to make local scope the default
The npm package postcss-modules-local-by-default receives a total of 11,232,916 weekly downloads. As such, postcss-modules-local-by-default popularity was classified as popular.
We found that postcss-modules-local-by-default demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.