Socket
Socket
Sign inDemoInstall

@csstools/selector-specificity

Package Overview
Dependencies
7
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

10

CHANGELOG.md
# Changes to Selector Specificity
### 2.0.0 (June 3, 2022)
- Breaking: use only named exports instead of `default`
- Added: `compare(a, b)` function to compare selectors by specificity
```diff
- `import selectorSpecificity from '@csstools/selector-specificity';`
+ `import { selectorSpecificity } from '@csstools/selector-specificity';`
```
### 1.0.0 (April 26, 2022)
- Initial version

4

dist/index.d.ts
import type { Node } from 'postcss-selector-parser';
export default function selectorSpecificity(node: Node): {
export declare type Specificity = {
a: number;

@@ -7,1 +7,3 @@ b: number;

};
export declare function selectorSpecificity(node: Node): Specificity;
export declare function compare(s1: Specificity, s2: Specificity): number;
{
"name": "@csstools/selector-specificity",
"description": "Determine selector specificity with postcss-selector-parser",
"version": "1.0.0",
"version": "2.0.0",
"contributors": [

@@ -12,3 +12,3 @@ {

{
"name": "Romain Menke ",
"name": "Romain Menke",
"email": "romainmenke@gmail.com"

@@ -56,3 +56,3 @@ }

"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",
"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"

@@ -59,0 +59,0 @@ },

@@ -17,3 +17,3 @@ # Selector Specificity

import parser from 'postcss-selector-parser';
import selectorSpecificity from '@csstools/selector-specificity';
import { selectorSpecificity } from '@csstools/selector-specificity';

@@ -31,2 +31,18 @@ const selectorAST = parser().astSync('#foo:has(> .foo)');

### Comparing
The package exports a utility function to compare two specificities.
```js
import { selectorSpecificity, compare } from '@csstools/selector-specificity';
const s1 = selectorSpecificity(ast1);
const s2 = selectorSpecificity(ast2);
compare(s1, s2); // -1 | 0 | 1
```
- if `s1 < s2` then `compare(s1, s2)` returns a negative number (`< 0`)
- if `s1 > s2` then `compare(s1, s2)` returns a positive number (`> 0`)
- if `s1 === s2` then `compare(s1, s2)` returns zero (`=== 0`)
## Prior Art

@@ -33,0 +49,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc