Opal-Estate-Pro/node_modules/postcss-normalize-charset/index.js
2019-09-13 11:27:52 +07:00

38 lines
1.0 KiB
JavaScript
Executable File

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);
}
}
};
});