postcss-normalize-charset 5.0.2 → 5.0.3
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 +3 -7
- package/{dist → src}/index.js +14 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-charset",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Add necessary or remove extra charset with PostCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postcss",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"author": "Bogdan Chadkin <trysound@yandex.ru>",
|
|
12
12
|
"files": [
|
|
13
|
-
"
|
|
13
|
+
"src",
|
|
14
14
|
"LICENSE"
|
|
15
15
|
],
|
|
16
16
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/cssnano/cssnano",
|
|
22
|
-
"main": "
|
|
22
|
+
"main": "src/index.js",
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": "^10 || ^12 || >=14.0"
|
|
25
25
|
},
|
|
@@ -29,9 +29,5 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"postcss": "^8.2.15"
|
|
31
31
|
},
|
|
32
|
-
"scripts": {
|
|
33
|
-
"prebuild": "rimraf dist",
|
|
34
|
-
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
|
|
35
|
-
},
|
|
36
32
|
"readme": "# postcss-normalize-charset\n\nAdd necessary or remove extra charset with PostCSS\n\n```css\na{\n content: \"©\";\n}\n```\n\n```css\n@charset \"utf-8\";\na{\n content: \"©\";\n}\n```\n\n## API\n\n### normalizeCharset([options])\n\n#### options\n\n##### add\n\nType: `boolean` \nDefault: `true`\n\nPass `false` to stop the module from adding a `@charset` declaration if it was\nmissing from the file (and the file contained non-ascii characters).\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 © [Bogdan Chadkin](mailto:trysound@yandex.ru)\n"
|
|
37
33
|
}
|
package/{dist → src}/index.js
RENAMED
|
@@ -1,30 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
const charset = 'charset'; // eslint-disable-next-line no-control-regex
|
|
8
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
const charset = 'charset';
|
|
3
|
+
// eslint-disable-next-line no-control-regex
|
|
9
4
|
const nonAscii = /[^\x00-\x7F]/;
|
|
10
5
|
|
|
11
6
|
function pluginCreator(opts = {}) {
|
|
12
7
|
return {
|
|
13
8
|
postcssPlugin: 'postcss-normalize-' + charset,
|
|
14
9
|
|
|
15
|
-
OnceExit(css, {
|
|
16
|
-
AtRule
|
|
17
|
-
}) {
|
|
10
|
+
OnceExit(css, { AtRule }) {
|
|
18
11
|
let charsetRule;
|
|
19
12
|
let nonAsciiNode;
|
|
20
|
-
|
|
13
|
+
|
|
14
|
+
css.walk((node) => {
|
|
21
15
|
if (node.type === 'atrule' && node.name === charset) {
|
|
22
16
|
if (!charsetRule) {
|
|
23
17
|
charsetRule = node;
|
|
24
18
|
}
|
|
25
|
-
|
|
26
19
|
node.remove();
|
|
27
|
-
} else if (
|
|
20
|
+
} else if (
|
|
21
|
+
!nonAsciiNode &&
|
|
22
|
+
node.parent === css &&
|
|
23
|
+
nonAscii.test(node.toString())
|
|
24
|
+
) {
|
|
28
25
|
nonAsciiNode = node;
|
|
29
26
|
}
|
|
30
27
|
});
|
|
@@ -33,21 +30,17 @@ function pluginCreator(opts = {}) {
|
|
|
33
30
|
if (!charsetRule && opts.add !== false) {
|
|
34
31
|
charsetRule = new AtRule({
|
|
35
32
|
name: charset,
|
|
36
|
-
params: '"utf-8"'
|
|
33
|
+
params: '"utf-8"',
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
if (charsetRule) {
|
|
41
37
|
charsetRule.source = nonAsciiNode.source;
|
|
42
38
|
css.prepend(charsetRule);
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
|
-
}
|
|
46
|
-
|
|
41
|
+
},
|
|
47
42
|
};
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
pluginCreator.postcss = true;
|
|
51
|
-
|
|
52
|
-
exports.default = _default;
|
|
53
|
-
module.exports = exports.default;
|
|
46
|
+
module.exports = pluginCreator;
|