Socket
Socket
Sign inDemoInstall

postcss-reduce-idents

Package Overview
Dependencies
5
Maintainers
8
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.1.0 to 5.2.0

4

package.json
{
"name": "postcss-reduce-idents",
"version": "5.1.0",
"version": "5.2.0",
"description": "Reduce custom identifiers with PostCSS.",

@@ -40,3 +40,3 @@ "main": "src/index.js",

},
"readme": "# [postcss][postcss]-reduce-idents\n\n> Reduce [custom identifiers][idents] with PostCSS.\n\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-reduce-idents) do:\n\n```\nnpm install postcss-reduce-idents --save\n```\n\n\n## Example\n\n### Input\n\nThis module will rename custom identifiers in your CSS files; it does so by\nconverting each name to a index, which is then encoded into a legal identifier.\nA legal custom identifier in CSS is case sensitive and must start with a\nletter, but can contain digits, hyphens and underscores. There are over 3,000\npossible two character identifiers, and 51 possible single character identifiers\nthat will be generated.\n\n```css\n@keyframes whiteToBlack {\n 0% {\n color: #fff\n }\n to {\n color: #000\n }\n}\n\n.one {\n animation-name: whiteToBlack\n}\n```\n\n### Output\n\n```css\n@keyframes a {\n 0% {\n color: #fff\n }\n to {\n color: #000\n }\n}\n\n.one {\n animation-name: a\n}\n```\n\nNote that this module does not handle identifiers that are not linked together.\nThe following example will not be transformed in any way:\n\n```css\n@keyframes fadeOut {\n 0% { opacity: 1 }\n to { opacity: 0 }\n}\n\n.fadeIn {\n animation-name: fadeIn;\n}\n```\n\nIt works for `@keyframes`, `@counter-style`, custom `counter` values and grid area definitions. See the\n[documentation][idents] for more information, or the [tests](src/__tests__) for more\nexamples.\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n\n## API\n\n### reduceIdents([options])\n\n#### options\n\n##### counter\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `content`, `counter-reset` and `counter-increment` declarations.\n\n##### keyframes\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `keyframes` rules and `animation` declarations.\n\n##### counterStyle\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `counter-style` rules and `list-style` and `system` declarations.\n\n##### gridTemplate\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `grid-template`, `grid-area` and `grid-template-areas` declarations.\n\n##### encoder\n\nType: `function` \nDefault: [`lib/encode.js`](https://github.com/cssnano/postcss-reduce-idents/blob/master/src/lib/encode.js)\n\nPass a custom function to encode the identifier with (e.g.: as a way of prefixing them automatically).\n\nIt receives two parameters:\n - A `String` with the node value.\n - A `Number` identifying the index of the occurrence.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[idents]: https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident\n\n[postcss]: https://github.com/postcss/postcss\n"
"readme": "# [postcss][postcss]-reduce-idents\n\n> Reduce [custom identifiers][idents] with PostCSS.\n\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-reduce-idents) do:\n\n```\nnpm install postcss-reduce-idents --save\n```\n\n\n## Example\n\n### Input\n\nThis module will rename custom identifiers in your CSS files; it does so by\nconverting each name to a index, which is then encoded into a legal identifier.\nA legal custom identifier in CSS is case sensitive and must start with a\nletter, but can contain digits, hyphens and underscores. There are over 3,000\npossible two character identifiers, and 51 possible single character identifiers\nthat will be generated.\n\n```css\n@keyframes whiteToBlack {\n 0% {\n color: #fff\n }\n to {\n color: #000\n }\n}\n\n.one {\n animation-name: whiteToBlack\n}\n```\n\n### Output\n\n```css\n@keyframes a {\n 0% {\n color: #fff\n }\n to {\n color: #000\n }\n}\n\n.one {\n animation-name: a\n}\n```\n\nNote that this module does not handle identifiers that are not linked together.\nThe following example will not be transformed in any way:\n\n```css\n@keyframes fadeOut {\n 0% { opacity: 1 }\n to { opacity: 0 }\n}\n\n.fadeIn {\n animation-name: fadeIn;\n}\n```\n\nIt works for `@keyframes`, `@counter-style`, custom `counter` values and grid area definitions. See the\n[documentation][idents] for more information, or the [tests](src/__tests__) for more\nexamples.\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n\n## API\n\n### reduceIdents([options])\n\n#### options\n\n##### counter\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `content`, `counter-reset` and `counter-increment` declarations.\n\n##### keyframes\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `keyframes` rules and `animation` declarations.\n\n##### counterStyle\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `counter-style` rules and `list-style` and `system` declarations.\n\n##### gridTemplate\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to disable reducing `grid-template`, `grid-area`, `grid-column`, `grid-row` and `grid-template-areas` declarations.\n\n##### encoder\n\nType: `function` \nDefault: [`lib/encode.js`](https://github.com/cssnano/postcss-reduce-idents/blob/master/src/lib/encode.js)\n\nPass a custom function to encode the identifier with (e.g.: as a way of prefixing them automatically).\n\nIt receives two parameters:\n - A `String` with the node value.\n - A `Number` identifying the index of the occurrence.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[idents]: https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident\n\n[postcss]: https://github.com/postcss/postcss\n"
}

@@ -115,3 +115,3 @@ # [postcss][postcss]-reduce-idents

Pass `false` to disable reducing `grid-template`, `grid-area` and `grid-template-areas` declarations.
Pass `false` to disable reducing `grid-template`, `grid-area`, `grid-column`, `grid-row` and `grid-template-areas` declarations.

@@ -118,0 +118,0 @@ ##### encoder

@@ -14,2 +14,17 @@ 'use strict';

const gridTemplateProperties = new Set([
'grid-template',
'grid-template-areas',
]);
const gridChildProperties = new Set([
'grid-area',
'grid-column',
'grid-row',
'grid-column-start',
'grid-column-end',
'grid-row-start',
'grid-row-end',
]);
/**

@@ -30,3 +45,3 @@ * @return {import('../index.js').Reducer}

if (/(grid-template|grid-template-areas)/i.test(node.prop)) {
if (gridTemplateProperties.has(node.prop.toLowerCase())) {
valueParser(node.value).walk((child) => {

@@ -46,5 +61,8 @@ if (child.type === 'string') {

declCache.push(node);
} else if (node.prop.toLowerCase() === 'grid-area') {
} else if (gridChildProperties.has(node.prop.toLowerCase())) {
valueParser(node.value).walk((child) => {
if (child.type === 'word' && !RESERVED_KEYWORDS.has(child.value)) {
if (
child.type === 'word' &&
!RESERVED_KEYWORDS.has(child.value.toLowerCase())
) {
addToCache(child.value, encoder, cache);

@@ -62,3 +80,3 @@ }

.walk((node) => {
if (/(grid-template|grid-template-areas)/i.test(decl.prop)) {
if (gridTemplateProperties.has(decl.prop.toLowerCase())) {
node.value.split(/\s+/).forEach((word) => {

@@ -72,3 +90,6 @@ if (word in cache) {

if (decl.prop.toLowerCase() === 'grid-area' && !isNum(node)) {
if (
gridChildProperties.has(decl.prop.toLowerCase()) &&
!isNum(node)
) {
if (node.value in cache) {

@@ -75,0 +96,0 @@ node.value = cache[node.value].ident;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc