aboutsummaryrefslogtreecommitdiff
path: root/node_modules/postcss-normalize-charset/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/postcss-normalize-charset/index.js')
-rw-r--r--node_modules/postcss-normalize-charset/index.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/node_modules/postcss-normalize-charset/index.js b/node_modules/postcss-normalize-charset/index.js
new file mode 100644
index 00000000..1c6f610d
--- /dev/null
+++ b/node_modules/postcss-normalize-charset/index.js
@@ -0,0 +1,37 @@
+var postcss = require('postcss');
+
+var charset = 'charset';
+
+module.exports = postcss.plugin('postcss-normalize-' + charset, function (opts) {
+ opts = opts || {};
+
+ return function (css) {
+ var charsetRule;
+ var nonAsciiNode;
+ var nonAscii = /[^\x00-\x7F]/;
+
+ css.walk(function (node) {
+ if (node.type === 'atrule' && node.name === charset) {
+ if (!charsetRule) {
+ charsetRule = node;
+ }
+ node.remove();
+ } else if (!nonAsciiNode && node.parent === css && nonAscii.test(node)) {
+ nonAsciiNode = node;
+ }
+ });
+
+ if (nonAsciiNode) {
+ if (!charsetRule && opts.add !== false) {
+ charsetRule = postcss.atRule({
+ name: charset,
+ params: '"utf-8"'
+ });
+ }
+ if (charsetRule) {
+ charsetRule.source = nonAsciiNode.source;
+ css.prepend(charsetRule);
+ }
+ }
+ };
+});