css-conflict-inspector
Version:
Find potential conflict in your CSS files - to avoid surprises when used in the context of Micro Frontends.
78 lines • 2.28 kB
JavaScript
function serializeOperation(op) {
if (op) {
const mapping = {
equal: '=',
includes: '~=',
'dash-match': '|=',
prefix: '^=',
substring: '*=',
suffix: '$=',
};
const o = mapping[op.operator];
return `${o}${op.value}`;
}
return '';
}
function serializeNamespace(ns) {
if (ns) {
if (ns.type === 'specific') {
return `${ns.prefix}\\:`;
}
else if (ns.type === 'any') {
return '*\\:';
}
}
return '';
}
export function stringify(selectors) {
return selectors
.map((sel) => {
switch (sel.type) {
case 'combinator':
// e.g., ">"
switch (sel.value) {
case 'descendant':
return ' ';
case 'child':
return '>';
case 'next-sibling':
return '+';
case 'later-sibling':
return '~';
}
return '';
case 'universal':
// e.g., "*"
return '*';
case 'type':
// e.g., "p"
return sel.name;
case 'class':
// e.g., ".foo"
return `.${sel.name}`;
case 'id':
// e.g., "#foo"
return `#${sel.name}`;
case 'attribute':
// e.g., "hidden"
return `[${serializeNamespace(sel.namespace)}${sel.name}${serializeOperation(sel.operation)}]`;
case 'pseudo-class':
// e.g., ":where"
if (Array.isArray(sel.selectors)) {
const inner = stringify(sel.selectors);
return `:${sel.kind}(${inner})`;
}
return `:${sel.kind}`;
case 'pseudo-element':
return `::${sel.kind}`;
default: {
if (Array.isArray(sel)) {
return stringify(sel);
}
return '';
}
}
})
.join('');
}
//# sourceMappingURL=stringify.js.map