id-dom 0.0.1 → 0.0.2
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/Readme.md +11 -11
- package/package.json +1 -1
package/Readme.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
# dom
|
|
1
|
+
# id-dom
|
|
2
2
|
|
|
3
3
|
**Deterministic DOM element getters by ID (typed, tiny, modern).**
|
|
4
4
|
|
|
5
|
-
`dom
|
|
5
|
+
`id-dom` is a small utility for grabbing DOM references safely **by `id`**, with predictable behavior:
|
|
6
6
|
|
|
7
7
|
* ✅ **Typed getters** (`button('saveBtn')`, `input('name')`, etc.)
|
|
8
8
|
* ✅ **Strict or optional** mode (`throw` vs `null`)
|
|
@@ -18,7 +18,7 @@ This is deliberately **not** a selector framework — it’s a tiny “ID-first
|
|
|
18
18
|
## Install
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
|
-
npm install dom
|
|
21
|
+
npm install id-dom
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
---
|
|
@@ -26,7 +26,7 @@ npm install dom-id
|
|
|
26
26
|
## Quick Start
|
|
27
27
|
|
|
28
28
|
```js
|
|
29
|
-
import dom from 'dom
|
|
29
|
+
import dom from 'id-dom'
|
|
30
30
|
|
|
31
31
|
const saveBtn = dom.button('saveBtn') // throws if missing or wrong type
|
|
32
32
|
saveBtn.addEventListener('click', save)
|
|
@@ -68,7 +68,7 @@ The default export is a scoped instance using `document` (when available) with *
|
|
|
68
68
|
* wrong type/tag → **throws**
|
|
69
69
|
|
|
70
70
|
```js
|
|
71
|
-
import dom from 'dom
|
|
71
|
+
import dom from 'id-dom'
|
|
72
72
|
|
|
73
73
|
const name = dom.input('nameInput')
|
|
74
74
|
const submit = dom.button('submitBtn')
|
|
@@ -84,7 +84,7 @@ Create a scoped instance that searches within a root:
|
|
|
84
84
|
* `ShadowRoot` / `Element` (uses `querySelector(#id)` fallback)
|
|
85
85
|
|
|
86
86
|
```js
|
|
87
|
-
import { createDom } from 'dom
|
|
87
|
+
import { createDom } from 'id-dom'
|
|
88
88
|
|
|
89
89
|
const d = createDom(document, { mode: 'null', warn: true })
|
|
90
90
|
|
|
@@ -110,7 +110,7 @@ type DomMode = 'throw' | 'null'
|
|
|
110
110
|
Generic typed lookup:
|
|
111
111
|
|
|
112
112
|
```js
|
|
113
|
-
import { byId } from 'dom
|
|
113
|
+
import { byId } from 'id-dom'
|
|
114
114
|
|
|
115
115
|
const btn = byId('saveBtn', HTMLButtonElement)
|
|
116
116
|
```
|
|
@@ -129,7 +129,7 @@ const maybeBtn2 = byId.opt('saveBtn', HTMLButtonElement)
|
|
|
129
129
|
Tag-based validation for semantic elements:
|
|
130
130
|
|
|
131
131
|
```js
|
|
132
|
-
import { tag } from 'dom
|
|
132
|
+
import { tag } from 'id-dom'
|
|
133
133
|
|
|
134
134
|
const main = tag('appMain', 'main')
|
|
135
135
|
```
|
|
@@ -184,7 +184,7 @@ dom.canvas.opt('game')
|
|
|
184
184
|
### Throwing (default)
|
|
185
185
|
|
|
186
186
|
```js
|
|
187
|
-
import dom from 'dom
|
|
187
|
+
import dom from 'id-dom'
|
|
188
188
|
|
|
189
189
|
dom.button('missing') // throws
|
|
190
190
|
```
|
|
@@ -192,7 +192,7 @@ dom.button('missing') // throws
|
|
|
192
192
|
### Null-returning mode
|
|
193
193
|
|
|
194
194
|
```js
|
|
195
|
-
import { createDom } from 'dom
|
|
195
|
+
import { createDom } from 'id-dom'
|
|
196
196
|
|
|
197
197
|
const d = createDom(document, { mode: 'null' })
|
|
198
198
|
|
|
@@ -221,7 +221,7 @@ createDom(document, { mode: 'null', warn: true })
|
|
|
221
221
|
## Shadow DOM / Scoped Roots
|
|
222
222
|
|
|
223
223
|
```js
|
|
224
|
-
import { createDom } from 'dom
|
|
224
|
+
import { createDom } from 'id-dom'
|
|
225
225
|
|
|
226
226
|
const host = document.querySelector('#widget')
|
|
227
227
|
const shadow = host.attachShadow({ mode: 'open' })
|