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 4.0.0-rc.2 to 4.0.0

102

dist/index.js

@@ -19,29 +19,16 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
const { comma, space } = _postcss.list;
var comma = _postcss.list.comma,
space = _postcss.list.space;
const atrule = 'atrule';
const decl = 'decl';
const rule = 'rule';
var atrule = 'atrule';
var decl = 'decl';
var rule = 'rule';
function addValues(cache, _ref) {
var value = _ref.value;
return comma(value).reduce(function (memo, val) {
return [].concat(_toConsumableArray(memo), _toConsumableArray(space(val)));
}, cache);
function addValues(cache, { value }) {
return comma(value).reduce((memo, val) => [...memo, ...space(val)], cache);
}
function filterAtRule(_ref2) {
var atRules = _ref2.atRules,
values = _ref2.values;
function filterAtRule({ atRules, values }) {
values = (0, _uniqs2.default)(values);
atRules.forEach(function (node) {
var hasAtRule = values.some(function (value) {
return value === node.params;
});
atRules.forEach(node => {
const hasAtRule = values.some(value => value === node.params);
if (!hasAtRule) {

@@ -53,18 +40,10 @@ node.remove();

function filterNamespace(_ref3) {
var atRules = _ref3.atRules,
rules = _ref3.rules;
function filterNamespace({ atRules, rules }) {
rules = (0, _uniqs2.default)(rules);
atRules.forEach(function (atRule) {
var _atRule$params$split$ = atRule.params.split(' ').filter(Boolean),
param = _atRule$params$split$[0],
len = _atRule$params$split$.length;
atRules.forEach(atRule => {
const { 0: param, length: len } = atRule.params.split(' ').filter(Boolean);
if (len === 1) {
return;
}
var hasRule = rules.some(function (r) {
return r === param || r === '*';
});
const hasRule = rules.some(r => r === param || r === '*');
if (!hasRule) {

@@ -77,20 +56,10 @@ atRule.remove();

function hasFont(fontFamily, cache) {
return comma(fontFamily).some(function (font) {
return cache.some(function (c) {
return ~c.indexOf(font);
});
});
return comma(fontFamily).some(font => cache.some(c => ~c.indexOf(font)));
}
// fonts have slightly different logic
function filterFont(_ref4) {
var atRules = _ref4.atRules,
values = _ref4.values;
function filterFont({ atRules, values }) {
values = (0, _uniqs2.default)(values);
atRules.forEach(function (r) {
var families = r.nodes.filter(function (_ref5) {
var prop = _ref5.prop;
return prop === 'font-family';
});
atRules.forEach(r => {
const families = r.nodes.filter(({ prop }) => prop === 'font-family');
// Discard the @font-face if it has no font-family

@@ -100,3 +69,3 @@ if (!families.length) {

}
families.forEach(function (family) {
families.forEach(family => {
if (!hasFont(family.value.toLowerCase(), values)) {

@@ -109,4 +78,4 @@ r.remove();

exports.default = (0, _postcss.plugin)('postcss-discard-unused', function (opts) {
var _Object$assign = Object.assign({}, {
exports.default = (0, _postcss.plugin)('postcss-discard-unused', opts => {
const { fontFace, counterStyle, keyframes, namespace } = Object.assign({}, {
fontFace: true,

@@ -116,26 +85,15 @@ counterStyle: true,

namespace: true
}, opts),
fontFace = _Object$assign.fontFace,
counterStyle = _Object$assign.counterStyle,
keyframes = _Object$assign.keyframes,
namespace = _Object$assign.namespace;
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,
prop = node.prop,
selector = node.selector,
name = node.name;
}, 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;
if (type === rule && namespace && ~selector.indexOf('|')) {
if (~selector.indexOf('[')) {
// Attribute selector, so we should parse further.
(0, _postcssSelectorParser2.default)(function (ast) {
ast.walkAttributes(function (_ref6) {
var ns = _ref6.namespace;
(0, _postcssSelectorParser2.default)(ast => {
ast.walkAttributes(({ namespace: ns }) => {
namespaceCache.rules = namespaceCache.rules.concat(ns);

@@ -142,0 +100,0 @@ });

{
"name": "postcss-discard-unused",
"version": "4.0.0-rc.2",
"version": "4.0.0",
"description": "Discard unused counter styles, keyframes and fonts.",

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

"babel-cli": "^6.0.0",
"cross-env": "^3.0.0"
"cross-env": "^5.0.0"
},
"homepage": "https://github.com/ben-eb/cssnano",
"homepage": "https://github.com/cssnano/cssnano",
"author": {

@@ -34,14 +34,14 @@ "name": "Ben Briggs",

},
"repository": "ben-eb/cssnano",
"repository": "cssnano/cssnano",
"dependencies": {
"postcss": "^6.0.0",
"postcss-selector-parser": "^2.0.0",
"postcss-selector-parser": "^3.0.0",
"uniqs": "^2.0.0"
},
"bugs": {
"url": "https://github.com/ben-eb/cssnano/issues"
"url": "https://github.com/cssnano/cssnano/issues"
},
"engines": {
"node": ">=4"
"node": ">=6.9.0"
}
}

@@ -119,3 +119,3 @@ # [postcss][postcss]-discard-unused

See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md).
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).

@@ -122,0 +122,0 @@ ## License

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