All files / src/utils declarationValueIndex.js

100% Statements 8/8
47.06% Branches 8/17
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 293x                 7x 7x   7x             35x 14x     21x       3x  
const validateTypes = require("./validateTypes");
 
/**
 * Get the index of a declaration's value
 *
 * @param {import('postcss').Declaration} decl
 * @returns {number}
 */
function declarationValueIndex(decl) {
  const raws = decl.raws;
  const prop = raws.prop;
 
  return [
    validateTypes.isObject(prop) && "prefix" in prop && prop.prefix,
    (validateTypes.isObject(prop) && "raw" in prop && prop.raw) || decl.prop,
    validateTypes.isObject(prop) && "suffix" in prop && prop.suffix,
    raws.between || ":",
    raws.value && "prefix" in raws.value && raws.value.prefix
  ].reduce((/** @type {number} */ count, str) => {
    if (validateTypes.isString(str)) {
      return count + str.length;
    }
 
    return count;
  }, 0);
}
 
module.exports = declarationValueIndex;