{"name":"specificity","version":"1.0.0-beta","description":"Calculate the specificity of a CSS selector","keywords":["CSS","specificity"],"homepage":"https://github.com/keeganstreet/specificity","author":{"name":"Keegan Street","url":"http://keegan.st"},"repository":{"type":"git","url":"git+https://github.com/keeganstreet/specificity.git"},"license":"MIT","bugs":{"url":"https://github.com/keeganstreet/specificity/issues"},"type":"module","module":"./dist/esm/index.js","main":"./dist/cjs/index.js","types":"./dist/types/index.d.ts","exports":{".":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"./package.json":"./package.json"},"scripts":{"prebuild":"rm -rf ./dist","build":"tsc -b ./tsconfig.json ./tsconfig.cjs.json && cp package-cjs.json dist/cjs/package.json","test":"jest && node test/test-esm.mjs && node test/test-cjs.cjs"},"devDependencies":{"@jest/globals":"^29.5.0","@types/css-tree":"^2.3.1","jest":"^29.5.0","prettier":"^2.8.8","ts-jest":"^29.1.0","typescript":"^5.1.3"},"dependencies":{"css-tree":"^2.3.1"},"gitHead":"f8d583cb31e6648d57fb933583bc4747e9f6f4c8","readme":"# Specificity Calculator\n\nA JavaScript module for calculating and comparing the [specificity of CSS selectors](https://www.w3.org/TR/selectors-4/#specificity). The module is used on the [Specificity Calculator](https://specificity.keegan.st/) website.\n\nNote that version 1 is a complete re-write with support for CSS Selectors Level 4, and has a different API than earlier versions.\n\n## calculate(selector)\n\n### Parameters\n\n- `selector`: `string` - should be a valid CSS selector\n\n### Returns\n\nA `Specificity` object with a type of `Record<\"A\" | \"B\" | \"C\", number>`.\n\n### Examples\n\n```js\ncalculate(\"#id\");\n{\n  A: 1,\n  B: 0,\n  C: 0\n}\n\ncalculate(\".classname\");\n{\n  A: 0,\n  B: 1,\n  C: 0\n}\n\ncalculate(\"element\");\n{\n  A: 0,\n  B: 0,\n  C: 1\n}\n\ncalculate('ul#nav li.active a');\n{\n  A: 1,\n  B: 1,\n  C: 3\n}\n```\n\n## compare(a, b)\n\n### Parameters\n\n- `a`: `Specificity` object with a type of `Record<\"A\" | \"B\" | \"C\", number>`\n- `b`: `Specificity` object with a type of `Record<\"A\" | \"B\" | \"C\", number>`\n\n### Returns\n\nReturns a positive number if `a` has a higher specificity than `b`\nReturns a negative number if `a` has a lower specificity than `b`\nReturns `0` if `a` has the same specificity than `b`\n\n### Examples\n\n```js\n[\n  \"element\",\n  \".classname\",\n  \"#id\",\n]\n  .map(calculate)\n  .sort(compare);\n\n[ { A: 0, B: 0, C: 1 }, { A: 0, B: 1, C: 0 }, { A: 1, B: 0, C: 0 } ]\n```\n\n## compareDesc(a, b)\n\nSame as `compare` but returns the opposite value, for use in sorting specificity objects with the highest specificity first.\n","readmeFilename":"readme.md","_id":"specificity@1.0.0-beta","_nodeVersion":"20.3.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-t8GuLmK/EFc+reEpvgAm3ktbnbQFFrjVhLHsjOCQGclBwzIbIi6CeoyKN6ep4urJjwsYnjrYPHwxq3muCESO0w==","shasum":"d776d1c0363ce135cd9f84e7bf0a86e0da136fae","tarball":"http://registry-npm.ywwl.com/specificity/download/specificity-1.0.0-beta.tgz","fileCount":28,"unpackedSize":34067,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0YO9JsqpNOvRMBOj/j3/kKH0N7kAdkQyhO/ludfX3pQIhALC4g2ucLu2RnlNDAf8rI/76C0HnVYQt28yhxkqAwiSh"}],"size":6729,"noattachment":false,"key":"/specificity/-/specificity-1.0.0-beta.tgz"},"_npmUser":{"name":"keeganstreet","email":"keeganstreet@gmail.com"},"directories":{},"maintainers":[{"name":"keeganstreet","email":"keeganstreet@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/specificity_1.0.0-beta_1687510348150_0.4983683406468762"},"_hasShrinkwrap":false,"publish_time":1687510348328,"_cnpm_publish_time":1687510348328,"dist-tags":{"latest":"1.0.0","next":"1.0.0-beta"}}