{"name":"@csstools/selector-specificity","description":"Determine selector specificity with postcss-selector-parser","version":"2.1.0","contributors":[{"name":"Antonio Laguna","email":"antonio@laguna.es","url":"https://antonio.laguna.es"},{"name":"Romain Menke","email":"romainmenke@gmail.com"}],"license":"CC0-1.0","funding":{"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":{".":{"import":"./dist/index.mjs","require":"./dist/index.cjs","default":"./dist/index.mjs"}},"peerDependencies":{"postcss":"^8.4","postcss-selector-parser":"^6.0.10"},"devDependencies":{"postcss-selector-parser":"^6.0.10"},"scripts":{"prebuild":"npm run clean","build":"rollup -c ../../rollup/default.mjs","clean":"node -e \"fs.rmSync('./dist', { recursive: true, force: true }); fs.mkdirSync('./dist');\"","lint":"npm run lint:eslint && npm run lint:package-json","lint:eslint":"eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern","lint:package-json":"node ../../.github/bin/format-package-json.mjs","prepublishOnly":"npm run clean && npm run build && npm run test","stryker":"stryker run --logLevel error","test":"npm run test:exports && node ./test/example.mjs && node ./test/test.mjs && node ./test/tests-from-bramus-specificity.mjs && node ./test/tests-from-keeganstreet-specificity.mjs && node ./test/test-compare.mjs","test:exports":"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":"8ebb6d6c55c8f3adaf80ef2adc1ca952fa8d539c","_id":"@csstools/selector-specificity@2.1.0","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-zJ6hb3FDgBbO8d2e83vg6zq7tNvDqSq9RwdwfzJ8tdm9JHNvANq2fqwyRn6mlpUb7CwTs5ILdUrGwi9Gk4vY5w==","shasum":"923ebf8ba47e854863ae72510d9cbf7b44d525ea","tarball":"http://registry-npm.ywwl.com/@csstools/selector-specificity/download/@csstools/selector-specificity-2.1.0.tgz","fileCount":7,"unpackedSize":15914,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICXsS6J4NBn7KBiiyECAdBv+goPhKn2JhCDcSLvmFXKtAiEAl8J/Mfm4nCZqeQ4dkEMlqjMkG0ba9BPq7MBNBUXlrcM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjyZQyACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpiQA//UNt3XR9vJINV7Padn0FwJ0XWt8/mTWb4f6w8PPkSHnFIPSMQ\r\n6xoHE9jajVkmHSF+2pEBvpr9Z1tzi3qRhROB4VWWokiM3MyeDngHLw/5NbMe\r\nob8Lcczhs0rPtk6G87K1ohtrQ8fzf6+JxOdIARIZC4GNh68FNhoh/PjRZSu5\r\ndJomq3jdGf+L/dXgaUFkcnF+9TjbhBU7vLSavcmEkwWvxYMutQ7T7FCwxgTA\r\nAAFmLr1Pjrn3YmRpt3V15352AKuZkYK3iskLt/rkLE61Klk9r8NbLyT64M+E\r\n5u1xn0zMWio8Kpf2SbILReKHO3IUhUnHoNTBZqCmeLs0R+1HbIVu4fvH4H7o\r\nqKa5jz6fSJCOeg4CMRhIr6jngVqZsjcVJJSCrXtVKChDujafEjM4kQLeXhPR\r\n8xA08T+SoAu8g315qH05yGpcnxkVsKTeGHhOrBTIOyJ0zfnkFaX98D8YcOy5\r\n+YJzoUrBtjm8ildmzyltqfoFbZ1mfL8P/pxUDGj27STfcp9VUZYSZno5ml4k\r\nglB6MMx4eTnn+jnT5Q97Uk5qSG7HRnjPCL8rmsYb9sA6JduHv+071RE08o/i\r\nXDRuexnbjbwDZ7ryUnZAF6MLOaSLjNE0g4VSsG8yqIsRV5PGMaVq7HqYjHwL\r\ntvNom6YI4FY6KN1j1QYFH6+4/DrNf33yUOs=\r\n=lk9H\r\n-----END PGP SIGNATURE-----\r\n","size":5435,"noattachment":false,"key":"/@csstools/selector-specificity/-/@csstools/selector-specificity-2.1.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_2.1.0_1674155057812_0.03272184167265624"},"_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":1674155058031,"_cnpm_publish_time":1674155058031,"dist-tags":{"latest":"6.0.1"}}