Skip to content

Commit cc7a5d0

Browse files
authored
V4 (#88)
1 parent 9a2d569 commit cc7a5d0

File tree

13 files changed

+9770
-4683
lines changed

13 files changed

+9770
-4683
lines changed

.github/workflows/check.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Check
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
code-style:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- run: npm i
11+
- run: npm run fmt:check

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
node-version: [16.x, 18.x]
10+
node-version: [20.x, 22.x]
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- name: Use Node.js ${{ matrix.node-version }}
14-
uses: actions/setup-node@v3
14+
uses: actions/setup-node@v4
1515
with:
1616
node-version: ${{ matrix.node-version }}
1717
- run: npm i

README.md

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
## Features
1010

11-
* Generates the **shortest** selector
12-
* **Unique** selectors per page
13-
* Stable and **robust** selectors
14-
* **2kB** minified + gzipped
11+
* Generates **shortest** CSS selectors.
12+
* **Unique** CSS selectors per page.
13+
* Stable and **robust** CSS selectors.
14+
* Size: **1.5kb** (minified & gzipped).
1515

1616
## Install
1717

@@ -34,52 +34,35 @@ document.addEventListener('click', (event) => {
3434
An example of a generated selector:
3535

3636
```css
37-
.blog > article:nth-child(3) .add-comment
37+
.blog > article:nth-of-type(3) .add-comment
3838
```
3939

4040
## Configuration
4141

4242
```js
4343
const selector = finder(event.target, {
44-
root: document.body, // Root of search, defaults to document.body.
45-
idName: (name) => true, // Check if this ID can be used.
46-
className: (name) => true, // Check if this class name can be used.
47-
tagName: (name) => true, // Check if tag name can be used.
48-
attr: (name, value) => false, // Check if attr name can be used.
49-
seedMinLength: 1,
44+
root: document.body,
45+
timeoutMs: 1000,
46+
seedMinLength: 3,
5047
optimizedMinLength: 2,
51-
threshold: 1000,
52-
maxNumberOfTries: 10_000,
53-
timeoutMs: undefined,
5448
});
5549
```
5650

57-
### seedMinLength
58-
59-
Minimum length of levels in fining selector. Starts from `1`.
60-
For more robust selectors give this param value around 4-5 depending on depth of
61-
you DOM tree. If finder hits the `root`, this param is ignored.
62-
63-
### optimizedMinLength
51+
### root
6452

65-
Minimum length for optimising selector. Starts from `2`.
66-
For example selector `body > div > div > p` can be optimised to `body p`.
53+
Defines the root of the search. Defaults to `document.body`.
6754

68-
### threshold
55+
### timeoutMs
6956

70-
Max number of selectors to check before falling into `nth-child` usage.
71-
Checking for uniqueness of selector is very costly operation, if you have DOM
72-
tree depth of 5, with 5 classes on each level, that gives you more than 3k
73-
selectors to check. Default `1000` is good enough in most cases.
57+
Timeout to search for a selector. Defaults to `1000ms`. After the timeout, finder fallbacks to `nth-child` selectors.
7458

75-
### maxNumberOfTries
59+
### seedMinLength
7660

77-
Max number of tries for the optimization. This is a trade-off between
78-
optimization and efficiency. Default `10_000` is good enough in most cases.
61+
Minimum length of levels in fining selector. Defaults to `3`.
7962

80-
### timeoutMs
63+
### optimizedMinLength
8164

82-
Optional timeout in milliseconds. `undefined` (no timeout) by default. If `timeoutMs: 500` is provided, an error will be thrown if selector generation takes more than 500ms.
65+
Minimum length for optimising selector. Defaults to `2`.
8366

8467
## License
8568

0 commit comments

Comments
 (0)