postcss-normalize-string 4.0.2 → 5.0.0

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/index.js +204 -187
  3. package/package.json +14 -11
package/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-normalize-string@5.0.0-rc.2...postcss-normalize-string@5.0.0) (2021-04-06)
7
+
8
+ **Note:** Version bump only for package postcss-normalize-string
9
+
10
+
11
+
12
+
13
+
14
+ # [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-normalize-string@5.0.0-rc.1...postcss-normalize-string@5.0.0-rc.2) (2021-03-15)
15
+
16
+ **Note:** Version bump only for package postcss-normalize-string
17
+
18
+
19
+
20
+
21
+
22
+ # [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-normalize-string@5.0.0-rc.0...postcss-normalize-string@5.0.0-rc.1) (2021-03-04)
23
+
24
+ **Note:** Version bump only for package postcss-normalize-string
25
+
26
+
27
+
28
+
29
+
30
+ # 5.0.0-rc.0 (2021-02-19)
31
+
32
+
33
+ ### Bug Fixes
34
+
35
+ * **postcss-ordered-values:** columns transform returning string instead of the AST ([#928](https://github.com/cssnano/cssnano/issues/928)) ([a5d6d36](https://github.com/cssnano/cssnano/commit/a5d6d364e0815ecb198a95de301f3554ccce4f78))
36
+
37
+
38
+ ### chore
39
+
40
+ * minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
41
+
42
+
43
+ ### Features
44
+
45
+ * migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
46
+
47
+
48
+ ### BREAKING CHANGES
49
+
50
+ * minimum supported `postcss` version is `8.2.1`
51
+ * minimum require version of node is 10.13
52
+
53
+
54
+
55
+ ## 4.1.9 (2019-02-12)
56
+
57
+
58
+ ### Performance Improvements
59
+
60
+ * **postcss-normalize-string:** increase perf ([#689](https://github.com/cssnano/cssnano/issues/689)) ([07948cb](https://github.com/cssnano/cssnano/commit/07948cb3ff433825682c499516640abeeec7383a))
61
+
62
+
63
+
64
+ ## 4.1.1 (2018-09-24)
65
+
66
+
67
+ ### Bug Fixes
68
+
69
+ * **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
package/dist/index.js CHANGED
@@ -1,28 +1,18 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _postcss = require('postcss');
8
-
9
- var _postcss2 = _interopRequireDefault(_postcss);
10
-
11
- var _postcssValueParser = require('postcss-value-parser');
12
-
13
- var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
14
-
15
- var _has = require('has');
16
-
17
- var _has2 = _interopRequireDefault(_has);
8
+ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
18
9
 
19
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
11
 
21
12
  /*
22
13
  * Constants (parser usage)
23
14
  */
24
-
25
- const SINGLE_QUOTE = '\''.charCodeAt(0);
15
+ const SINGLE_QUOTE = "'".charCodeAt(0);
26
16
  const DOUBLE_QUOTE = '"'.charCodeAt(0);
27
17
  const BACKSLASH = '\\'.charCodeAt(0);
28
18
  const NEWLINE = '\n'.charCodeAt(0);
@@ -30,9 +20,7 @@ const SPACE = ' '.charCodeAt(0);
30
20
  const FEED = '\f'.charCodeAt(0);
31
21
  const TAB = '\t'.charCodeAt(0);
32
22
  const CR = '\r'.charCodeAt(0);
33
-
34
23
  const WORD_END = /[ \n\t\r\f'"\\]/g;
35
-
36
24
  /*
37
25
  * Constants (node type strings)
38
26
  */
@@ -44,7 +32,6 @@ const C_SINGLE_QUOTE = 'singleQuote';
44
32
  const C_DOUBLE_QUOTE = 'doubleQuote';
45
33
  const C_NEWLINE = 'newline';
46
34
  const C_SINGLE = 'single';
47
-
48
35
  /*
49
36
  * Literals
50
37
  */
@@ -52,209 +39,239 @@ const C_SINGLE = 'single';
52
39
  const L_SINGLE_QUOTE = `'`;
53
40
  const L_DOUBLE_QUOTE = `"`;
54
41
  const L_NEWLINE = `\\\n`;
55
-
56
42
  /*
57
43
  * Parser nodes
58
44
  */
59
45
 
60
- const T_ESCAPED_SINGLE_QUOTE = { type: C_ESCAPED_SINGLE_QUOTE, value: `\\'` };
61
- const T_ESCAPED_DOUBLE_QUOTE = { type: C_ESCAPED_DOUBLE_QUOTE, value: `\\"` };
62
- const T_SINGLE_QUOTE = { type: C_SINGLE_QUOTE, value: L_SINGLE_QUOTE };
63
- const T_DOUBLE_QUOTE = { type: C_DOUBLE_QUOTE, value: L_DOUBLE_QUOTE };
64
- const T_NEWLINE = { type: C_NEWLINE, value: L_NEWLINE };
46
+ const T_ESCAPED_SINGLE_QUOTE = {
47
+ type: C_ESCAPED_SINGLE_QUOTE,
48
+ value: `\\'`
49
+ };
50
+ const T_ESCAPED_DOUBLE_QUOTE = {
51
+ type: C_ESCAPED_DOUBLE_QUOTE,
52
+ value: `\\"`
53
+ };
54
+ const T_SINGLE_QUOTE = {
55
+ type: C_SINGLE_QUOTE,
56
+ value: L_SINGLE_QUOTE
57
+ };
58
+ const T_DOUBLE_QUOTE = {
59
+ type: C_DOUBLE_QUOTE,
60
+ value: L_DOUBLE_QUOTE
61
+ };
62
+ const T_NEWLINE = {
63
+ type: C_NEWLINE,
64
+ value: L_NEWLINE
65
+ };
65
66
 
66
67
  function stringify(ast) {
67
- return ast.nodes.reduce((str, { value }) => {
68
- // Collapse multiple line strings automatically
69
- if (value === L_NEWLINE) {
70
- return str;
71
- }
68
+ return ast.nodes.reduce((str, {
69
+ value
70
+ }) => {
71
+ // Collapse multiple line strings automatically
72
+ if (value === L_NEWLINE) {
73
+ return str;
74
+ }
72
75
 
73
- return str + value;
74
- }, '');
76
+ return str + value;
77
+ }, '');
75
78
  }
76
79
 
77
80
  function parse(str) {
78
- let code, next, value;
79
- let pos = 0;
80
- let len = str.length;
81
-
82
- const ast = {
83
- nodes: [],
84
- types: {
85
- escapedSingleQuote: 0,
86
- escapedDoubleQuote: 0,
87
- singleQuote: 0,
88
- doubleQuote: 0
89
- },
90
- quotes: false
91
- };
92
-
93
- while (pos < len) {
94
- code = str.charCodeAt(pos);
95
-
96
- switch (code) {
97
- case SPACE:
98
- case TAB:
99
- case CR:
100
- case FEED:
101
- next = pos;
102
-
103
- do {
104
- next += 1;
105
- code = str.charCodeAt(next);
106
- } while (code === SPACE || code === NEWLINE || code === TAB || code === CR || code === FEED);
107
-
108
- ast.nodes.push({
109
- type: 'space',
110
- value: str.slice(pos, next)
111
- });
112
- pos = next - 1;
113
- break;
114
- case SINGLE_QUOTE:
115
- ast.nodes.push(T_SINGLE_QUOTE);
116
- ast.types[C_SINGLE_QUOTE]++;
117
- ast.quotes = true;
118
- break;
119
- case DOUBLE_QUOTE:
120
- ast.nodes.push(T_DOUBLE_QUOTE);
121
- ast.types[C_DOUBLE_QUOTE]++;
122
- ast.quotes = true;
123
- break;
124
- case BACKSLASH:
125
- next = pos + 1;
126
-
127
- if (str.charCodeAt(next) === SINGLE_QUOTE) {
128
- ast.nodes.push(T_ESCAPED_SINGLE_QUOTE);
129
- ast.types[C_ESCAPED_SINGLE_QUOTE]++;
130
- ast.quotes = true;
131
- pos = next;
132
- break;
133
- } else if (str.charCodeAt(next) === DOUBLE_QUOTE) {
134
- ast.nodes.push(T_ESCAPED_DOUBLE_QUOTE);
135
- ast.types[C_ESCAPED_DOUBLE_QUOTE]++;
136
- ast.quotes = true;
137
- pos = next;
138
- break;
139
- } else if (str.charCodeAt(next) === NEWLINE) {
140
- ast.nodes.push(T_NEWLINE);
141
- pos = next;
142
- break;
143
- }
144
- /*
145
- * We need to fall through here to handle the token as
146
- * a whole word. The missing 'break' is intentional.
147
- */
148
- default:
149
- WORD_END.lastIndex = pos + 1;
150
- WORD_END.test(str);
151
-
152
- if (WORD_END.lastIndex === 0) {
153
- next = len - 1;
154
- } else {
155
- next = WORD_END.lastIndex - 2;
156
- }
157
-
158
- value = str.slice(pos, next + 1);
159
-
160
- ast.nodes.push({
161
- type: C_STRING,
162
- value
163
- });
164
-
165
- pos = next;
81
+ let code, next, value;
82
+ let pos = 0;
83
+ let len = str.length;
84
+ const ast = {
85
+ nodes: [],
86
+ types: {
87
+ escapedSingleQuote: 0,
88
+ escapedDoubleQuote: 0,
89
+ singleQuote: 0,
90
+ doubleQuote: 0
91
+ },
92
+ quotes: false
93
+ };
94
+
95
+ while (pos < len) {
96
+ code = str.charCodeAt(pos);
97
+
98
+ switch (code) {
99
+ case SPACE:
100
+ case TAB:
101
+ case CR:
102
+ case FEED:
103
+ next = pos;
104
+
105
+ do {
106
+ next += 1;
107
+ code = str.charCodeAt(next);
108
+ } while (code === SPACE || code === NEWLINE || code === TAB || code === CR || code === FEED);
109
+
110
+ ast.nodes.push({
111
+ type: 'space',
112
+ value: str.slice(pos, next)
113
+ });
114
+ pos = next - 1;
115
+ break;
116
+
117
+ case SINGLE_QUOTE:
118
+ ast.nodes.push(T_SINGLE_QUOTE);
119
+ ast.types[C_SINGLE_QUOTE]++;
120
+ ast.quotes = true;
121
+ break;
122
+
123
+ case DOUBLE_QUOTE:
124
+ ast.nodes.push(T_DOUBLE_QUOTE);
125
+ ast.types[C_DOUBLE_QUOTE]++;
126
+ ast.quotes = true;
127
+ break;
128
+
129
+ case BACKSLASH:
130
+ next = pos + 1;
131
+
132
+ if (str.charCodeAt(next) === SINGLE_QUOTE) {
133
+ ast.nodes.push(T_ESCAPED_SINGLE_QUOTE);
134
+ ast.types[C_ESCAPED_SINGLE_QUOTE]++;
135
+ ast.quotes = true;
136
+ pos = next;
137
+ break;
138
+ } else if (str.charCodeAt(next) === DOUBLE_QUOTE) {
139
+ ast.nodes.push(T_ESCAPED_DOUBLE_QUOTE);
140
+ ast.types[C_ESCAPED_DOUBLE_QUOTE]++;
141
+ ast.quotes = true;
142
+ pos = next;
143
+ break;
144
+ } else if (str.charCodeAt(next) === NEWLINE) {
145
+ ast.nodes.push(T_NEWLINE);
146
+ pos = next;
147
+ break;
148
+ }
149
+
150
+ /*
151
+ * We need to fall through here to handle the token as
152
+ * a whole word. The missing 'break' is intentional.
153
+ */
154
+
155
+ default:
156
+ WORD_END.lastIndex = pos + 1;
157
+ WORD_END.test(str);
158
+
159
+ if (WORD_END.lastIndex === 0) {
160
+ next = len - 1;
161
+ } else {
162
+ next = WORD_END.lastIndex - 2;
166
163
  }
167
- pos++;
164
+
165
+ value = str.slice(pos, next + 1);
166
+ ast.nodes.push({
167
+ type: C_STRING,
168
+ value
169
+ });
170
+ pos = next;
168
171
  }
169
172
 
170
- return ast;
173
+ pos++;
174
+ }
175
+
176
+ return ast;
171
177
  }
172
178
 
173
179
  function changeWrappingQuotes(node, ast) {
174
- const { types } = ast;
180
+ const {
181
+ types
182
+ } = ast;
175
183
 
176
- if (types[C_SINGLE_QUOTE] || types[C_DOUBLE_QUOTE]) {
177
- return;
178
- }
184
+ if (types[C_SINGLE_QUOTE] || types[C_DOUBLE_QUOTE]) {
185
+ return;
186
+ }
179
187
 
180
- if (node.quote === L_SINGLE_QUOTE && types[C_ESCAPED_SINGLE_QUOTE] > 0 && !types[C_ESCAPED_DOUBLE_QUOTE]) {
181
- node.quote = L_DOUBLE_QUOTE;
182
- }
188
+ if (node.quote === L_SINGLE_QUOTE && types[C_ESCAPED_SINGLE_QUOTE] > 0 && !types[C_ESCAPED_DOUBLE_QUOTE]) {
189
+ node.quote = L_DOUBLE_QUOTE;
190
+ }
183
191
 
184
- if (node.quote === L_DOUBLE_QUOTE && types[C_ESCAPED_DOUBLE_QUOTE] > 0 && !types[C_ESCAPED_SINGLE_QUOTE]) {
185
- node.quote = L_SINGLE_QUOTE;
186
- }
192
+ if (node.quote === L_DOUBLE_QUOTE && types[C_ESCAPED_DOUBLE_QUOTE] > 0 && !types[C_ESCAPED_SINGLE_QUOTE]) {
193
+ node.quote = L_SINGLE_QUOTE;
194
+ }
187
195
 
188
- ast.nodes = ast.nodes.reduce((newAst, child) => {
189
- if (child.type === C_ESCAPED_DOUBLE_QUOTE && node.quote === L_SINGLE_QUOTE) {
190
- return [...newAst, T_DOUBLE_QUOTE];
191
- }
196
+ ast.nodes = ast.nodes.reduce((newAst, child) => {
197
+ if (child.type === C_ESCAPED_DOUBLE_QUOTE && node.quote === L_SINGLE_QUOTE) {
198
+ return [...newAst, T_DOUBLE_QUOTE];
199
+ }
192
200
 
193
- if (child.type === C_ESCAPED_SINGLE_QUOTE && node.quote === L_DOUBLE_QUOTE) {
194
- return [...newAst, T_SINGLE_QUOTE];
195
- }
201
+ if (child.type === C_ESCAPED_SINGLE_QUOTE && node.quote === L_DOUBLE_QUOTE) {
202
+ return [...newAst, T_SINGLE_QUOTE];
203
+ }
196
204
 
197
- return [...newAst, child];
198
- }, []);
205
+ return [...newAst, child];
206
+ }, []);
199
207
  }
200
208
 
201
209
  function normalize(value, preferredQuote) {
202
- if (!value || !value.length) {
203
- return value;
204
- }
210
+ if (!value || !value.length) {
211
+ return value;
212
+ }
205
213
 
206
- return (0, _postcssValueParser2.default)(value).walk(child => {
207
- if (child.type !== C_STRING) {
208
- return;
209
- }
214
+ return (0, _postcssValueParser.default)(value).walk(child => {
215
+ if (child.type !== C_STRING) {
216
+ return;
217
+ }
210
218
 
211
- const ast = parse(child.value);
219
+ const ast = parse(child.value);
212
220
 
213
- if (ast.quotes) {
214
- changeWrappingQuotes(child, ast);
215
- } else if (preferredQuote === C_SINGLE) {
216
- child.quote = L_SINGLE_QUOTE;
217
- } else {
218
- child.quote = L_DOUBLE_QUOTE;
219
- }
221
+ if (ast.quotes) {
222
+ changeWrappingQuotes(child, ast);
223
+ } else if (preferredQuote === C_SINGLE) {
224
+ child.quote = L_SINGLE_QUOTE;
225
+ } else {
226
+ child.quote = L_DOUBLE_QUOTE;
227
+ }
220
228
 
221
- child.value = stringify(ast);
222
- }).toString();
229
+ child.value = stringify(ast);
230
+ }).toString();
223
231
  }
224
232
 
225
233
  const params = {
226
- rule: 'selector',
227
- decl: 'value',
228
- atrule: 'params'
234
+ rule: 'selector',
235
+ decl: 'value',
236
+ atrule: 'params'
229
237
  };
230
238
 
231
- exports.default = _postcss2.default.plugin('postcss-normalize-string', opts => {
232
- const { preferredQuote } = Object.assign({}, {
233
- preferredQuote: 'double'
234
- }, opts);
235
-
236
- return css => {
237
- const cache = {};
238
-
239
- css.walk(node => {
240
- const { type } = node;
241
-
242
- if ((0, _has2.default)(params, type)) {
243
- const param = params[type];
244
- const key = node[param] + '|' + preferredQuote;
245
-
246
- if (cache[key]) {
247
- node[param] = cache[key];
239
+ function pluginCreator(opts) {
240
+ const {
241
+ preferredQuote
242
+ } = Object.assign({}, {
243
+ preferredQuote: 'double'
244
+ }, opts);
245
+ return {
246
+ postcssPlugin: 'postcss-normalize-string',
247
+
248
+ OnceExit(css) {
249
+ const cache = {};
250
+ css.walk(node => {
251
+ const {
252
+ type
253
+ } = node;
254
+
255
+ if (Object.prototype.hasOwnProperty.call(params, type)) {
256
+ const param = params[type];
257
+ const key = node[param] + '|' + preferredQuote;
258
+
259
+ if (cache[key]) {
260
+ node[param] = cache[key];
261
+ return;
262
+ }
248
263
 
249
- return;
250
- }
264
+ const newValue = normalize(node[param], preferredQuote);
265
+ node[param] = newValue;
266
+ cache[key] = newValue;
267
+ }
268
+ });
269
+ }
251
270
 
252
- const result = normalize(node[param], preferredQuote);
271
+ };
272
+ }
253
273
 
254
- node[param] = result;
255
- cache[key] = result;
256
- }
257
- });
258
- };
259
- });
260
- module.exports = exports['default'];
274
+ pluginCreator.postcss = true;
275
+ var _default = pluginCreator;
276
+ exports.default = _default;
277
+ module.exports = exports.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-normalize-string",
3
- "version": "4.0.2",
3
+ "version": "5.0.0",
4
4
  "description": "Normalize wrapping quotes for CSS string literals.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -8,7 +8,9 @@
8
8
  "LICENSE-MIT"
9
9
  ],
10
10
  "scripts": {
11
- "prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
11
+ "prebuild": "del-cli dist",
12
+ "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
13
+ "prepublish": "yarn build"
12
14
  },
13
15
  "keywords": [
14
16
  "css",
@@ -16,10 +18,6 @@
16
18
  "postcss-plugin"
17
19
  ],
18
20
  "license": "MIT",
19
- "devDependencies": {
20
- "babel-cli": "^6.0.0",
21
- "cross-env": "^5.0.0"
22
- },
23
21
  "homepage": "https://github.com/cssnano/cssnano",
24
22
  "author": {
25
23
  "name": "Ben Briggs",
@@ -28,14 +26,19 @@
28
26
  },
29
27
  "repository": "cssnano/cssnano",
30
28
  "dependencies": {
31
- "has": "^1.0.0",
32
- "postcss": "^7.0.0",
33
- "postcss-value-parser": "^3.0.0"
29
+ "postcss-value-parser": "^4.1.0"
34
30
  },
35
31
  "bugs": {
36
32
  "url": "https://github.com/cssnano/cssnano/issues"
37
33
  },
38
34
  "engines": {
39
- "node": ">=6.9.0"
40
- }
35
+ "node": "^10 || ^12 || >=14.0"
36
+ },
37
+ "devDependencies": {
38
+ "postcss": "^8.2.1"
39
+ },
40
+ "peerDependencies": {
41
+ "postcss": "^8.2.1"
42
+ },
43
+ "gitHead": "0e2c3bf5835bafcdc8783bef66f730a24194c8f3"
41
44
  }