postcss-normalize-unicode 5.0.3 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "postcss-normalize-unicode",
3
- "version": "5.0.3",
3
+ "version": "5.0.4",
4
4
  "description": "Normalize unicode-range descriptors, and can convert to wildcard ranges.",
5
- "main": "dist/index.js",
5
+ "main": "src/index.js",
6
6
  "files": [
7
- "dist",
7
+ "src",
8
8
  "LICENSE-MIT"
9
9
  ],
10
10
  "keywords": [
@@ -36,9 +36,5 @@
36
36
  "peerDependencies": {
37
37
  "postcss": "^8.2.15"
38
38
  },
39
- "scripts": {
40
- "prebuild": "rimraf dist",
41
- "build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
42
- },
43
39
  "readme": "# [postcss][postcss]-normalize-unicode\n\n> Normalize unicode with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-normalize-unicode) do:\n\n```\nnpm install postcss-normalize-unicode --save\n```\n\n## Example\n\n### Input\n\n```css\n@font-face{\n font-family: test;\n unicode-range: u+2b00-2bff\n}\n```\n\n### Output\n\n```css\n@font-face{\n font-family: test;\n unicode-range: u+2b??\n}\n``` \n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
44
40
  }
@@ -1,15 +1,6 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _browserslist = _interopRequireDefault(require("browserslist"));
9
-
10
- var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1
+ 'use strict';
2
+ const browserslist = require('browserslist');
3
+ const valueParser = require('postcss-value-parser');
13
4
 
14
5
  const regexLowerCaseUPrefix = /^u(?=\+)/;
15
6
 
@@ -27,88 +18,100 @@ function unicode(range) {
27
18
  return range;
28
19
  }
29
20
 
30
- let questionCounter = 0;
31
- const merged = left.reduce((group, value, index) => {
32
- if (group === false) {
33
- return false;
34
- }
21
+ const merged = mergeRangeBounds(left, right);
35
22
 
36
- if (value === right[index] && !questionCounter) {
37
- return group + value;
38
- }
23
+ if (merged) {
24
+ return merged;
25
+ }
39
26
 
40
- if (value === '0' && right[index] === 'f') {
27
+ return range;
28
+ }
29
+ /**
30
+ * @param {string[]} left
31
+ * @param {string[]} right
32
+ * @return {false|string}
33
+ */
34
+ function mergeRangeBounds(left, right) {
35
+ let questionCounter = 0;
36
+ let group = 'u+';
37
+ for (const [index, value] of left.entries()) {
38
+ if (value === right[index] && questionCounter === 0) {
39
+ group = group + value;
40
+ } else if (value === '0' && right[index] === 'f') {
41
41
  questionCounter++;
42
- return group + '?';
42
+ group = group + '?';
43
+ } else {
44
+ return false;
43
45
  }
44
-
46
+ }
47
+ // The maximum number of wildcard characters (?) for ranges is 5.
48
+ if (questionCounter < 6) {
49
+ return group;
50
+ } else {
45
51
  return false;
46
- }, 'u+'); // The maximum number of wildcard characters (?) for ranges is 5.
47
-
48
- if (merged && questionCounter < 6) {
49
- return merged;
50
52
  }
51
-
52
- return range;
53
53
  }
54
+
54
55
  /*
55
56
  * IE and Edge before 16 version ignore the unicode-range if the 'U' is lowercase
56
57
  *
57
58
  * https://caniuse.com/#search=unicode-range
58
59
  */
59
60
 
60
-
61
61
  function hasLowerCaseUPrefixBug(browser) {
62
- return (0, _browserslist.default)('ie <=11, edge <= 15').includes(browser);
62
+ return browserslist('ie <=11, edge <= 15').includes(browser);
63
63
  }
64
64
 
65
65
  function transform(value, isLegacy = false) {
66
- return (0, _postcssValueParser.default)(value).walk(child => {
67
- if (child.type === 'unicode-range') {
68
- const transformed = unicode(child.value.toLowerCase());
69
- child.value = isLegacy ? transformed.replace(regexLowerCaseUPrefix, 'U') : transformed;
70
- }
66
+ return valueParser(value)
67
+ .walk((child) => {
68
+ if (child.type === 'unicode-range') {
69
+ const transformed = unicode(child.value.toLowerCase());
71
70
 
72
- return false;
73
- }).toString();
71
+ child.value = isLegacy
72
+ ? transformed.replace(regexLowerCaseUPrefix, 'U')
73
+ : transformed;
74
+ }
75
+
76
+ return false;
77
+ })
78
+ .toString();
74
79
  }
75
80
 
76
81
  function pluginCreator() {
77
82
  return {
78
83
  postcssPlugin: 'postcss-normalize-unicode',
79
-
80
84
  prepare(result) {
81
85
  const cache = new Map();
82
86
  const resultOpts = result.opts || {};
83
- const browsers = (0, _browserslist.default)(null, {
87
+ const browsers = browserslist(null, {
84
88
  stats: resultOpts.stats,
85
89
  path: __dirname,
86
- env: resultOpts.env
90
+ env: resultOpts.env,
87
91
  });
88
92
  const isLegacy = browsers.some(hasLowerCaseUPrefixBug);
93
+
89
94
  return {
90
95
  OnceExit(css) {
91
- css.walkDecls(/^unicode-range$/i, decl => {
96
+ css.walkDecls(/^unicode-range$/i, (decl) => {
92
97
  const value = decl.value;
93
98
 
94
99
  if (cache.has(value)) {
95
100
  decl.value = cache.get(value);
101
+
96
102
  return;
97
103
  }
98
104
 
99
105
  const newValue = transform(value, isLegacy);
106
+
100
107
  decl.value = newValue;
101
108
  cache.set(value, newValue);
102
109
  });
103
- }
104
-
110
+ },
105
111
  };
106
- }
107
-
112
+ },
108
113
  };
109
114
  }
110
115
 
111
116
  pluginCreator.postcss = true;
112
- var _default = pluginCreator;
113
- exports.default = _default;
114
- module.exports = exports.default;
117
+ module.exports = pluginCreator;