{"_id":"@csstools/selector-specificity@6.0.1","bugs":{"url":"https://github.com/csstools/postcss-plugins/issues"},"dist":{"shasum":"7c5f0ef843e1bc8dd0c2438be134bd31bf298622","tarball":"http://registry-npm.ywwl.com/@csstools/selector-specificity/download/@csstools/selector-specificity-6.0.1.tgz","fileCount":6,"integrity":"sha512-MBuqFIIvqk4S593MGAskTkPpEUUzZNvGzh8mMxEwl3oHwjQlXmqHEDxNbN3Y0Tsh+xjmem4GZjeg7I0qkwBivg==","signatures":[{"sig":"MEUCIGOx8NSNhicB6HYF7GqQzbvP+aGqjMu+SKcjAWuD2ZDLAiEAogVqkTJ5Fb6mIppVDSEfYHHEZwEERt00Xhb4IoARtu8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCOlRjBCQI+YCh8+5zuCxpkRUmjLTkwYFRGApfEOGO0/QIhAIJyO7eb/8lSxmXyr+pEorMM33iimNVCLXnqTQQZ/e6v"}],"unpackedSize":8918,"size":3515,"noattachment":false,"key":"/@csstools/selector-specificity/-/@csstools/selector-specificity-6.0.1.tgz"},"name":"@csstools/selector-specificity","type":"module","engines":{"node":">=20.19.0"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.mjs"}},"funding":[{"url":"https://github.com/sponsors/csstools","type":"github"},{"url":"https://opencollective.com/csstools","type":"opencollective"}],"gitHead":"9c5764248350e92b002c00a07ec477495ac53214","license":"MIT-0","scripts":{},"version":"6.0.1","_npmUser":{"name":"romainmenke","email":"romainmenke@gmail.com"},"homepage":"https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity#readme","keywords":["css","postcss-selector-parser","selector","specificity"],"repository":{"url":"git+https://github.com/csstools/postcss-plugins.git","type":"git","directory":"packages/selector-specificity"},"_npmVersion":"11.13.0","description":"Determine selector specificity with postcss-selector-parser","directories":{},"maintainers":[{"name":"jonathantneal","email":"jonathantneal@hotmail.com"},{"name":"alaguna","email":"sombragriselros@gmail.com"},{"name":"romainmenke","email":"romainmenke@gmail.com"}],"_nodeVersion":"26.1.0","contributors":[{"url":"https://antonio.laguna.es","name":"Antonio Laguna","email":"antonio@laguna.es"},{"name":"Romain Menke","email":"romainmenke@gmail.com"}],"_hasShrinkwrap":false,"peerDependencies":{"postcss-selector-parser":"^7.1.1"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/selector-specificity_6.0.1_1791230196266_0.1488991253245049"},"readme":"# Selector Specificity [<img src=\"https://postcss.github.io/postcss/logo.svg\" alt=\"for PostCSS\" width=\"90\" height=\"90\" align=\"right\">][postcss]\n\n[<img alt=\"npm version\" src=\"https://img.shields.io/npm/v/@csstools/selector-specificity.svg\" height=\"20\">][npm-url]\n[<img alt=\"Build Status\" src=\"https://github.com/csstools/postcss-plugins/actions/workflows/test.yml/badge.svg?branch=main\" height=\"20\">][cli-url]\n[<img alt=\"Discord\" src=\"https://shields.io/badge/Discord-5865F2?logo=discord&logoColor=white\">][discord]\n\n## Usage\n\nAdd [Selector Specificity] to your project:\n\n```bash\nnpm install @csstools/selector-specificity --save-dev\n```\n\n```js\nimport parser from 'postcss-selector-parser';\nimport { selectorSpecificity } from '@csstools/selector-specificity';\n\nconst selectorAST = parser().astSync('#foo:has(> .foo)');\nconst specificity = selectorSpecificity(selectorAST);\n\nconsole.log(specificity.a); // 1\nconsole.log(specificity.b); // 1\nconsole.log(specificity.c); // 0\n```\n\n_`selectorSpecificity` takes a single selector, not a list of selectors (not : `a, b, c`).\nTo compare or otherwise manipulate lists of selectors you need to call `selectorSpecificity` on each part._\n\n### Comparing\n\nThe package exports a utility function to compare two specificities.\n\n```js\nimport { selectorSpecificity, compare } from '@csstools/selector-specificity';\n\nconst s1 = selectorSpecificity(ast1);\nconst s2 = selectorSpecificity(ast2);\ncompare(s1, s2); // -1 | 0 | 1\n```\n\n- if `s1 < s2` then `compare(s1, s2)` returns a negative number (`< 0`)\n- if `s1 > s2` then `compare(s1, s2)` returns a positive number (`> 0`)\n- if `s1 === s2` then `compare(s1, s2)` returns zero (`=== 0`)\n\n## Prior Art\n\n- [keeganstreet/specificity](https://github.com/keeganstreet/specificity)\n- [bramus/specificity](https://github.com/bramus/specificity)\n\nFor CSSTools we always use `postcss-selector-parser` and want to calculate specificity from this AST.\n\n[cli-url]: https://github.com/csstools/postcss-plugins/actions/workflows/test.yml?query=workflow/test\n[discord]: https://discord.gg/bUadyRwkJS\n[npm-url]: https://www.npmjs.com/package/@csstools/selector-specificity\n[postcss]: https://github.com/postcss/postcss\n\n[Selector Specificity]: https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity\n","publish_time":1791230196345,"_cnpm_publish_time":1791230196345,"dist-tags":{"latest":"6.0.1"}}