postcss-normalize-unicode
Advanced tools
Comparing version
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _browserslist = require('browserslist'); | ||
var _browserslist2 = _interopRequireDefault(_browserslist); | ||
var _postcss = require('postcss'); | ||
@@ -18,9 +22,11 @@ | ||
const regexLowerCaseUPrefix = /^u(?=\+)/; | ||
function unicode(range) { | ||
var values = range.slice(2).split('-'); | ||
const values = range.slice(2).split('-'); | ||
if (values.length < 2) { | ||
return range; | ||
} | ||
var left = values[0].split(''); | ||
var right = values[1].split(''); | ||
const left = values[0].split(''); | ||
const right = values[1].split(''); | ||
@@ -31,5 +37,5 @@ if (left.length !== right.length) { | ||
var questionCounter = 0; | ||
let questionCounter = 0; | ||
var merged = left.reduce(function (group, value, index) { | ||
const merged = left.reduce((group, value, index) => { | ||
if (group === false) { | ||
@@ -59,15 +65,33 @@ return false; | ||
exports.default = _postcss2.default.plugin('postcss-normalize-unicode', function () { | ||
return function (css) { | ||
css.walkDecls(/^unicode-range$/i, function (node) { | ||
node.prop = 'unicode-range'; | ||
node.value = (0, _postcssValueParser2.default)(node.value).walk(function (child) { | ||
if (child.type === 'word') { | ||
child.value = unicode(child.value.toLowerCase()); | ||
} | ||
return false; | ||
}).toString(); | ||
/* | ||
* IE and Edge before 16 version ignore the unicode-range if the 'U' is lowercase | ||
* | ||
* https://caniuse.com/#search=unicode-range | ||
*/ | ||
function hasLowerCaseUPrefixBug(browser) { | ||
return ~(0, _browserslist2.default)('ie <=11, edge <= 15').indexOf(browser); | ||
} | ||
function transform(legacy = false, node) { | ||
node.value = (0, _postcssValueParser2.default)(node.value).walk(child => { | ||
if (child.type === 'word') { | ||
const transformed = unicode(child.value.toLowerCase()); | ||
child.value = legacy ? transformed.replace(regexLowerCaseUPrefix, 'U') : transformed; | ||
} | ||
return false; | ||
}).toString(); | ||
} | ||
exports.default = _postcss2.default.plugin('postcss-normalize-unicode', () => { | ||
return (css, result) => { | ||
const resultOpts = result.opts || {}; | ||
const browsers = (0, _browserslist2.default)(null, { | ||
stats: resultOpts.stats, | ||
path: __dirname, | ||
env: resultOpts.env | ||
}); | ||
css.walkDecls(/^unicode-range$/i, transform.bind(null, browsers.some(hasLowerCaseUPrefixBug))); | ||
}; | ||
}); | ||
module.exports = exports['default']; |
{ | ||
"name": "postcss-normalize-unicode", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0", | ||
"description": "Normalize unicode-range descriptors, and can convert to wildcard ranges.", | ||
@@ -21,5 +21,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": { | ||
@@ -30,3 +30,3 @@ "name": "Ben Briggs", | ||
}, | ||
"repository": "ben-eb/cssnano", | ||
"repository": "cssnano/cssnano", | ||
"dependencies": { | ||
@@ -37,7 +37,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" | ||
} | ||
} |
@@ -40,3 +40,3 @@ # [postcss][postcss]-normalize-unicode | ||
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). | ||
@@ -43,0 +43,0 @@ ## License |
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
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
5397
15.35%72
33.33%0
-100%1
Infinity%