All files / postcss parse-attribute-nodes.js

100% Statements 10/10
100% Branches 2/2
100% Functions 2/2
100% Lines 10/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 201x 1x   1x 6x 2x 2x 2x 2x 2x                 1x  
const parser = require('postcss-selector-parser');
const { unique } = require('shorthash');
 
const parseAttributeNodes = (id, componentName, nodes) =>
  nodes.map(node => {
    const { operator, attribute, raws: { unquoted, insensitive }} = node;
    const attributeId = operator ? unique(operator + unquoted) : '';
    const attributeClassName = `${ componentName }-${ attribute }_${ attributeId }_${ id }`;
    node.replaceWith(parser.className({ value: attributeClassName }));
    return {
      operator,
      name: attribute,
      value: unquoted,
      insensitive,
      className: attributeClassName,
    };
  });
 
module.exports = parseAttributeNodes;