How to use the specificity.compare function in specificity

To help you get started, we’ve selected a few specificity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stylelint / stylelint / lib / rules / selector-max-specificity / index.js View on Github external
parseSelector(resolvedSelector, result, rule, (selectorTree) => {
							// Check if the selector specificity exceeds the allowed maximum
							if (
								specificity.compare(maxChildSpecificity(selectorTree), maxSpecificityArray) === 1
							) {
								report({
									ruleName,
									result,
									node: rule,
									message: messages.expected(resolvedSelector, max),
									word: selector,
								});
							}
						});
					} catch (e) {
github alexjlockwood / ShapeShifter / src / app / scripts / parsers / svgo / svgo.ts View on Github external
var selectorItemsSorted = stable(selectorItemsPseudoClasses, function (itemA, itemB) {
    return specificity.compare(itemA.selectorStr, itemB.selectorStr);
  }).reverse(); // last declaration applies last (final)
github stylelint / stylelint / lib / rules / selector-max-specificity / index.js View on Github external
node.reduce((max, child) => {
				const childSpecificity = nodeSpecificity(child); // eslint-disable-line no-use-before-define

				return specificity.compare(childSpecificity, max) === 1 ? childSpecificity : max;
			}, zeroSpecificity());
github ant-motion / editor-list / src / utils.js View on Github external
Object.keys(styleObj).sort((a, b) => {
    const aArray = a.split('~');
    const bArray = b.split('~');
    return specificity.compare(aArray[0], bArray[0]) ||
      parseFloat(aArray[1]) - parseFloat(bArray[1]) ||
      parseFloat(aArray[2]) - parseFloat(bArray[2]) ||
      aArray.length - bArray.length ||
      parseFloat(aArray[3]) - parseFloat(bArray[3]);
  }).forEach(key => {
    style += styleObj[key];
github linkedin / opticss / src / optimizations / ShareDeclarations.ts View on Github external
this.selectorTree = new BSTree((s1, s2) => {
      let cmp = specificity.compare(s1.specificity.specificityArray, s2.specificity.specificityArray);
      if (cmp === 0) cmp = compare(s1.fileIndex, s2.fileIndex);
      if (cmp === 0) cmp = compare(s1.sourceIndex, s2.sourceIndex);
      return cmp;
    });
    this.elementSelectors = new Map();
github projectwallace / css-analyzer / src / analyzer / selectors / specificity.js View on Github external
    selector => compare(selector.value, maxSpecificitySelector.value) === 0
  )
github whinc / web-console / src / utils / style.js View on Github external
selectorArr.forEach(v => {
      if (compare(v, _selector) === 1) {
        _selector = v;
      }
    });
  } else {
github linkedin / opticss / packages / resolve-cascade / src / Cascade.ts View on Github external
this.matchedSelectors.sort((a, b) => {
        let cmp = specificity.compare(a.specificity.specificityArray,
                                      b.specificity.specificityArray);
        if (cmp === 0) {
          return (indexMap.get(a)! < indexMap.get(b)!) ? -1 : 1;
        } else {
          return cmp;
        }
      });
    }
github stylelint / stylelint / lib / rules / no-descending-specificity / index.js View on Github external
priorComparableSelectors.forEach((priorEntry) => {
				if (specificity.compare(selectorSpecificity, priorEntry.specificity) === -1) {
					report({
						ruleName,
						result,
						node: rule,
						message: messages.rejected(selector, priorEntry.selector),
						index: sourceIndex,
					});
				}
			});

specificity

Calculate the specificity of a CSS selector

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Popular specificity functions