{"name":"@csstools/selector-specificity","description":"Determine selector specificity with postcss-selector-parser","version":"2.2.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":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.cjs","default":"./dist/index.mjs"}},"peerDependencies":{"postcss-selector-parser":"^6.0.10"},"devDependencies":{"postcss-selector-parser":"^6.0.10"},"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":"89e7c02b95e176bb1243d648d14be67d52b796e2","_id":"@csstools/selector-specificity@2.2.0","_nodeVersion":"18.13.0","_npmVersion":"9.4.1","dist":{"integrity":"sha512-+OJ9konv95ClSTOJCmMZqpd5+YGsB2S+x6w3E1oaM8UuR5j8nTNHYSz8c9BEPGDOCMQYIEEGlVPj/VY64iTbGw==","shasum":"2cbcf822bf3764c9658c4d2e568bd0c0cb748016","tarball":"http://registry-npm.ywwl.com/@csstools/selector-specificity/download/@csstools/selector-specificity-2.2.0.tgz","fileCount":7,"unpackedSize":16718,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIF5uCEeBaeENaqOYayMVXrxmw/aHAcQ2jrqGDW+eep/VAiEApnVg55kxwkY1Xrmca8k0VopD2Zt0SSTmnJ6zB1kh1js="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkGXPtACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp7Bw//U/oV0jdFD6orx4b5SwDfKgbGdnKk649m4l2Zhf1bSEhBzxTA\r\n5NAXkyPMppbR+aPSO6fZXm8P/qMjGDQ0qEZEXgni3yP/WWzELrPLNn0s2emC\r\nBtukmL5iF00buieb8g1Q0NyueYKU98sikX7x52+ny3f/Q5osWoeV4B5TND1S\r\nhGIguSCR61mE110AsyRI9TZRCiI3lvTc/nFWBmy+hKjw/t/CG7bjSjIvPwDB\r\nbHsL4jKBkPNQGW4pijMJbahnxfC7l8TZMDpuSJCnnXTEVouoa9uSP7FNHX7U\r\nZT5eBXRqwnDq+voCFA119GZyMai+72fLwItNX3gHPM9vDzDKqX+bcKz8gkKa\r\n8umFzu2jUkiuRIcWuaRHIFiqHA8iZDskkztwGIMZGfLdNWGZLGcLXBQqeChq\r\ne9nhvZegKnK8+mfSrokKcFwG2qZQtRR3cIvieoi9H0HyO4zwOPoJPIwyYDGh\r\n6po4ziBOIYR/WCM2Cnzc+X6j8TM0sMGinKDgmqSN3F9bG1vdGNmq07OhJw34\r\nsXow0N25Q8SX5FZC+3KOqa+Um4RM6gFN/LmQxkBMPdMMsiQsyYuGuitME6e3\r\nXCPanRBPlVxcJOslvtRn7HBdZ789PxIdjDq1JJCLs7w9Zoxw+H1UKuCvIae+\r\nAC2mB8JbtdqfQqy2cquEKlDrAHiZ3ziLEes=\r\n=hEOD\r\n-----END PGP SIGNATURE-----\r\n","size":5481,"noattachment":false,"key":"/@csstools/selector-specificity/-/@csstools/selector-specificity-2.2.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.2.0_1679389677228_0.9257955883830253"},"_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":1679389677372,"_cnpm_publish_time":1679389677372,"dist-tags":{"latest":"6.0.1"}}