{"name":"@csstools/selector-specificity","description":"Determine selector specificity with postcss-selector-parser","version":"2.0.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":"^12 || ^14 || >=16"},"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.3","postcss-selector-parser":"^6.0.10"},"devDependencies":{"postcss-selector-parser":"^6.0.10"},"scripts":{"build":"rollup -c ../../rollup/default.js","clean":"node -e \"fs.rmSync('./dist', { recursive: true, force: true });\"","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":"16a4ac080a0a7f4988887950ef4de18aa266edb7","_id":"@csstools/selector-specificity@2.0.0","_nodeVersion":"16.13.1","_npmVersion":"8.1.2","dist":{"integrity":"sha512-rZ6vufeY/UjAgtyiJ4WvfF6XP6HizIyOfbZOg0RnecIwjrvH8Am3nN1BpKnnPZunYAkUcPPXDhwbxOtGop8cfQ==","shasum":"65b12f12db55188422070e34687bf3af09870922","tarball":"http://registry-npm.ywwl.com/@csstools/selector-specificity/download/@csstools/selector-specificity-2.0.0.tgz","fileCount":7,"unpackedSize":14518,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAbACW6P2LCjx1BkaqoZUHiSLXBo7ojSykIvHrP4cz9vAiEAqcwavFZGolcsgBZIFJa5tyinTKgohP988SsDw/FDPsk="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJimwUFACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmq1ig/+Kl/r1G+FYDkeaMYTkYAo1leOrORYUm2qUyROEqJVVvJ0Evy4\r\nEIJnBFv7RChmdxsLMvIYxTJ0OXLF9KldyFpjnySjnwCp6iLzLLjt3pQ/lqu2\r\nV53vTzgSWz8/fjNZwqgPiCdiLir9wMucetSdEAQMhTRCvmSYUOJjXh10CSsS\r\n7fsc3AjAHlwrxteyEEcyAGquZsoFITkiDRrdT2u2uD+ayOlNj6f14dbvuN64\r\neU8ULxkDjUGDKbeOdNi3Ti+DWnVur2R9Xzzr8RHZHwWjNsVOFLJ2S1mXP9VI\r\nsvQwYTAc4vOgG0JSEeZi0HYH37k0exBTlW0pQ/vgp86pQTLpRNU486AVY6CJ\r\nTcq6Voe2F6q18ykp8hhgRqD39f2cmAP65mvELRUKEblIEmipZUzlPumnJNWV\r\n1V8+WGY6HQstroogUl+yyI9wYNM/Lf6Y1ops75zUB0qinjAWWgzifDr/yi1v\r\nTmRorVZs87oMWAp/FL7BQC+/mGjdy7RJ+kLXSq/E2R2FzP+hnUCS6pg+KgOp\r\nLLLpZjkC4mv8j3j2xzxnaMJucphH08zEKvgFGRqXAfVZfLToxG5c3wXBrqxz\r\n+tPE+eRgihTXqSGntQ4zCSPJYN75SJ2VkhUGXemokxLqTDiYLy4He9VIpege\r\nhN3wkdD7p+/jTbdG6zVYREhxS4bitMErb/8=\r\n=MzjM\r\n-----END PGP SIGNATURE-----\r\n","size":5516,"noattachment":false,"key":"/@csstools/selector-specificity/-/@csstools/selector-specificity-2.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_2.0.0_1654326533076_0.017308726541886532"},"_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":1654326533244,"_cnpm_publish_time":1654326533244,"dist-tags":{"latest":"6.0.1"}}