0.2.3 • Published 1 year ago

selector-specificity v0.2.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Installation

npm install selector-specificity

Usage

// CommonJS
const specificity = require('selector-specificity')
// ESModule
import specificity from 'selector-specificity'
const s = 'div:nth-of-type(2n) > span .foo + .bar.baz ~ .qux a[quux=corge]:not(.grault)'

specificity.getNodes(s)
// [
//   { type: "element", name: "div", specificity: 1 },
//   { 
//     type: "pseudo-class", 
//     name: "nth-of-type", 
//     specificity: 10, 
//     value: "2n" 
//   }, 
//   { type: "child" }, 
//   { type: "element", name: "span", specificity: 1 }, 
//   { type: "descendant" }, 
//   { type: "class", name: "foo", specificity: 10 }, 
//   { type: "adjacent" }, 
//   { type: "class", name: "bar", specificity: 10 }, 
//   { type: "class", name: "baz", specificity: 10 }, 
//   { type: "sibling" }, 
//   { type: "class", name: "qux", specificity: 10 }, 
//   { type: "descendant" }, 
//   { type: "element", name: "a", specificity: 1 }, 
//   { type: "attribute", name: "quux", value: "corge", specificity: 10 }, 
//   { 
//     type: "pseudo-class", 
//     name: "not", specificity: 10, 
//     "innerNodes": [{ type: "class", name: "grault" }] 
//   }
// ]

specificity.getSpecificity(s) // -> 73

specificity.compare('#foo', 'div') // -> 1
specificity.compare('div', 'span') // -> 0
specificity.compare('div', '#foo') // -> -1
0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.0

1 year ago

8.0.11

1 year ago