postcss-colormin
Advanced tools
Comparing version 4.0.0-rc.2 to 4.0.0
@@ -21,22 +21,18 @@ 'use strict'; | ||
var shorter = function shorter(a, b) { | ||
return (a && a.length < b.length ? a : b).toLowerCase(); | ||
}; | ||
const shorter = (a, b) => (a && a.length < b.length ? a : b).toLowerCase(); | ||
exports.default = function (colour) { | ||
var legacy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
exports.default = (colour, legacy = false) => { | ||
try { | ||
var parsed = (0, _color2.default)(colour.toLowerCase()); | ||
var alpha = parsed.alpha(); | ||
const parsed = (0, _color2.default)(colour.toLowerCase()); | ||
const alpha = parsed.alpha(); | ||
if (alpha === 1) { | ||
var toHex = (0, _toShorthand2.default)(parsed.hex().toLowerCase()); | ||
const toHex = (0, _toShorthand2.default)(parsed.hex().toLowerCase()); | ||
return shorter(_keywords2.default[toHex], toHex); | ||
} else { | ||
var rgb = parsed.rgb(); | ||
const rgb = parsed.rgb(); | ||
if (!legacy && !rgb.color[0] && !rgb.color[1] && !rgb.color[2] && !alpha) { | ||
return 'transparent'; | ||
} | ||
var hsla = parsed.hsl().round().string(); | ||
var rgba = rgb.string(); | ||
let hsla = parsed.hsl().round().string(); | ||
let rgba = rgb.string(); | ||
return hsla.length < rgba.length ? hsla : rgba; | ||
@@ -43,0 +39,0 @@ } |
@@ -26,4 +26,4 @@ 'use strict'; | ||
function walk(parent, callback) { | ||
parent.nodes.forEach(function (node, index) { | ||
var bubble = callback(node, index, parent); | ||
parent.nodes.forEach((node, index) => { | ||
const bubble = callback(node, index, parent); | ||
if (node.nodes && bubble !== false) { | ||
@@ -39,15 +39,14 @@ walk(node, callback); | ||
} | ||
var ast = (0, _postcssValueParser2.default)(decl.value); | ||
walk(ast, function (node, index, parent) { | ||
const ast = (0, _postcssValueParser2.default)(decl.value); | ||
walk(ast, (node, index, parent) => { | ||
if (node.type === 'function') { | ||
if (/^(rgb|hsl)a?$/.test(node.value)) { | ||
var value = node.value; | ||
if (/^(rgb|hsl)a?$/i.test(node.value)) { | ||
const { value } = node; | ||
node.value = (0, _colours2.default)((0, _postcssValueParser.stringify)(node), legacy); | ||
node.type = 'word'; | ||
var next = parent.nodes[index + 1]; | ||
if (node.value !== value && next && next.type === 'word') { | ||
const next = parent.nodes[index + 1]; | ||
if (node.value !== value && next && (next.type === 'word' || next.type === 'function')) { | ||
parent.nodes.splice(index + 1, 0, { type: 'space', value: ' ' }); | ||
} | ||
} else if (node.value === 'calc') { | ||
} else if (node.value.toLowerCase() === 'calc') { | ||
return false; | ||
@@ -73,6 +72,6 @@ } | ||
exports.default = _postcss2.default.plugin('postcss-colormin', function () { | ||
return function (css, result) { | ||
var resultOpts = result.opts || {}; | ||
var browsers = (0, _browserslist2.default)(null, { | ||
exports.default = _postcss2.default.plugin('postcss-colormin', () => { | ||
return (css, result) => { | ||
const resultOpts = result.opts || {}; | ||
const browsers = (0, _browserslist2.default)(null, { | ||
stats: resultOpts.stats, | ||
@@ -79,0 +78,0 @@ path: __dirname, |
@@ -7,3 +7,3 @@ 'use strict'; | ||
exports.default = function (hex) { | ||
exports.default = hex => { | ||
if (hex[1] === hex[2] && hex[3] === hex[4] && hex[5] === hex[6]) { | ||
@@ -10,0 +10,0 @@ return '#' + hex[2] + hex[4] + hex[6]; |
{ | ||
"name": "postcss-colormin", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0", | ||
"description": "Minify colors in your CSS files with PostCSS.", | ||
@@ -25,7 +25,7 @@ "main": "dist/index.js", | ||
"babel-cli": "^6.0.0", | ||
"cross-env": "^3.0.0", | ||
"cross-env": "^5.0.0", | ||
"css-color-names": "0.0.4", | ||
"write-file": "^1.0.0" | ||
}, | ||
"homepage": "https://github.com/ben-eb/cssnano", | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
"author": { | ||
@@ -36,6 +36,6 @@ "name": "Ben Briggs", | ||
}, | ||
"repository": "ben-eb/cssnano", | ||
"repository": "cssnano/cssnano", | ||
"dependencies": { | ||
"browserslist": "^2.0.0", | ||
"color": "^1.0.0", | ||
"browserslist": "^4.0.0", | ||
"color": "^3.0.0", | ||
"has": "^1.0.0", | ||
@@ -46,7 +46,7 @@ "postcss": "^6.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" | ||
} | ||
} |
@@ -37,3 +37,3 @@ # [postcss][postcss]-colormin | ||
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). | ||
@@ -40,0 +40,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
11115
138
1
+ Addedbrowserslist@4.23.3(transitive)
+ Addedcolor@3.2.1(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addednode-releases@2.0.18(transitive)
+ Addedpicocolors@1.1.0(transitive)
+ Addedupdate-browserslist-db@1.1.0(transitive)
- Removedbrowserslist@2.11.3(transitive)
- Removedcolor@1.0.3(transitive)
Updatedbrowserslist@^4.0.0
Updatedcolor@^3.0.0