Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

import { calculate } from '../dist/esm/index.js';

const selector = process.argv[2];
if (selector) {
const { A, B, C } = calculate(selector);
const formatted = `${A},${B},${C}`;
console.log(formatted);
} else {
console.log('Usage: specificity <selector>');
console.log('Computes the specificity of a CSS selector.');
process.exit(1);
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
},
"./package.json": "./package.json"
},
"bin": {
"specificity": "./bin/cli.js"
},
"scripts": {
"prebuild": "rm -rf ./dist",
"build": "tsc -b ./tsconfig.json ./tsconfig.cjs.json && cp package-cjs.json dist/cjs/package.json",
Expand Down
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,20 @@ Returns `0` if `a` has the same specificity than `b`
## compareDesc(a, b)

Same as `compare` but returns the opposite value, for use in sorting specificity objects with the highest specificity first.

## Command-line usage

Run `npm install specificity` to install the module locally, or `npm install -g specificity` for global installation. Run `specificity` without arguments to learn about its usage:

```
$ specificity
Usage: specificity <selector>
Computes the specificity of a CSS selector.
```

Pass a selector as the first argument to get its specificity computed:

```
$ specificity "ul#nav li.active a"
1,1,3
```