@library/dom 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,19 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
[1m[30m[46m RUN [49m[39m[22m [36mv5.0.3 [39m[90m/Users/yeonjuan/Desktop/projects/library/packages/dom[39m
|
|
3
|
-
[2mCoverage enabled with [22m[33mv8[39m
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
[2m
|
|
9
|
-
[2m
|
|
10
|
-
[2m
|
|
11
|
-
|
|
12
|
-
[
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
[?25l
|
|
2
|
+
[1m[30m[46m RUN [49m[39m[22m [36mv5.0.3 [39m[90m/Users/yeonjuan/Desktop/projects/library/packages/dom[39m
|
|
3
|
+
[2mCoverage enabled with [22m[33mv8[39m
|
|
4
|
+
|
|
5
|
+
[?2026h
|
|
6
|
+
[1m[33m ❯ [39m[22msrc/uniqueSelectorOf.spec.ts[2m [queued][22m
|
|
7
|
+
|
|
8
|
+
[2m Test Files [22m[1m[32m0 passed[39m[22m[90m (1)[39m
|
|
9
|
+
[2m Tests [22m[1m[32m0 passed[39m[22m[90m (0)[39m
|
|
10
|
+
[2m Start at [22m22:55:01
|
|
11
|
+
[2m Duration [22m605ms
|
|
12
|
+
[?2026l[?2026h[K[1A[K[1A[K[1A[K[1A[K[1A[K[1A[K[1A[K [32m✓[39m src/uniqueSelectorOf.spec.ts [2m([22m[2m18 tests[22m[2m)[22m[32m 24[2mms[22m[39m
|
|
13
|
+
[32m✓[39m uniqueSelectorOf [2m(18)[22m
|
|
14
|
+
[32m✓[39m should return ID selector when element has an ID[32m 4[2mms[22m[39m
|
|
15
|
+
[32m✓[39m should return unique class selector[32m 5[2mms[22m[39m
|
|
16
|
+
[32m✓[39m should return combined class selector when single classes are not unique[32m 1[2mms[22m[39m
|
|
17
|
+
[32m✓[39m should prefer single class over combined classes when unique[32m 0[2mms[22m[39m
|
|
18
|
+
[32m✓[39m should return path with nth-of-type when classes are not unique[32m 2[2mms[22m[39m
|
|
19
|
+
[32m✓[39m should return shortest unique path[32m 1[2mms[22m[39m
|
|
20
|
+
[32m✓[39m should handle nested elements with same tag[32m 1[2mms[22m[39m
|
|
21
|
+
[32m✓[39m should stop at parent with ID when needed[32m 1[2mms[22m[39m
|
|
22
|
+
[32m✓[39m should return unique selector for deeply nested elements[32m 1[2mms[22m[39m
|
|
23
|
+
[32m✓[39m should handle elements with multiple non-unique classes[32m 1[2mms[22m[39m
|
|
24
|
+
[32m✓[39m should handle body element[32m 0[2mms[22m[39m
|
|
25
|
+
[32m✓[39m should return unique selector even for complex DOM[32m 1[2mms[22m[39m
|
|
26
|
+
[32m✓[39m should handle elements with empty class attribute[32m 0[2mms[22m[39m
|
|
27
|
+
[32m✓[39m should verify returned selector actually queries the correct element[32m 2[2mms[22m[39m
|
|
28
|
+
[32m✓[39m should return combined class selector when unique[32m 1[2mms[22m[39m
|
|
29
|
+
[32m✓[39m should handle elements without parent[32m 0[2mms[22m[39m
|
|
30
|
+
[32m✓[39m should handle case where path never becomes unique until root[32m 1[2mms[22m[39m
|
|
31
|
+
[32m✓[39m should return null when unable to generate unique selector[32m 0[2mms[22m[39m
|
|
32
|
+
|
|
33
|
+
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
34
|
+
[2m Tests [22m [1m[32m18 passed[39m[22m[90m (18)[39m
|
|
35
|
+
[2m Start at [22m 22:55:01
|
|
36
|
+
[2m Duration [22m 760ms[2m (environment 87%, worker 4%, tests 4%, transform 4%, import 1%)[22m
|
|
37
|
+
|
|
38
|
+
[?2026l[34m % [39m[2mCoverage report from [22m[33mv8[39m
|
|
39
|
+
---------------------|---------|----------|---------|---------|-------------------
|
|
40
|
+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
|
|
41
|
+
---------------------|---------|----------|---------|---------|-------------------
|
|
42
|
+
[32;1mAll files [0m | [32;1m 100[0m | [32;1m 100[0m | [32;1m 100[0m | [32;1m 100[0m | [33;1m [0m
|
|
43
|
+
index.ts | 0 | 0 | 0 | 0 | [31;1m [0m
|
|
44
|
+
[32;1m uniqueSelectorOf.ts[0m | [32;1m 100[0m | [32;1m 100[0m | [32;1m 100[0m | [32;1m 100[0m | [33;1m [0m
|
|
45
|
+
---------------------|---------|----------|---------|---------|-------------------
|
|
46
|
+
[?2026h[?2026l[?25h
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
117
117
|
Code coverage generated by
|
|
118
118
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
119
|
-
at 2026-10-
|
|
119
|
+
at 2026-10-09T09:53:07.218Z
|
|
120
120
|
</div>
|
|
121
121
|
<script src="prettify.js"></script>
|
|
122
122
|
<script>
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
74
74
|
Code coverage generated by
|
|
75
75
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
76
|
-
at 2026-10-
|
|
76
|
+
at 2026-10-09T09:53:07.218Z
|
|
77
77
|
</div>
|
|
78
78
|
<script src="prettify.js"></script>
|
|
79
79
|
<script>
|
|
@@ -228,13 +228,13 @@
|
|
|
228
228
|
* @returns {string | null} - A unique query selector string that can be used with document.querySelector.
|
|
229
229
|
* @example
|
|
230
230
|
* ```
|
|
231
|
-
* import {
|
|
231
|
+
* import { uniqueSelectorOf } from "@library/dom";
|
|
232
232
|
*
|
|
233
233
|
* const el = document.getElementById('myId');
|
|
234
|
-
*
|
|
234
|
+
* uniqueSelectorOf(el); // "#myId"
|
|
235
235
|
*
|
|
236
236
|
* const el2 = document.querySelector('.unique-class');
|
|
237
|
-
*
|
|
237
|
+
* uniqueSelectorOf(el2); // ".unique-class"
|
|
238
238
|
* ```
|
|
239
239
|
*/
|
|
240
240
|
export function uniqueSelectorOf(element: HTMLElement): string | null {
|
|
@@ -307,7 +307,7 @@ export function uniqueSelectorOf(element: HTMLElement): string | null {
|
|
|
307
307
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
308
308
|
Code coverage generated by
|
|
309
309
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
310
|
-
at 2026-10-
|
|
310
|
+
at 2026-10-09T09:53:07.218Z
|
|
311
311
|
</div>
|
|
312
312
|
<script src="prettify.js"></script>
|
|
313
313
|
<script>
|
package/llms.txt
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<!-- Generated by `yarn docs`. Do not edit by hand. -->
|
|
2
|
+
# @library/dom
|
|
3
|
+
|
|
4
|
+
> A collection of DOM utilities for TypeScript.
|
|
5
|
+
|
|
6
|
+
Install:
|
|
7
|
+
|
|
8
|
+
```console
|
|
9
|
+
npm install @library/dom
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
All exports are named ESM/CJS exports, importable as:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { uniqueSelectorOf } from "@library/dom";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## API
|
|
19
|
+
|
|
20
|
+
### uniqueSelectorOf
|
|
21
|
+
|
|
22
|
+
Generate the shortest unique querySelector string that identifies the given element.
|
|
23
|
+
Priority: id > unique class > path with nth-of-type
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
function uniqueSelectorOf(element: HTMLElement): string | null
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Parameters:
|
|
30
|
+
|
|
31
|
+
- `element`: The HTML element to generate a query selector for.
|
|
32
|
+
|
|
33
|
+
Returns: A unique query selector string that can be used with document.querySelector.
|
|
34
|
+
|
|
35
|
+
Example:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { uniqueSelectorOf } from "@library/dom";
|
|
39
|
+
|
|
40
|
+
const el = document.getElementById('myId');
|
|
41
|
+
uniqueSelectorOf(el); // "#myId"
|
|
42
|
+
|
|
43
|
+
const el2 = document.querySelector('.unique-class');
|
|
44
|
+
uniqueSelectorOf(el2); // ".unique-class"
|
|
45
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@library/dom",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "A collection of DOM utilities for TypeScript.",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "./dist/cjs/index.cjs",
|
|
6
7
|
"types": "./dist/cjs/index.d.cts",
|
|
@@ -17,6 +18,21 @@
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"dom",
|
|
23
|
+
"html",
|
|
24
|
+
"typescript",
|
|
25
|
+
"utility"
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://github.com/yeonjuan/library/tree/main/packages/dom#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/yeonjuan/library/issues"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/yeonjuan/library.git",
|
|
34
|
+
"directory": "packages/dom"
|
|
35
|
+
},
|
|
20
36
|
"license": "MIT",
|
|
21
37
|
"scripts": {
|
|
22
38
|
"build": "rimraf dist && tsup --tsconfig tsconfig.build.json",
|
|
@@ -25,5 +41,5 @@
|
|
|
25
41
|
"publishConfig": {
|
|
26
42
|
"access": "public"
|
|
27
43
|
},
|
|
28
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "fea3f714ec98af5ce58621c53734e44a62f881df"
|
|
29
45
|
}
|
package/src/uniqueSelectorOf.ts
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
* @returns {string | null} - A unique query selector string that can be used with document.querySelector.
|
|
6
6
|
* @example
|
|
7
7
|
* ```
|
|
8
|
-
* import {
|
|
8
|
+
* import { uniqueSelectorOf } from "@library/dom";
|
|
9
9
|
*
|
|
10
10
|
* const el = document.getElementById('myId');
|
|
11
|
-
*
|
|
11
|
+
* uniqueSelectorOf(el); // "#myId"
|
|
12
12
|
*
|
|
13
13
|
* const el2 = document.querySelector('.unique-class');
|
|
14
|
-
*
|
|
14
|
+
* uniqueSelectorOf(el2); // ".unique-class"
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export function uniqueSelectorOf(element: HTMLElement): string | null {
|