This repository has been archived on 2020-11-02. You can view files and clone it, but cannot push or open issues or pull requests.
2020-11-01 22:46:04 +00:00

30 lines
691 B
JavaScript

/* eslint no-param-reassign: off */
const tokenize = require('postcss/lib/tokenize');
const urlPattern = /^url\((.+)\)/;
module.exports = (node) => {
const { name, params = '' } = node;
if (name === 'import' && params.length) {
node.import = true;
const tokenizer = tokenize({ css: params });
node.filename = params.replace(urlPattern, '$1');
while (!tokenizer.endOfFile()) {
const [type, content] = tokenizer.nextToken();
if (type === 'word' && content === 'url') {
return;
} else if (type === 'brackets') {
node.options = content;
node.filename = params.replace(content, '').trim();
break;
}
}
}
};