{"name":"@csstools/selector-specificity","description":"Determine selector specificity with postcss-selector-parser","version":"3.0.0","contributors":[{"name":"Antonio Laguna","email":"antonio@laguna.es","url":"https://antonio.laguna.es"},{"name":"Romain Menke","email":"romainmenke@gmail.com"}],"license":"MIT-0","funding":[{"type":"github","url":"https://github.com/sponsors/csstools"},{"type":"opencollective","url":"https://opencollective.com/csstools"}],"engines":{"node":"^14 || ^16 || >=18"},"main":"dist/index.cjs","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs","default":"./dist/index.mjs"}},"peerDependencies":{"postcss-selector-parser":"^6.0.13"},"devDependencies":{"postcss-selector-parser":"^6.0.13"},"scripts":{"build":"rollup -c ../../rollup/default.mjs","lint":"node ../../.github/bin/format-package-json.mjs","prepublishOnly":"npm run build && npm run test","stryker":"stryker run --logLevel error","test":"node ./test/index.mjs && node ./test/_import.mjs && node ./test/_require.cjs"},"homepage":"https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity#readme","repository":{"type":"git","url":"git+https://github.com/csstools/postcss-plugins.git","directory":"packages/selector-specificity"},"bugs":{"url":"https://github.com/csstools/postcss-plugins/issues"},"keywords":["css","postcss-selector-parser","specificity"],"volta":{"extends":"../../package.json"},"gitHead":"d5bf6e582b96443a4a56fb3385f2b33642ce5370","_id":"@csstools/selector-specificity@3.0.0","_nodeVersion":"18.15.0","_npmVersion":"9.5.0","dist":{"integrity":"sha512-hBI9tfBtuPIi885ZsZ32IMEU/5nlZH/KOVYJCOh7gyMxaVLGmLedYqFN6Ui1LXkI8JlC8IsuC0rF0btcRZKd5g==","shasum":"798622546b63847e82389e473fd67f2707d82247","tarball":"http://registry-npm.ywwl.com/@csstools/selector-specificity/download/@csstools/selector-specificity-3.0.0.tgz","fileCount":8,"unpackedSize":11415,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDDjdmnYsbNX1lut2/jKCVOPETnHk925sdg3wdnErI+dAIhAL+EPuS0HhBLE5a90QAsbLsXXtSiyUQcvbtHRqHU89XU"}],"size":3727,"noattachment":false,"key":"/@csstools/selector-specificity/-/@csstools/selector-specificity-3.0.0.tgz"},"_npmUser":{"name":"alaguna","email":"sombragriselros@gmail.com"},"directories":{},"maintainers":[{"name":"alaguna","email":"sombragriselros@gmail.com"},{"name":"jonathantneal","email":"jonathantneal@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/selector-specificity_3.0.0_1688371694520_0.5247261307683786"},"_hasShrinkwrap":false,"readme":"# Selector Specificity\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/workflows/test/badge.svg\" 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\n[Selector Specificity]: https://github.com/csstools/postcss-plugins/tree/main/packages/selector-specificity\n","publish_time":1688371694700,"_cnpm_publish_time":1688371694700,"dist-tags":{"latest":"6.0.1"}}