Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
postcss-reduce-idents
Advanced tools
The postcss-reduce-idents package is a PostCSS plugin that reduces the size of CSS by minimizing identifier names. It specifically targets keyframes and counter styles, renaming them to shorter identifiers to save space.
Reduce Keyframe Identifiers
This feature reduces the length of keyframe identifiers. In the example, the keyframe name 'longAnimationName' will be shortened to a more compact identifier.
const postcss = require('postcss');
const reduceIdents = require('postcss-reduce-idents');
const css = `
@keyframes longAnimationName {
from { opacity: 0; }
to { opacity: 1; }
}
.element {
animation: longAnimationName 1s;
}`;
postcss([reduceIdents()])
.process(css, { from: undefined })
.then(result => {
console.log(result.css);
});
Reduce Counter Style Identifiers
This feature reduces the length of counter style identifiers. In the example, the counter style name 'longCounterName' will be shortened to a more compact identifier.
const postcss = require('postcss');
const reduceIdents = require('postcss-reduce-idents');
const css = `
@counter-style longCounterName {
system: numeric;
symbols: \2022;
}
ol {
list-style: longCounterName;
}`;
postcss([reduceIdents()])
.process(css, { from: undefined })
.then(result => {
console.log(result.css);
});
cssnano is a modular minifier that optimizes CSS for production. It includes a variety of plugins, including one for reducing identifier names, making it a more comprehensive solution compared to postcss-reduce-idents.
clean-css is a fast and efficient CSS optimizer that can minify CSS files. While it does not specifically target identifier reduction, it provides a broad range of optimizations that can reduce the overall size of CSS files.
csso (CSS Optimizer) is a CSS minifier that performs structural optimizations. It can reduce the size of CSS files by merging rules, removing redundant properties, and more. It offers a different approach to optimization compared to postcss-reduce-idents.
Reduce custom identifiers with PostCSS.
With npm do:
npm install postcss-reduce-idents --save
This module will rename custom identifiers in your CSS files; it does so by converting each name to a index, which is then encoded into a legal identifier. A legal custom identifier in CSS is case sensitive and must start with a letter, but can contain digits, hyphens and underscores. There are over 3,000 possible two character identifiers, and 51 possible single character identifiers that will be generated.
@keyframes whiteToBlack {
0% {
color: #fff
}
to {
color: #000
}
}
.one {
animation-name: whiteToBlack
}
@keyframes a {
0% {
color: #fff
}
to {
color: #000
}
}
.one {
animation-name: a
}
Note that this module does not handle identifiers that are not linked together. The following example will not be transformed in any way:
@keyframes fadeOut {
0% { opacity: 1 }
to { opacity: 0 }
}
.fadeIn {
animation-name: fadeIn;
}
It works for @keyframes
, @counter-style
, custom counter
values and grid area definitions. See the
documentation for more information, or the tests for more
examples.
See the PostCSS documentation for examples for your environment.
Type: boolean
Default: true
Pass false
to disable reducing content
, counter-reset
and counter-increment
declarations.
Type: boolean
Default: true
Pass false
to disable reducing keyframes
rules and animation
declarations.
Type: boolean
Default: true
Pass false
to disable reducing counter-style
rules and list-style
and system
declarations.
Type: boolean
Default: true
Pass false
to disable reducing grid-template
, grid-area
and grid-template-areas
declarations.
Type: function
Default: lib/encode.js
Pass a custom function to encode the identifier with (e.g.: as a way of prefixing them automatically).
It receives two parameters:
String
with the node value.Number
identifying the index of the occurrence.See CONTRIBUTORS.md.
MIT © Ben Briggs
FAQs
Reduce custom identifiers with PostCSS.
The npm package postcss-reduce-idents receives a total of 644,897 weekly downloads. As such, postcss-reduce-idents popularity was classified as popular.
We found that postcss-reduce-idents demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.