Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-reduce-idents

Package Overview
Dependencies
Maintainers
8
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-reduce-idents - npm Package Compare versions

Comparing version 4.0.2 to 5.0.0-rc.0

CHANGELOG.md

75

dist/index.js

@@ -1,55 +0,48 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = void 0;
var _postcss = require('postcss');
var _encode = _interopRequireDefault(require("./lib/encode"));
var _postcss2 = _interopRequireDefault(_postcss);
var _counter = _interopRequireDefault(require("./lib/counter"));
var _encode = require('./lib/encode');
var _counterStyle = _interopRequireDefault(require("./lib/counter-style"));
var _encode2 = _interopRequireDefault(_encode);
var _keyframes = _interopRequireDefault(require("./lib/keyframes"));
var _counter = require('./lib/counter');
var _gridTemplate = _interopRequireDefault(require("./lib/grid-template"));
var _counter2 = _interopRequireDefault(_counter);
var _counterStyle = require('./lib/counter-style');
var _counterStyle2 = _interopRequireDefault(_counterStyle);
var _keyframes = require('./lib/keyframes');
var _keyframes2 = _interopRequireDefault(_keyframes);
var _gridTemplate = require('./lib/grid-template');
var _gridTemplate2 = _interopRequireDefault(_gridTemplate);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = _postcss2.default.plugin('postcss-reduce-idents', ({
counter = true,
counterStyle = true,
keyframes = true,
gridTemplate = true,
encoder = _encode2.default
} = {}) => {
const reducers = [];
function pluginCreator({
counter = true,
counterStyle = true,
keyframes = true,
gridTemplate = true,
encoder = _encode.default
} = {}) {
const reducers = [];
counter && reducers.push((0, _counter.default)());
counterStyle && reducers.push((0, _counterStyle.default)());
keyframes && reducers.push((0, _keyframes.default)());
gridTemplate && reducers.push((0, _gridTemplate.default)());
return {
postcssPlugin: 'postcss-reduce-idents',
counter && reducers.push((0, _counter2.default)());
counterStyle && reducers.push((0, _counterStyle2.default)());
keyframes && reducers.push((0, _keyframes2.default)());
gridTemplate && reducers.push((0, _gridTemplate2.default)());
OnceExit(css) {
css.walk(node => {
reducers.forEach(reducer => reducer.collect(node, encoder));
});
reducers.forEach(reducer => reducer.transform());
}
return css => {
css.walk(node => {
reducers.forEach(reducer => reducer.collect(node, encoder));
});
};
}
reducers.forEach(reducer => reducer.transform());
};
});
module.exports = exports['default'];
pluginCreator.postcss = true;
var _default = pluginCreator;
exports.default = _default;
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = _default;
exports.default = function (value, encoder, cache) {
if (cache[value]) {
return;
}
function _default(value, encoder, cache) {
if (cache[value]) {
return;
}
cache[value] = {
ident: encoder(value, Object.keys(cache).length),
count: 0
};
};
cache[value] = {
ident: encoder(value, Object.keys(cache).length),
count: 0
};
}
module.exports = exports["default"];
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = _default;
exports.default = function () {
let cache = {};
let atRules = [];
let decls = [];
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
return {
collect(node, encoder) {
const { name, prop, type } = node;
var _cache = _interopRequireDefault(require("./cache"));
if (type === 'atrule' && /counter-style/i.test(name) && RESERVED_KEYWORDS.indexOf(node.params.toLowerCase()) === -1) {
(0, _cache2.default)(node.params, encoder, cache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
atRules.push(node);
}
const RESERVED_KEYWORDS = ['unset', 'initial', 'inherit', 'none', 'inline', 'outside', 'disc', 'circle', 'square', 'decimal', 'cjk-decimal', 'decimal-leading-zero', 'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha', 'lower-latin', 'upper-alpha', 'upper-latin', 'arabic-indic', 'armenian', 'bengali', 'cambodian', 'cjk-earthly-branch', 'cjk-heavenly-stem', 'cjk-ideographic', 'devanagari', 'ethiopic-numeric', 'georgian', 'gujarati', 'gurmukhi', 'hebrew', 'hiragana', 'hiragana-iroha', 'japanese-formal', 'japanese-informal', 'kannada', 'katakana', 'katakana-iroha', 'khmer', 'korean-hangul-formal', 'korean-hanja-formal', 'korean-hanja-informal', 'lao', 'lower-armenian', 'malayalam', 'mongolian', 'myanmar', 'oriya', 'persian', 'simp-chinese-formal', 'simp-chinese-informal', 'tamil', 'telugu', 'thai', 'tibetan', 'trad-chinese-formal', 'trad-chinese-informal', 'upper-armenian', 'disclosure-open', 'disclosure-close'];
if (type === 'decl' && /(list-style|system)/i.test(prop)) {
decls.push(node);
}
},
function _default() {
let cache = {};
let atRules = [];
let decls = [];
return {
collect(node, encoder) {
const {
name,
prop,
type
} = node;
transform() {
// Iterate each property and change their names
decls.forEach(decl => {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(node => {
if (node.type === 'word' && node.value in cache) {
cache[node.value].count++;
if (type === 'atrule' && /counter-style/i.test(name) && RESERVED_KEYWORDS.indexOf(node.params.toLowerCase()) === -1) {
(0, _cache.default)(node.params, encoder, cache);
atRules.push(node);
}
node.value = cache[node.value].ident;
}
}).toString();
});
if (type === 'decl' && /(list-style|system)/i.test(prop)) {
decls.push(node);
}
},
// Iterate each at rule and change their name if references to them have been found
atRules.forEach(rule => {
const cached = cache[rule.params];
transform() {
// Iterate each property and change their names
decls.forEach(decl => {
decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => {
if (node.type === 'word' && node.value in cache) {
cache[node.value].count++;
node.value = cache[node.value].ident;
}
}).toString();
}); // Iterate each at rule and change their name if references to them have been found
if (cached && cached.count > 0) {
rule.params = cached.ident;
}
});
atRules.forEach(rule => {
const cached = cache[rule.params];
// reset cache after transform
atRules = [];
decls = [];
if (cached && cached.count > 0) {
rule.params = cached.ident;
}
};
};
}); // reset cache after transform
var _postcssValueParser = require("postcss-value-parser");
atRules = [];
decls = [];
}
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
};
}
var _cache = require("./cache");
var _cache2 = _interopRequireDefault(_cache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const RESERVED_KEYWORDS = ["unset", "initial", "inherit", "none", "inline", "outside", "disc", "circle", "square", "decimal", "cjk-decimal", "decimal-leading-zero", "lower-roman", "upper-roman", "lower-greek", "lower-alpha", "lower-latin", "upper-alpha", "upper-latin", "arabic-indic", "armenian", "bengali", "cambodian", "cjk-earthly-branch", "cjk-heavenly-stem", "cjk-ideographic", "devanagari", "ethiopic-numeric", "georgian", "gujarati", "gurmukhi", "hebrew", "hiragana", "hiragana-iroha", "japanese-formal", "japanese-informal", "kannada", "katakana", "katakana-iroha", "khmer", "korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal", "lao", "lower-armenian", "malayalam", "mongolian", "myanmar", "oriya", "persian", "simp-chinese-formal", "simp-chinese-informal", "tamil", "telugu", "thai", "tibetan", "trad-chinese-formal", "trad-chinese-informal", "upper-armenian", "disclosure-open", "disclosure-close"];
module.exports = exports["default"];
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = _default;
exports.default = function () {
let cache = {};
let declOneCache = [];
let declTwoCache = [];
var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
return {
collect(node, encoder) {
const { prop, type } = node;
var _cache = _interopRequireDefault(require("./cache"));
if (type !== 'decl') {
return;
}
var _isNum = _interopRequireDefault(require("./isNum"));
if (/counter-(reset|increment)/i.test(prop)) {
node.value = (0, _postcssValueParser2.default)(node.value).walk(child => {
if (child.type === 'word' && !(0, _isNum2.default)(child) && RESERVED_KEYWORDS.indexOf(child.value.toLowerCase()) === -1) {
(0, _cache2.default)(child.value, encoder, cache);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
child.value = cache[child.value].ident;
}
});
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
declOneCache.push(node);
} else if (/content/i.test(prop)) {
declTwoCache.push(node);
}
},
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
transform() {
declTwoCache.forEach(decl => {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(node => {
const { type } = node;
const RESERVED_KEYWORDS = ['unset', 'initial', 'inherit', 'none'];
const value = node.value.toLowerCase();
function _default() {
let cache = {};
let declOneCache = [];
let declTwoCache = [];
return {
collect(node, encoder) {
const {
prop,
type
} = node;
if (type === 'function' && (value === 'counter' || value === 'counters')) {
(0, _postcssValueParser.walk)(node.nodes, child => {
if (child.type === 'word' && child.value in cache) {
cache[child.value].count++;
if (type !== 'decl') {
return;
}
child.value = cache[child.value].ident;
}
});
}
if (/counter-(reset|increment)/i.test(prop)) {
node.value = (0, _postcssValueParser.default)(node.value).walk(child => {
if (child.type === 'word' && !(0, _isNum.default)(child) && RESERVED_KEYWORDS.indexOf(child.value.toLowerCase()) === -1) {
(0, _cache.default)(child.value, encoder, cache);
child.value = cache[child.value].ident;
}
});
declOneCache.push(node);
} else if (/content/i.test(prop)) {
declTwoCache.push(node);
}
},
if (type === 'space') {
node.value = ' ';
}
transform() {
declTwoCache.forEach(decl => {
decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => {
const {
type
} = node;
const value = node.value.toLowerCase();
return false;
}).toString();
if (type === 'function' && (value === 'counter' || value === 'counters')) {
(0, _postcssValueParser.walk)(node.nodes, child => {
if (child.type === 'word' && child.value in cache) {
cache[child.value].count++;
child.value = cache[child.value].ident;
}
});
}
declOneCache.forEach(decl => {
decl.value = decl.value.walk(node => {
if (node.type === 'word' && !(0, _isNum2.default)(node)) {
Object.keys(cache).forEach(key => {
const cached = cache[key];
if (type === 'space') {
node.value = ' ';
}
if (cached.ident === node.value && !cached.count) {
node.value = key;
}
});
}
}).toString();
return false;
}).toString();
});
declOneCache.forEach(decl => {
decl.value = decl.value.walk(node => {
if (node.type === 'word' && !(0, _isNum.default)(node)) {
Object.keys(cache).forEach(key => {
const cached = cache[key];
if (cached.ident === node.value && !cached.count) {
node.value = key;
}
});
}
}).toString();
}); // reset cache after transform
// reset cache after transform
declOneCache = [];
declTwoCache = [];
}
};
};
declOneCache = [];
declTwoCache = [];
}
var _postcssValueParser = require("postcss-value-parser");
};
}
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _cache = require("./cache");
var _cache2 = _interopRequireDefault(_cache);
var _isNum = require("./isNum");
var _isNum2 = _interopRequireDefault(_isNum);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const RESERVED_KEYWORDS = ["unset", "initial", "inherit", "none"];
module.exports = exports["default"];
module.exports = exports.default;

@@ -1,26 +0,30 @@

'use strict';
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = encode;
function encode(val, num) {
let base = 52;
let characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let character = num % base;
let result = characters[character];
let remainder = Math.floor(num / base);
let base = 52;
let characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let character = num % base;
let result = characters[character];
let remainder = Math.floor(num / base);
if (remainder) {
base = 64;
characters = characters + '0123456789-_';
while (remainder) {
character = remainder % base;
remainder = Math.floor(remainder / base);
result = result + characters[character];
}
if (remainder) {
base = 64;
characters = characters + '0123456789-_';
while (remainder) {
remainder--;
character = remainder % base;
remainder = Math.floor(remainder / base);
result = result + characters[character];
}
}
return result;
};
module.exports = exports['default'];
return result;
}
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = _default;
exports.default = function () {
let cache = {};
let declCache = [];
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
return {
collect(node, encoder) {
if (node.type !== 'decl') {
return;
}
var _cache = _interopRequireDefault(require("./cache"));
if (/(grid-template|grid-template-areas)/i.test(node.prop)) {
(0, _postcssValueParser2.default)(node.value).walk(child => {
if (child.type === 'string') {
child.value.split(/\s+/).forEach(word => {
if (/\.+/.test(word)) {
// reduce empty zones to a single `.`
node.value = node.value.replace(word, ".");
} else if (word && RESERVED_KEYWORDS.indexOf(word.toLowerCase()) === -1) {
(0, _cache2.default)(word, encoder, cache);
}
});
}
});
var _isNum = _interopRequireDefault(require("./isNum"));
declCache.push(node);
} else if (node.prop.toLowerCase() === 'grid-area') {
(0, _postcssValueParser2.default)(node.value).walk(child => {
if (child.type === 'word' && RESERVED_KEYWORDS.indexOf(child.value) === -1) {
(0, _cache2.default)(child.value, encoder, cache);
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
declCache.push(node);
}
},
const RESERVED_KEYWORDS = ['auto', 'span', 'inherit', 'initial', 'unset'];
transform() {
declCache.forEach(decl => {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(node => {
if (/(grid-template|grid-template-areas)/i.test(decl.prop)) {
node.value.split(/\s+/).forEach(word => {
if (word in cache) {
node.value = node.value.replace(word, cache[word].ident);
}
});
node.value = node.value.replace(/\s+/g, " "); // merge white-spaces
}
function _default() {
let cache = {};
let declCache = [];
return {
collect(node, encoder) {
if (node.type !== 'decl') {
return;
}
if (decl.prop.toLowerCase() === 'grid-area' && !(0, _isNum2.default)(node)) {
if (node.value in cache) {
node.value = cache[node.value].ident;
}
}
if (/(grid-template|grid-template-areas)/i.test(node.prop)) {
(0, _postcssValueParser.default)(node.value).walk(child => {
if (child.type === 'string') {
child.value.split(/\s+/).forEach(word => {
if (/\.+/.test(word)) {
// reduce empty zones to a single `.`
node.value = node.value.replace(word, '.');
} else if (word && RESERVED_KEYWORDS.indexOf(word.toLowerCase()) === -1) {
(0, _cache.default)(word, encoder, cache);
}
});
}
});
declCache.push(node);
} else if (node.prop.toLowerCase() === 'grid-area') {
(0, _postcssValueParser.default)(node.value).walk(child => {
if (child.type === 'word' && RESERVED_KEYWORDS.indexOf(child.value) === -1) {
(0, _cache.default)(child.value, encoder, cache);
}
});
declCache.push(node);
}
},
return false;
}).toString();
transform() {
declCache.forEach(decl => {
decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => {
if (/(grid-template|grid-template-areas)/i.test(decl.prop)) {
node.value.split(/\s+/).forEach(word => {
if (word in cache) {
node.value = node.value.replace(word, cache[word].ident);
}
});
node.value = node.value.replace(/\s+/g, ' '); // merge white-spaces
}
// reset cache after transform
declCache = [];
}
};
};
if (decl.prop.toLowerCase() === 'grid-area' && !(0, _isNum.default)(node)) {
if (node.value in cache) {
node.value = cache[node.value].ident;
}
}
var _postcssValueParser = require("postcss-value-parser");
return false;
}).toString();
}); // reset cache after transform
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
declCache = [];
}
var _cache = require("./cache");
};
}
var _cache2 = _interopRequireDefault(_cache);
var _isNum = require("./isNum");
var _isNum2 = _interopRequireDefault(_isNum);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const RESERVED_KEYWORDS = ["auto", "span", "inherit", "initial", "unset"];
module.exports = exports["default"];
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});

@@ -11,4 +11,5 @@ exports.default = isNum;

function isNum(node) {
return (0, _postcssValueParser.unit)(node.value);
return (0, _postcssValueParser.unit)(node.value);
}
module.exports = exports["default"];
module.exports = exports.default;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.default = _default;
exports.default = function () {
let cache = {};
let atRules = [];
let decls = [];
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
return {
collect(node, encoder) {
const { name, prop, type } = node;
var _cache = _interopRequireDefault(require("./cache"));
if (type === 'atrule' && /keyframes/i.test(name) && RESERVED_KEYWORDS.indexOf(node.params.toLowerCase()) === -1) {
(0, _cache2.default)(node.params, encoder, cache);
atRules.push(node);
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (type === 'decl' && /animation/i.test(prop)) {
decls.push(node);
}
},
const RESERVED_KEYWORDS = ['none', 'inherit', 'initial', 'unset'];
transform() {
let referenced = [];
function _default() {
let cache = {};
let atRules = [];
let decls = [];
return {
collect(node, encoder) {
const {
name,
prop,
type
} = node;
// Iterate each property and change their names
decls.forEach(decl => {
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(node => {
if (node.type === 'word' && node.value in cache) {
if (!~referenced.indexOf(node.value)) {
referenced.push(node.value);
}
if (type === 'atrule' && /keyframes/i.test(name) && RESERVED_KEYWORDS.indexOf(node.params.toLowerCase()) === -1) {
(0, _cache.default)(node.params, encoder, cache);
atRules.push(node);
}
cache[node.value].count++;
node.value = cache[node.value].ident;
}
}).toString();
});
if (type === 'decl' && /animation/i.test(prop)) {
decls.push(node);
}
},
// Iterate each at rule and change their name if references to them have been found
atRules.forEach(rule => {
const cached = cache[rule.params];
transform() {
let referenced = []; // Iterate each property and change their names
if (cached && cached.count > 0 && !!~referenced.indexOf(rule.params)) {
rule.params = cached.ident;
}
});
decls.forEach(decl => {
decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => {
if (node.type === 'word' && node.value in cache) {
if (!~referenced.indexOf(node.value)) {
referenced.push(node.value);
}
// reset cache after transform
atRules = [];
decls = [];
}
};
};
cache[node.value].count++;
node.value = cache[node.value].ident;
}
}).toString();
}); // Iterate each at rule and change their name if references to them have been found
var _postcssValueParser = require("postcss-value-parser");
atRules.forEach(rule => {
const cached = cache[rule.params];
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
if (cached && cached.count > 0 && !!~referenced.indexOf(rule.params)) {
rule.params = cached.ident;
}
}); // reset cache after transform
var _cache = require("./cache");
atRules = [];
decls = [];
}
var _cache2 = _interopRequireDefault(_cache);
};
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const RESERVED_KEYWORDS = ["none", "inherit", "initial", "unset"];
module.exports = exports["default"];
module.exports = exports.default;
{
"name": "postcss-reduce-idents",
"version": "4.0.2",
"version": "5.0.0-rc.0",
"description": "Reduce custom identifiers with PostCSS.",

@@ -11,3 +11,5 @@ "main": "dist/index.js",

"scripts": {
"prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
"prebuild": "del-cli dist",
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
"prepublish": "yarn build"
},

@@ -20,6 +22,2 @@ "keywords": [

"license": "MIT",
"devDependencies": {
"babel-cli": "^6.0.0",
"cross-env": "^5.0.0"
},
"homepage": "https://github.com/cssnano/cssnano",

@@ -33,4 +31,3 @@ "author": {

"dependencies": {
"postcss": "^7.0.0",
"postcss-value-parser": "^3.0.0"
"postcss-value-parser": "^4.1.0"
},

@@ -41,4 +38,11 @@ "bugs": {

"engines": {
"node": ">=6.9.0"
}
"node": "^10 || ^12 || >=14.0"
},
"devDependencies": {
"postcss": "^8.2.1"
},
"peerDependencies": {
"postcss": "^8.2.1"
},
"gitHead": "8c16e67a4d24a13ac7e09a36d4faf504196efd0f"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc