New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

postcss-discard-unused

Package Overview
Dependencies
Maintainers
5
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-discard-unused - npm Package Compare versions

Comparing version 2.2.3 to 4.0.0-nightly.2020.7.24

293

dist/index.js

@@ -1,162 +0,193 @@

'use strict';
"use strict";
exports.__esModule = true;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _uniqs = _interopRequireDefault(require("uniqs"));
var _uniqs = require('uniqs');
var _postcss = require("postcss");
var _uniqs2 = _interopRequireDefault(_uniqs);
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
var _postcss = require('postcss');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var comma = _postcss.list.comma;
var space = _postcss.list.space;
const {
comma,
space
} = _postcss.list;
const atrule = 'atrule';
const decl = 'decl';
const rule = 'rule';
function addValues(cache, {
value
}) {
return comma(value).reduce((memo, val) => [...memo, ...space(val)], cache);
}
var atrule = 'atrule';
var decl = 'decl';
var rule = 'rule';
function filterAtRule({
atRules,
values
}) {
values = (0, _uniqs.default)(values);
atRules.forEach(node => {
const hasAtRule = values.some(value => value === node.params);
function addValues(cache, _ref) {
var value = _ref.value;
if (!hasAtRule) {
node.remove();
}
});
}
return comma(value).reduce(function (memo, val) {
return [].concat(memo, space(val));
}, cache);
function filterNamespace({
atRules,
rules
}) {
rules = (0, _uniqs.default)(rules);
atRules.forEach(atRule => {
const {
0: param,
length: len
} = atRule.params.split(' ').filter(Boolean);
if (len === 1) {
return;
}
const hasRule = rules.some(r => r === param || r === '*');
if (!hasRule) {
atRule.remove();
}
});
}
function filterAtRule(_ref2) {
var atRules = _ref2.atRules;
var values = _ref2.values;
function hasFont(fontFamily, cache) {
return comma(fontFamily).some(font => cache.some(c => ~c.indexOf(font)));
} // fonts have slightly different logic
values = (0, _uniqs2.default)(values);
atRules.forEach(function (node) {
var hasAtRule = values.some(function (value) {
return value === node.params;
});
if (!hasAtRule) {
node.remove();
}
function filterFont({
atRules,
values
}) {
values = (0, _uniqs.default)(values);
atRules.forEach(r => {
const families = r.nodes.filter(({
prop
}) => prop === 'font-family'); // Discard the @font-face if it has no font-family
if (!families.length) {
return r.remove();
}
families.forEach(family => {
if (!hasFont(family.value.toLowerCase(), values)) {
r.remove();
}
});
});
}
function filterNamespace(_ref3) {
var atRules = _ref3.atRules;
var rules = _ref3.rules;
var _default = (0, _postcss.plugin)('postcss-discard-unused', opts => {
const {
fontFace,
counterStyle,
keyframes,
namespace
} = Object.assign({}, {
fontFace: true,
counterStyle: true,
keyframes: true,
namespace: true
}, opts);
return css => {
const counterStyleCache = {
atRules: [],
values: []
};
const keyframesCache = {
atRules: [],
values: []
};
const namespaceCache = {
atRules: [],
rules: []
};
const fontCache = {
atRules: [],
values: []
};
css.walk(node => {
const {
type,
prop,
selector,
name
} = node;
rules = (0, _uniqs2.default)(rules);
atRules.forEach(function (atRule) {
var _atRule$params$split$ = atRule.params.split(' ').filter(Boolean);
if (type === rule && namespace && ~selector.indexOf('|')) {
if (~selector.indexOf('[')) {
// Attribute selector, so we should parse further.
(0, _postcssSelectorParser.default)(ast => {
ast.walkAttributes(({
namespace: ns
}) => {
namespaceCache.rules = namespaceCache.rules.concat(ns);
});
}).process(selector);
} else {
// Use a simple split function for the namespace
namespaceCache.rules = namespaceCache.rules.concat(selector.split('|')[0]);
}
var param = _atRule$params$split$[0];
var len = _atRule$params$split$.length;
return;
}
if (len === 1) {
return;
if (type === decl) {
if (counterStyle && /list-style|system/.test(prop)) {
counterStyleCache.values = addValues(counterStyleCache.values, node);
}
var hasRule = rules.some(function (r) {
return r === param || r === '*';
});
if (!hasRule) {
atRule.remove();
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) {
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase()));
}
});
}
function hasFont(fontFamily, cache) {
return comma(fontFamily).some(function (font) {
return cache.some(function (c) {
return ~c.indexOf(font);
});
});
}
if (keyframes && /animation/.test(prop)) {
keyframesCache.values = addValues(keyframesCache.values, node);
}
// fonts have slightly different logic
function filterFont(_ref4) {
var atRules = _ref4.atRules;
var values = _ref4.values;
return;
}
values = (0, _uniqs2.default)(values);
atRules.forEach(function (r) {
var families = r.nodes.filter(function (_ref5) {
var prop = _ref5.prop;
return prop === 'font-family';
});
// Discard the @font-face if it has no font-family
if (!families.length) {
return r.remove();
if (type === atrule) {
if (counterStyle && /counter-style/.test(name)) {
counterStyleCache.atRules.push(node);
}
families.forEach(function (family) {
if (!hasFont(family.value.toLowerCase(), values)) {
r.remove();
}
});
});
}
exports.default = (0, _postcss.plugin)('postcss-discard-unused', function (opts) {
var _fontFace$counterStyl = _extends({
fontFace: true,
counterStyle: true,
keyframes: true,
namespace: true
}, opts);
if (fontFace && name === 'font-face' && node.nodes) {
fontCache.atRules.push(node);
}
var fontFace = _fontFace$counterStyl.fontFace;
var counterStyle = _fontFace$counterStyl.counterStyle;
var keyframes = _fontFace$counterStyl.keyframes;
var namespace = _fontFace$counterStyl.namespace;
if (keyframes && /keyframes/.test(name)) {
keyframesCache.atRules.push(node);
}
return function (css) {
var counterStyleCache = { atRules: [], values: [] };
var keyframesCache = { atRules: [], values: [] };
var namespaceCache = { atRules: [], rules: [] };
var fontCache = { atRules: [], values: [] };
css.walk(function (node) {
var type = node.type;
var prop = node.prop;
var selector = node.selector;
var name = node.name;
if (namespace && name === 'namespace') {
namespaceCache.atRules.push(node);
}
if (type === rule && namespace && ~selector.indexOf('|')) {
namespaceCache.rules = namespaceCache.rules.concat(selector.split('|')[0]);
return;
}
if (type === decl) {
if (counterStyle && /list-style|system/.test(prop)) {
counterStyleCache.values = addValues(counterStyleCache.values, node);
}
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) {
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase()));
}
if (keyframes && /animation/.test(prop)) {
keyframesCache.values = addValues(keyframesCache.values, node);
}
return;
}
if (type === atrule) {
if (counterStyle && /counter-style/.test(name)) {
counterStyleCache.atRules.push(node);
}
if (fontFace && name === 'font-face' && node.nodes) {
fontCache.atRules.push(node);
}
if (keyframes && /keyframes/.test(name)) {
keyframesCache.atRules.push(node);
}
if (namespace && name === 'namespace') {
namespaceCache.atRules.push(node);
}
return;
}
});
counterStyle && filterAtRule(counterStyleCache);
fontFace && filterFont(fontCache);
keyframes && filterAtRule(keyframesCache);
namespace && filterNamespace(namespaceCache);
};
return;
}
});
counterStyle && filterAtRule(counterStyleCache);
fontFace && filterFont(fontCache);
keyframes && filterAtRule(keyframesCache);
namespace && filterNamespace(namespaceCache);
};
});
module.exports = exports['default'];
exports.default = _default;
module.exports = exports.default;
{
"name": "postcss-discard-unused",
"version": "2.2.3",
"version": "4.0.0-nightly.2020.7.24",
"description": "Discard unused counter styles, keyframes and fonts.",

@@ -12,8 +12,5 @@ "main": "dist/index.js",

"scripts": {
"contributorAdd": "all-contributors add",
"contributorGenerate": "all-contributors generate",
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"pretest": "eslint src",
"test": "ava src/__tests__",
"test-012": "ava src/__tests__"
"prebuild": "",
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
"prepublish": ""
},

@@ -29,19 +26,3 @@ "keywords": [

"license": "MIT",
"devDependencies": {
"all-contributors-cli": "^3.0.5",
"ava": "^0.16.0",
"babel-cli": "^6.4.5",
"babel-core": "^6.4.5",
"babel-plugin-add-module-exports": "^0.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-es2015-loose": "^7.0.0",
"babel-preset-stage-0": "^6.3.13",
"babel-register": "^6.9.0",
"del-cli": "^0.2.0",
"eslint": "^3.0.0",
"eslint-config-cssnano": "^3.0.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^2.0.1"
},
"homepage": "https://github.com/ben-eb/postcss-discard-unused",
"homepage": "https://github.com/cssnano/cssnano",
"author": {

@@ -52,13 +33,14 @@ "name": "Ben Briggs",

},
"repository": "ben-eb/postcss-discard-unused",
"repository": "cssnano/cssnano",
"dependencies": {
"postcss": "^5.0.14",
"postcss": "^7.0.16",
"postcss-selector-parser": "^3.1.1",
"uniqs": "^2.0.0"
},
"ava": {
"require": "babel-register"
"bugs": {
"url": "https://github.com/cssnano/cssnano/issues"
},
"eslintConfig": {
"extends": "cssnano"
"engines": {
"node": ">=6.9.0"
}
}
}

@@ -1,2 +0,2 @@

# [postcss][postcss]-discard-unused [![Build Status](https://travis-ci.org/ben-eb/postcss-discard-unused.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-discard-unused.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-discard-unused.svg)][deps]
# [postcss][postcss]-discard-unused

@@ -68,3 +68,3 @@ > Discard unused counter styles, keyframes and fonts.

*before* this plugin, which will take care of normalising quotes, and
deduplicating. For more examples, see the [tests](test.js).
deduplicating. For more examples, see the [tests](src/__tests__/index.js).

@@ -113,13 +113,10 @@

## Contributors
## Usage
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-discard-unused/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=TrySound) [📖](https://github.com/ben-eb/postcss-discard-unused/commits?author=TrySound) 👀 [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/770675?v=3" width="100px;"/><br /><sub>Paweł Lesiecki</sub>](https://github.com/plesiecki)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=plesiecki) [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=plesiecki) | [<img src="https://avatars.githubusercontent.com/u/197928?v=3" width="100px;"/><br /><sub>Thomas McDonald</sub>](https://github.com/thomas-mcdonald)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=thomas-mcdonald) [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=thomas-mcdonald) |
| :---: | :---: | :---: | :---: |
<!-- ALL-CONTRIBUTORS-LIST:END -->
## Contributors
This project follows the [all-contributors] specification. Contributions of
any kind welcome!
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).

@@ -131,7 +128,3 @@ ## License

[all-contributors]: https://github.com/kentcdodds/all-contributors
[ci]: https://travis-ci.org/ben-eb/postcss-discard-unused
[deps]: https://gemnasium.com/ben-eb/postcss-discard-unused
[npm]: http://badge.fury.io/js/postcss-discard-unused
[postcss]: https://github.com/postcss/postcss
[mfv]: https://github.com/trysound/postcss-minify-font-values
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