dphelper 4.6.0 → 4.6.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/COPYRIGHT.md +6 -6
- package/FUNDING.yml +12 -12
- package/LICENSE.md +21 -21
- package/README.md +637 -397
- package/SECURITY.md +26 -26
- package/SUMMARY.md +83 -83
- package/index.cjs +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/llms.txt +515 -73
- package/modules/ai.cjs +1 -1
- package/modules/ai.d.ts +11 -11
- package/modules/ai.js +1 -1
- package/modules/anchor.cjs +1 -1
- package/modules/anchor.d.ts +6 -6
- package/modules/anchor.js +1 -1
- package/modules/array.cjs +1 -1
- package/modules/array.d.ts +21 -21
- package/modules/array.js +1 -1
- package/modules/audio.cjs +1 -1
- package/modules/audio.d.ts +10 -10
- package/modules/audio.js +1 -1
- package/modules/avoid.cjs +1 -1
- package/modules/avoid.d.ts +2 -2
- package/modules/avoid.js +1 -1
- package/modules/biometric.cjs +1 -1
- package/modules/biometric.d.ts +14 -14
- package/modules/biometric.js +1 -1
- package/modules/browser.cjs +1 -1
- package/modules/browser.d.ts +10 -10
- package/modules/browser.js +1 -1
- package/modules/check.cjs +1 -1
- package/modules/check.d.ts +4 -4
- package/modules/check.js +1 -1
- package/modules/color.cjs +1 -1
- package/modules/color.d.ts +6 -6
- package/modules/color.js +1 -1
- package/modules/compress.cjs +1 -1
- package/modules/compress.d.ts +13 -13
- package/modules/compress.js +1 -1
- package/modules/cookie.cjs +1 -1
- package/modules/cookie.d.ts +12 -12
- package/modules/cookie.js +1 -1
- package/modules/coords.cjs +1 -1
- package/modules/coords.d.ts +8 -8
- package/modules/coords.js +1 -1
- package/modules/credits.cjs +1 -1
- package/modules/credits.d.ts +11 -11
- package/modules/credits.js +1 -1
- package/modules/date.cjs +1 -1
- package/modules/date.d.ts +25 -25
- package/modules/date.js +1 -1
- package/modules/disable.cjs +1 -1
- package/modules/disable.d.ts +8 -8
- package/modules/disable.js +1 -1
- package/modules/dispatch.cjs +1 -1
- package/modules/dispatch.d.ts +4 -4
- package/modules/dispatch.js +1 -1
- package/modules/elements.cjs +1 -1
- package/modules/elements.d.ts +3 -3
- package/modules/elements.js +1 -1
- package/modules/events.cjs +1 -1
- package/modules/events.d.ts +6 -6
- package/modules/events.js +1 -1
- package/modules/fetch.cjs +1 -1
- package/modules/fetch.d.ts +15 -15
- package/modules/fetch.js +1 -1
- package/modules/form.cjs +1 -1
- package/modules/form.d.ts +13 -13
- package/modules/form.js +1 -1
- package/modules/format.cjs +1 -1
- package/modules/format.d.ts +3 -3
- package/modules/format.js +1 -1
- package/modules/i18n.cjs +1 -1
- package/modules/i18n.d.ts +11 -11
- package/modules/i18n.js +1 -1
- package/modules/image.cjs +1 -1
- package/modules/image.d.ts +13 -13
- package/modules/image.js +1 -1
- package/modules/json.cjs +1 -1
- package/modules/json.d.ts +8 -8
- package/modules/json.js +1 -1
- package/modules/load.cjs +1 -1
- package/modules/load.d.ts +8 -8
- package/modules/load.js +1 -1
- package/modules/logging.cjs +1 -1
- package/modules/logging.d.ts +8 -8
- package/modules/logging.js +1 -1
- package/modules/math.cjs +1 -1
- package/modules/math.d.ts +13 -13
- package/modules/math.js +1 -1
- package/modules/memory.cjs +1 -1
- package/modules/memory.d.ts +3 -3
- package/modules/memory.js +1 -1
- package/modules/navigation.cjs +1 -1
- package/modules/navigation.d.ts +4 -4
- package/modules/navigation.js +1 -1
- package/modules/net.cjs +1 -1
- package/modules/net.d.ts +10 -10
- package/modules/net.js +1 -1
- package/modules/objects.cjs +1 -1
- package/modules/objects.d.ts +15 -15
- package/modules/objects.js +1 -1
- package/modules/path.cjs +1 -1
- package/modules/path.d.ts +4 -4
- package/modules/path.js +1 -1
- package/modules/promise.cjs +1 -1
- package/modules/promise.d.ts +3 -3
- package/modules/promise.js +1 -1
- package/modules/sanitize.cjs +1 -1
- package/modules/sanitize.d.ts +2 -2
- package/modules/sanitize.js +1 -1
- package/modules/screen.cjs +1 -1
- package/modules/screen.d.ts +11 -11
- package/modules/screen.js +1 -1
- package/modules/scrollbar.cjs +1 -1
- package/modules/scrollbar.d.ts +9 -9
- package/modules/scrollbar.js +1 -1
- package/modules/security.cjs +1 -1
- package/modules/security.d.ts +15 -15
- package/modules/security.js +1 -1
- package/modules/shortcut.cjs +1 -1
- package/modules/shortcut.d.ts +2 -2
- package/modules/shortcut.js +1 -1
- package/modules/socket.cjs +1 -1
- package/modules/socket.d.ts +13 -13
- package/modules/socket.js +1 -1
- package/modules/sse.cjs +1 -1
- package/modules/sse.d.ts +8 -8
- package/modules/sse.js +1 -1
- package/modules/svg.cjs +1 -1
- package/modules/svg.d.ts +12 -12
- package/modules/svg.js +1 -1
- package/modules/sync.cjs +1 -1
- package/modules/sync.d.ts +13 -13
- package/modules/sync.js +1 -1
- package/modules/system.cjs +1 -1
- package/modules/system.d.ts +2 -2
- package/modules/system.js +1 -1
- package/modules/text.cjs +1 -1
- package/modules/text.d.ts +13 -13
- package/modules/text.js +1 -1
- package/modules/timer.cjs +1 -1
- package/modules/timer.d.ts +3 -3
- package/modules/timer.js +1 -1
- package/modules/tools.cjs +1 -1
- package/modules/tools.d.ts +5 -5
- package/modules/tools.js +1 -1
- package/modules/translators.cjs +1 -1
- package/modules/translators.d.ts +2 -2
- package/modules/translators.js +1 -1
- package/modules/triggers.cjs +1 -1
- package/modules/triggers.d.ts +43 -43
- package/modules/triggers.js +1 -1
- package/modules/types.cjs +1 -1
- package/modules/types.d.ts +5 -5
- package/modules/types.js +1 -1
- package/modules/ui.cjs +1 -1
- package/modules/ui.d.ts +3 -3
- package/modules/ui.js +1 -1
- package/modules/window.cjs +1 -1
- package/modules/window.d.ts +9 -9
- package/modules/window.js +1 -1
- package/modules/worker.cjs +1 -1
- package/modules/worker.d.ts +16 -16
- package/modules/worker.js +1 -1
- package/package.json +2 -2
- package/sbom.json +10 -15
- package/types/dphelper.d.ts +546 -546
- package/types/global.d.ts +8 -8
package/llms.txt
CHANGED
|
@@ -1,73 +1,515 @@
|
|
|
1
|
-
# dphelper
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
1
|
+
# dphelper
|
|
2
|
+
|
|
3
|
+
> **Stateless, zero-dependency capability toolkit for Web, Node.js, Bun, Deno and AI systems.**
|
|
4
|
+
|
|
5
|
+
`dphelper` provides a consistent namespace of modular capabilities for modern JavaScript and TypeScript applications.
|
|
6
|
+
|
|
7
|
+
**Core principles:**
|
|
8
|
+
|
|
9
|
+
* Stateless
|
|
10
|
+
* Zero runtime dependencies
|
|
11
|
+
* Modular
|
|
12
|
+
* Isomorphic where supported
|
|
13
|
+
* Consistent namespace
|
|
14
|
+
* TypeScript-friendly
|
|
15
|
+
* AI-ready
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## IMPORTANT: Architecture
|
|
20
|
+
|
|
21
|
+
**Application state management has been removed from `dphelper`.**
|
|
22
|
+
|
|
23
|
+
Do **not** use legacy state APIs such as:
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
dphelper.store
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Application state must be handled by a dedicated state manager:
|
|
30
|
+
|
|
31
|
+
* **Memorio** — lightweight application-wide/global state.
|
|
32
|
+
* **Argis RGS** — enterprise and complex reactive state architectures.
|
|
33
|
+
|
|
34
|
+
`dphelper` provides capabilities and operations. It does not own application state.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Core Mental Model
|
|
39
|
+
|
|
40
|
+
Think of `dphelper` as a **capability layer**, not as an application framework.
|
|
41
|
+
|
|
42
|
+
```text
|
|
43
|
+
Application
|
|
44
|
+
│
|
|
45
|
+
├── State
|
|
46
|
+
│ ├── Memorio
|
|
47
|
+
│ └── Argis RGS
|
|
48
|
+
│
|
|
49
|
+
└── Capabilities
|
|
50
|
+
│
|
|
51
|
+
└── dphelper
|
|
52
|
+
├── ai
|
|
53
|
+
├── worker
|
|
54
|
+
├── fetch
|
|
55
|
+
├── security
|
|
56
|
+
├── sanitize
|
|
57
|
+
├── i18n
|
|
58
|
+
├── sync
|
|
59
|
+
├── compress
|
|
60
|
+
└── ...
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Keep these responsibilities separate.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Initialization
|
|
68
|
+
|
|
69
|
+
`dphelper` uses a global namespace.
|
|
70
|
+
|
|
71
|
+
Initialize it **once**, at the application's root entry point:
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import "dphelper";
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
After initialization:
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
console.debug(dphelper.version);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Important
|
|
84
|
+
|
|
85
|
+
Do not repeatedly initialize `dphelper` from individual submodules.
|
|
86
|
+
|
|
87
|
+
Preferred architecture:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
Application Root
|
|
91
|
+
│
|
|
92
|
+
└── import "dphelper"
|
|
93
|
+
│
|
|
94
|
+
▼
|
|
95
|
+
global dphelper
|
|
96
|
+
│
|
|
97
|
+
┌──────┼──────┐
|
|
98
|
+
▼ ▼ ▼
|
|
99
|
+
ai worker security
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## Modular Imports
|
|
105
|
+
|
|
106
|
+
Individual capabilities can also be imported explicitly:
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { sanitize } from "dphelper/sanitize";
|
|
110
|
+
import { format } from "dphelper/format";
|
|
111
|
+
import { fetch } from "dphelper/fetch";
|
|
112
|
+
import { security } from "dphelper/security";
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Use modular imports when explicit imports and tree-shaking are preferred.
|
|
116
|
+
|
|
117
|
+
The corresponding global namespace remains available after initialization.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## Capability Namespace
|
|
122
|
+
|
|
123
|
+
Capabilities follow the general pattern:
|
|
124
|
+
|
|
125
|
+
```text
|
|
126
|
+
dphelper.<domain>.<operation>
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Examples:
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
dphelper.ai.toon(data);
|
|
133
|
+
dphelper.ai.tokenCount(data);
|
|
134
|
+
|
|
135
|
+
dphelper.security.ulid();
|
|
136
|
+
|
|
137
|
+
dphelper.i18n.t("hello");
|
|
138
|
+
|
|
139
|
+
dphelper.worker.create("worker.js");
|
|
140
|
+
|
|
141
|
+
dphelper.sync.pulse("my-app", callback);
|
|
142
|
+
|
|
143
|
+
dphelper.format.currency(1234.56, "en-US", "USD");
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
When generating code, prefer the existing `dphelper` namespace rather than introducing an additional utility dependency for functionality already provided by the library.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
# AI Capabilities
|
|
151
|
+
|
|
152
|
+
`dphelper.ai` provides capabilities intended for LLM, RAG and AI-assisted application workflows.
|
|
153
|
+
|
|
154
|
+
## TOON
|
|
155
|
+
|
|
156
|
+
Use:
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
const toonData = dphelper.ai.toon(data);
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
TOON provides a compact structured representation intended for AI/LLM-oriented data exchange.
|
|
163
|
+
|
|
164
|
+
## Token Counting
|
|
165
|
+
|
|
166
|
+
Use:
|
|
167
|
+
|
|
168
|
+
```javascript
|
|
169
|
+
const tokens = dphelper.ai.tokenCount(data);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Use this when estimating the token representation of structured data for AI workflows.
|
|
173
|
+
|
|
174
|
+
## RAG Chunking
|
|
175
|
+
|
|
176
|
+
Use:
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
const chunks = dphelper.ai.chunker(text, {
|
|
180
|
+
size: 1000,
|
|
181
|
+
overlap: 200
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Semantic Similarity
|
|
186
|
+
|
|
187
|
+
Use:
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
const score = dphelper.ai.similarity(
|
|
191
|
+
embeddingA,
|
|
192
|
+
embeddingB
|
|
193
|
+
);
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Reasoning Extraction
|
|
197
|
+
|
|
198
|
+
Use:
|
|
199
|
+
|
|
200
|
+
```javascript
|
|
201
|
+
const {
|
|
202
|
+
reasoning,
|
|
203
|
+
content
|
|
204
|
+
} = dphelper.ai.extractReasoning(rawAiReply);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
This capability can process responses containing separate reasoning and content representations.
|
|
208
|
+
|
|
209
|
+
## Runtime Snapshot
|
|
210
|
+
|
|
211
|
+
Use:
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
const snapshot = dphelper.ai.snapshot();
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The snapshot capability creates a compact representation of relevant application/runtime context for AI-assisted inspection, debugging and recovery.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
# Worker Capabilities
|
|
222
|
+
|
|
223
|
+
`dphelper.worker` provides browser Worker primitives.
|
|
224
|
+
|
|
225
|
+
## Worker
|
|
226
|
+
|
|
227
|
+
```javascript
|
|
228
|
+
const worker = dphelper.worker.create("worker.js", {
|
|
229
|
+
onmessage: (event) => {
|
|
230
|
+
console.log(event.data);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Inline Worker
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
const worker = dphelper.worker.createInline(`
|
|
239
|
+
self.onmessage = e => {
|
|
240
|
+
postMessage(e.data * 2);
|
|
241
|
+
};
|
|
242
|
+
`);
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## Worker Pool
|
|
246
|
+
|
|
247
|
+
```javascript
|
|
248
|
+
const pool = dphelper.worker.pool("worker.js", 4);
|
|
249
|
+
|
|
250
|
+
const results =
|
|
251
|
+
await dphelper.worker.poolExec(
|
|
252
|
+
pool,
|
|
253
|
+
[1, 2, 3, 4]
|
|
254
|
+
);
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## SharedWorker
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
const shared =
|
|
261
|
+
dphelper.worker.shared("worker.js", {
|
|
262
|
+
name: "my-shared"
|
|
263
|
+
});
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Worker Security Rule
|
|
267
|
+
|
|
268
|
+
Worker code and worker script URLs must be treated as **trusted input**.
|
|
269
|
+
|
|
270
|
+
Never pass arbitrary user-controlled code directly to:
|
|
271
|
+
|
|
272
|
+
```javascript
|
|
273
|
+
dphelper.worker.createInline(userInput);
|
|
274
|
+
dphelper.worker.create(userInput);
|
|
275
|
+
dphelper.worker.pool(userInput);
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Do not load worker scripts from URLs controlled by untrusted users.
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
# Cross-Tab Synchronization
|
|
283
|
+
|
|
284
|
+
Use `dphelper.sync.pulse` for event-based communication between browser contexts:
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
const bus = dphelper.sync.pulse(
|
|
288
|
+
"my-app",
|
|
289
|
+
(message) => {
|
|
290
|
+
console.log(message);
|
|
291
|
+
}
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
bus.emit({
|
|
295
|
+
action: "theme-change",
|
|
296
|
+
value: "dark"
|
|
297
|
+
});
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
`sync.pulse` provides communication.
|
|
301
|
+
|
|
302
|
+
It is **not** the application state store.
|
|
303
|
+
|
|
304
|
+
For persistent/application state:
|
|
305
|
+
|
|
306
|
+
```text
|
|
307
|
+
Cross-tab events → dphelper.sync.pulse
|
|
308
|
+
Application state → Memorio / Argis RGS
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
# Internationalization
|
|
314
|
+
|
|
315
|
+
Use:
|
|
316
|
+
|
|
317
|
+
```javascript
|
|
318
|
+
dphelper.i18n.setLocale("it");
|
|
319
|
+
|
|
320
|
+
dphelper.i18n.addTranslations("it", {
|
|
321
|
+
hello: "Ciao {name}!"
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
dphelper.i18n.t("hello", {
|
|
325
|
+
name: "World"
|
|
326
|
+
});
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
Other internationalization capabilities include pluralization, number formatting and relative time.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
# Security Guidance
|
|
334
|
+
|
|
335
|
+
`dphelper` provides security-oriented capabilities but does not automatically make an application secure.
|
|
336
|
+
|
|
337
|
+
Always consider the application's threat model and validate external input at the application boundary.
|
|
338
|
+
|
|
339
|
+
## Cryptography
|
|
340
|
+
|
|
341
|
+
Available cryptographic primitives include:
|
|
342
|
+
|
|
343
|
+
* AES-256-GCM
|
|
344
|
+
* SHA-256
|
|
345
|
+
* PBKDF2
|
|
346
|
+
* PBKDF2 configurations using 310,000 iterations where applicable
|
|
347
|
+
|
|
348
|
+
Do not describe `dphelper` as universally "NIST compliant" or "NSA compliant" unless a specific component, configuration and compliance scope has been formally established.
|
|
349
|
+
|
|
350
|
+
Prefer precise descriptions of the cryptographic primitive being used.
|
|
351
|
+
|
|
352
|
+
## Network Input
|
|
353
|
+
|
|
354
|
+
Networking capabilities include:
|
|
355
|
+
|
|
356
|
+
```text
|
|
357
|
+
dphelper.fetch
|
|
358
|
+
dphelper.sse
|
|
359
|
+
dphelper.socket
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Treat externally supplied URLs as untrusted.
|
|
363
|
+
|
|
364
|
+
Example:
|
|
365
|
+
|
|
366
|
+
```javascript
|
|
367
|
+
const safeUrl =
|
|
368
|
+
dphelper.sanitize.url(userInput);
|
|
369
|
+
|
|
370
|
+
await dphelper.fetch.get(safeUrl);
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Do not assume that passing data through a utility automatically makes the application's overall network operation safe.
|
|
374
|
+
|
|
375
|
+
---
|
|
376
|
+
|
|
377
|
+
# Environment Model
|
|
378
|
+
|
|
379
|
+
Capabilities may target different environments.
|
|
380
|
+
|
|
381
|
+
| Type | Meaning |
|
|
382
|
+
| ---------- | ---------------------------------------------------------- |
|
|
383
|
+
| Client | Browser APIs such as DOM, window or navigator |
|
|
384
|
+
| Server | Node.js, Bun or Deno APIs |
|
|
385
|
+
| Isomorphic | Designed to operate in both client and server environments |
|
|
386
|
+
|
|
387
|
+
Examples:
|
|
388
|
+
|
|
389
|
+
```text
|
|
390
|
+
dphelper.ai → Isomorphic
|
|
391
|
+
dphelper.fetch → Isomorphic
|
|
392
|
+
dphelper.sse → Client
|
|
393
|
+
dphelper.socket → Client
|
|
394
|
+
dphelper.sync → Client
|
|
395
|
+
dphelper.UI → Client
|
|
396
|
+
dphelper.worker → Client
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Always respect the execution environment of the capability being used.
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
# State Management Rules
|
|
404
|
+
|
|
405
|
+
### NEVER generate:
|
|
406
|
+
|
|
407
|
+
```javascript
|
|
408
|
+
dphelper.store
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### USE:
|
|
412
|
+
|
|
413
|
+
```text
|
|
414
|
+
Simple/global application state
|
|
415
|
+
↓
|
|
416
|
+
Memorio
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
or:
|
|
420
|
+
|
|
421
|
+
```text
|
|
422
|
+
Enterprise / complex reactive state
|
|
423
|
+
↓
|
|
424
|
+
Argis RGS
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Cross-tab communication:
|
|
428
|
+
|
|
429
|
+
```javascript
|
|
430
|
+
dphelper.sync.pulse(...)
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
Use `sync.pulse` for events and communication, not as a replacement for the application's state manager.
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
437
|
+
# AI Code Generation Rules
|
|
438
|
+
|
|
439
|
+
When generating code for a project using `dphelper`:
|
|
440
|
+
|
|
441
|
+
1. Prefer an existing `dphelper` capability over adding another dependency for the same operation.
|
|
442
|
+
2. Do not introduce `dphelper.store` or legacy state-management APIs.
|
|
443
|
+
3. Keep application state outside `dphelper`.
|
|
444
|
+
4. Initialize the global namespace once at the application root when using global mode.
|
|
445
|
+
5. Use modular imports when explicit capability imports are preferable.
|
|
446
|
+
6. Use `dphelper.sync.pulse` for cross-tab event communication.
|
|
447
|
+
7. Use Memorio or Argis RGS for application state.
|
|
448
|
+
8. Treat network URLs and worker sources as potentially untrusted input.
|
|
449
|
+
9. Respect client/server/isomorphic environment constraints.
|
|
450
|
+
10. Do not assume that a `dphelper` capability exists unless it is part of the published API.
|
|
451
|
+
|
|
452
|
+
---
|
|
453
|
+
|
|
454
|
+
# Architectural Summary
|
|
455
|
+
|
|
456
|
+
```text
|
|
457
|
+
APPLICATION
|
|
458
|
+
│
|
|
459
|
+
┌───────────┴───────────┐
|
|
460
|
+
│ │
|
|
461
|
+
STATE CAPABILITIES
|
|
462
|
+
│ │
|
|
463
|
+
┌────┴────┐ │
|
|
464
|
+
│ │ │
|
|
465
|
+
Memorio Argis RGS │
|
|
466
|
+
dphelper
|
|
467
|
+
│
|
|
468
|
+
┌────────────┬───────┼────────┐
|
|
469
|
+
│ │ │ │
|
|
470
|
+
AI Worker Web Security
|
|
471
|
+
│ │ │ │
|
|
472
|
+
TOON Pools Fetch Crypto
|
|
473
|
+
RAG Shared SSE Sanitize
|
|
474
|
+
Tokens Worker Socket
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
**dphelper is the stateless capability layer.**
|
|
478
|
+
|
|
479
|
+
**Memorio and Argis RGS are state-management layers.**
|
|
480
|
+
|
|
481
|
+
Do not merge these responsibilities.
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## Package
|
|
486
|
+
|
|
487
|
+
`dphelper` is distributed through npm:
|
|
488
|
+
|
|
489
|
+
```text
|
|
490
|
+
npm install dphelper
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
Official package:
|
|
494
|
+
|
|
495
|
+
https://www.npmjs.com/package/dphelper
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
## Related Packages
|
|
500
|
+
|
|
501
|
+
### Memorio
|
|
502
|
+
|
|
503
|
+
Application-wide state management for simpler applications.
|
|
504
|
+
|
|
505
|
+
```text
|
|
506
|
+
https://www.npmjs.com/package/memorio
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### Argis RGS
|
|
510
|
+
|
|
511
|
+
Enterprise-oriented reactive state architecture.
|
|
512
|
+
|
|
513
|
+
```text
|
|
514
|
+
https://www.npmjs.com/package/@biglogic/rgs
|
|
515
|
+
```
|
package/modules/ai.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
'use strict';var P={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var v={version:"4.6.
|
|
1
|
+
'use strict';var P={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var v={version:"4.6.2"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...P},configurable:true,writable:true},version:{value:v.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var f=dphelper;Object.defineProperty(f,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(f,"setDescription",{value:(e,t)=>{Object.defineProperties(f,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(f[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),f.setProps(f,e,{writable:false,configurable:false,enumerable:false}),f._list.scripts.push(e);}});var M={name:"ai",active:true,subCommand:[{name:"tokenCount",version:"0.0.3",example:"dphelper.ai.tokenCount({ users: [1,2,3] })",author:"Dario Passariello",creationDate:"20260220",lastMod:"20260221",type:"function",active:true,description:"Estimate token count for LLMs. If an object is passed, it uses TOON format for calculation.",env:"both",subCommand:[]},{name:"smartSanitize",version:"0.0.2",example:"dphelper.ai.smartSanitize('My email is test@example.com')",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Remove PII (emails, phones, etc) from text for AI privacy",subCommand:[]},{name:"toon",version:"0.0.1",example:"dphelper.ai.toon({ users: [{id: 1, name: 'Ada'}] })",author:"TOON + Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert JSON to TOON format (Token-Oriented Object Notation)",subCommand:[]},{name:"toonToJson",version:"0.0.1",example:"dphelper.ai.toonToJson('users[1]{id,name}:\\n 1,Ada')",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert TOON format back to JSON/Object",subCommand:[]},{name:"chunker",version:"0.0.1",example:"dphelper.ai.chunker(text, { size: 1000, overlap: 200 })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Split long text into chunks for RAG or AI processing.",subCommand:[]},{name:"similarity",version:"0.0.1",example:"dphelper.ai.similarity(vecA, vecB)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Calculate cosine similarity between two embedding vectors.",subCommand:[]},{name:"extractReasoning",version:"0.0.1",example:"dphelper.ai.extractReasoning(aiResponse)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Extract <think> tags or internal reasoning from AI responses.",subCommand:[]},{name:"prompt",version:"0.0.1",example:"dphelper.ai.prompt('Hello {{name}}', { name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Simple prompt template engine with variable injection.",subCommand:[]},{name:"schema",version:"0.0.1",example:"dphelper.ai.schema({ id: 1, name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Generate a TOON-style schema definition for AI instructions.",subCommand:[]},{name:"snapshot",version:"0.0.1",example:"dphelper.ai.snapshot()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Capture a 'mental snapshot' of the app state (logs/globals) in TOON format for AI debugging.",env:"both",subCommand:[]}]},x=e=>e===null||typeof e!="object",O=e=>e===null?"null":typeof e=="string"?e.includes(",")||e.includes(":")||e.includes('"')||e.includes(`
|
|
2
2
|
`)||e.trim()!==e?`"${e.replace(/"/g,'\\"')}"`:e||'""':String(e),b=(e,t=0)=>{let r=" ".repeat(t);if(x(e))return O(e);if(Array.isArray(e)){if(e.length===0)return "[0]:";let n=e[0];if(!x(n)&&!Array.isArray(n)){let s=Object.keys(n),o=`[${e.length}]{${s.join(",")}}:`;for(let i of e){let u=s.map(a=>O(i[a])).join(",");o+=`
|
|
3
3
|
${r} ${u}`;}return o}else return `[${e.length}]: `+e.map(O).join(",")}else return Object.entries(e).map(([n,s])=>{let o=n.includes(" ")||n.includes(":")?`"${n}"`:n;if(!x(s)){let i=b(s,t+1);return i.startsWith("[")?`${o}${i}`:`${o}:
|
|
4
4
|
${r}${i}`}return `${o}: ${O(s)}`}).join(`
|
package/modules/ai.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/// <reference path="../types/dphelper.d.ts" />
|
|
2
|
-
export interface AiTool {
|
|
3
|
-
tokenCount: (data: any) => number
|
|
4
|
-
smartSanitize: (text: string) => string
|
|
5
|
-
toon: (data: any) => string
|
|
6
|
-
toonToJson: (toon: string) => any
|
|
7
|
-
chunker: (text: string, options?: { size?: number, overlap?: number }) => string[]
|
|
8
|
-
similarity: (a: number[], b: number[]) => number
|
|
9
|
-
extractReasoning: (text: string) => { reasoning: string, content: string }
|
|
10
|
-
prompt: (template: string, vars: Record<string, any>) => string
|
|
11
|
-
schema: (data: any) => string
|
|
12
|
-
snapshot: () => string
|
|
2
|
+
export interface AiTool {
|
|
3
|
+
tokenCount: (data: any) => number
|
|
4
|
+
smartSanitize: (text: string) => string
|
|
5
|
+
toon: (data: any) => string
|
|
6
|
+
toonToJson: (toon: string) => any
|
|
7
|
+
chunker: (text: string, options?: { size?: number, overlap?: number }) => string[]
|
|
8
|
+
similarity: (a: number[], b: number[]) => number
|
|
9
|
+
extractReasoning: (text: string) => { reasoning: string, content: string }
|
|
10
|
+
prompt: (template: string, vars: Record<string, any>) => string
|
|
11
|
+
schema: (data: any) => string
|
|
12
|
+
snapshot: () => string
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export const ai: AiTool
|
package/modules/ai.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var v={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var $={version:"4.6.
|
|
1
|
+
var v={info:{title:"List",description:"Complete list of tools"},categories:["3party","system","financial","memory","numbers","time","path","file","forms","ui","other","development"]};var $={version:"4.6.2"};Object.defineProperty(globalThis,"dphelper",{value:new Proxy({},{}),writable:true,configurable:true,enumerable:false});Object.defineProperties(dphelper,{_list:{value:{scripts:[],sockets:[],...v},configurable:true,writable:true},version:{value:$.version,configurable:true,writable:true},isServer:{value:false,configurable:true,writable:true},isBrowser:{value:true,configurable:true,writable:true}});var f=dphelper;Object.defineProperty(f,"setProps",{value:(e,t,r)=>{Object.defineProperty(e,t.name,r||{writable:false,configurable:false,enumerable:false}),r?.lock&&Object.freeze(e[t.name]);},writable:false,configurable:false,enumerable:false});Object.defineProperty(f,"setDescription",{value:(e,t)=>{Object.defineProperties(f,{[e.name]:{value:t,writable:false,configurable:false,enumerable:false}}),Object.keys(t).map(r=>(Object.defineProperties(f[e.name],{[r]:{writable:false,configurable:false,enumerable:false}}),null)),f.setProps(f,e,{writable:false,configurable:false,enumerable:false}),f._list.scripts.push(e);}});var N={name:"ai",active:true,subCommand:[{name:"tokenCount",version:"0.0.3",example:"dphelper.ai.tokenCount({ users: [1,2,3] })",author:"Dario Passariello",creationDate:"20260220",lastMod:"20260221",type:"function",active:true,description:"Estimate token count for LLMs. If an object is passed, it uses TOON format for calculation.",env:"both",subCommand:[]},{name:"smartSanitize",version:"0.0.2",example:"dphelper.ai.smartSanitize('My email is test@example.com')",author:"Dario Passariello & Jo",creationDate:"20260220",lastMod:"20260220",type:"function",active:true,description:"Remove PII (emails, phones, etc) from text for AI privacy",subCommand:[]},{name:"toon",version:"0.0.1",example:"dphelper.ai.toon({ users: [{id: 1, name: 'Ada'}] })",author:"TOON + Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert JSON to TOON format (Token-Oriented Object Notation)",subCommand:[]},{name:"toonToJson",version:"0.0.1",example:"dphelper.ai.toonToJson('users[1]{id,name}:\\n 1,Ada')",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Convert TOON format back to JSON/Object",subCommand:[]},{name:"chunker",version:"0.0.1",example:"dphelper.ai.chunker(text, { size: 1000, overlap: 200 })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Split long text into chunks for RAG or AI processing.",subCommand:[]},{name:"similarity",version:"0.0.1",example:"dphelper.ai.similarity(vecA, vecB)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Calculate cosine similarity between two embedding vectors.",subCommand:[]},{name:"extractReasoning",version:"0.0.1",example:"dphelper.ai.extractReasoning(aiResponse)",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Extract <think> tags or internal reasoning from AI responses.",subCommand:[]},{name:"prompt",version:"0.0.1",example:"dphelper.ai.prompt('Hello {{name}}', { name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Simple prompt template engine with variable injection.",subCommand:[]},{name:"schema",version:"0.0.1",example:"dphelper.ai.schema({ id: 1, name: 'Ada' })",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Generate a TOON-style schema definition for AI instructions.",subCommand:[]},{name:"snapshot",version:"0.0.1",example:"dphelper.ai.snapshot()",author:"Dario Passariello",creationDate:"20260221",lastMod:"20260221",type:"function",active:true,description:"Capture a 'mental snapshot' of the app state (logs/globals) in TOON format for AI debugging.",env:"both",subCommand:[]}]},A=e=>e===null||typeof e!="object",O=e=>e===null?"null":typeof e=="string"?e.includes(",")||e.includes(":")||e.includes('"')||e.includes(`
|
|
2
2
|
`)||e.trim()!==e?`"${e.replace(/"/g,'\\"')}"`:e||'""':String(e),b=(e,t=0)=>{let r=" ".repeat(t);if(A(e))return O(e);if(Array.isArray(e)){if(e.length===0)return "[0]:";let n=e[0];if(!A(n)&&!Array.isArray(n)){let s=Object.keys(n),o=`[${e.length}]{${s.join(",")}}:`;for(let i of e){let u=s.map(a=>O(i[a])).join(",");o+=`
|
|
3
3
|
${r} ${u}`;}return o}else return `[${e.length}]: `+e.map(O).join(",")}else return Object.entries(e).map(([n,s])=>{let o=n.includes(" ")||n.includes(":")?`"${n}"`:n;if(!A(s)){let i=b(s,t+1);return i.startsWith("[")?`${o}${i}`:`${o}:
|
|
4
4
|
${r}${i}`}return `${o}: ${O(s)}`}).join(`
|