dphelper 3.7.1 → 3.7.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/docs/README.md +385 -0
- package/docs/SUMMARY.md +83 -0
- package/docs/_config.yml +1 -0
- package/docs/markdown/ai.md +345 -0
- package/docs/markdown/anchor.md +156 -0
- package/docs/markdown/array.md +208 -0
- package/docs/markdown/audio.md +113 -0
- package/docs/markdown/avoid.md +53 -0
- package/docs/markdown/biometric.md +338 -0
- package/docs/markdown/browser.md +203 -0
- package/docs/markdown/check.md +65 -0
- package/docs/markdown/color.md +159 -0
- package/docs/markdown/compress.md +310 -0
- package/docs/markdown/cookie.md +115 -0
- package/docs/markdown/coords.md +127 -0
- package/docs/markdown/credits.md +56 -0
- package/docs/markdown/date.md +260 -0
- package/docs/markdown/disable.md +109 -0
- package/docs/markdown/dispatch.md +108 -0
- package/docs/markdown/element.md +53 -0
- package/docs/markdown/event.md +85 -0
- package/docs/markdown/fetch.md +122 -0
- package/docs/markdown/form.md +302 -0
- package/docs/markdown/format.md +122 -0
- package/docs/markdown/i18n.md +292 -0
- package/docs/markdown/image.md +298 -0
- package/docs/markdown/json.md +269 -0
- package/docs/markdown/load.md +133 -0
- package/docs/markdown/logging.md +99 -0
- package/docs/markdown/math.md +172 -0
- package/docs/markdown/memory.md +85 -0
- package/docs/markdown/navigation.md +152 -0
- package/docs/markdown/net.md +60 -0
- package/docs/markdown/obj.md +242 -0
- package/docs/markdown/path.md +46 -0
- package/docs/markdown/promise.md +94 -0
- package/docs/markdown/sanitize.md +118 -0
- package/docs/markdown/screen.md +78 -0
- package/docs/markdown/scrollbar.md +82 -0
- package/docs/markdown/security.md +289 -0
- package/docs/markdown/shortcut.md +100 -0
- package/docs/markdown/socket.md +134 -0
- package/docs/markdown/sse.md +120 -0
- package/docs/markdown/svg.md +167 -0
- package/docs/markdown/sync.md +147 -0
- package/docs/markdown/system.md +78 -0
- package/docs/markdown/terminal.md +73 -0
- package/docs/markdown/text.md +245 -0
- package/docs/markdown/timer.md +98 -0
- package/docs/markdown/tools.md +111 -0
- package/docs/markdown/translators.md +65 -0
- package/docs/markdown/trigger.md +99 -0
- package/docs/markdown/triggers.md +133 -0
- package/docs/markdown/type.md +109 -0
- package/docs/markdown/types.md +102 -0
- package/docs/markdown/ui.md +45 -0
- package/docs/markdown/window.md +211 -0
- package/docs/markdown/worker.md +223 -0
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# socket
|
|
2
|
+
|
|
3
|
+
WebSocket utilities for real-time bidirectional communication.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `info` | Get socket library information | `dphelper.socket.info()` |
|
|
10
|
+
| `start` | Initialize and start a socket connection | `dphelper.socket.start(element, server, name)` |
|
|
11
|
+
| `connect` | Connect to a WebSocket server | `dphelper.socket.connect(server, name)` |
|
|
12
|
+
| `open` | Open a named socket connection | `dphelper.socket.open(id, server, name)` |
|
|
13
|
+
| `send` | Send data through socket | `dphelper.socket.send(message, type, name)` |
|
|
14
|
+
| `receive` | Set up message receiver | `dphelper.socket.receive(element, name)` |
|
|
15
|
+
| `keepAlive` | Maintain connection with ping/pong | `dphelper.socket.keepAlive(name)` |
|
|
16
|
+
| `ping` | Send ping to server | `dphelper.socket.ping(name)` |
|
|
17
|
+
| `check` | Check and cleanup closed connections | `dphelper.socket.check()` |
|
|
18
|
+
| `list` | List all active WebSocket connections | `dphelper.socket.list()` |
|
|
19
|
+
|
|
20
|
+
## Description
|
|
21
|
+
|
|
22
|
+
Complete WebSocket management toolkit:
|
|
23
|
+
- **Connection Management** - Connect, disconnect, keep-alive
|
|
24
|
+
- **Messaging** - Send and receive data
|
|
25
|
+
- **Monitoring** - Track active connections
|
|
26
|
+
- **Security** - Enforces WSS (TLS) for production
|
|
27
|
+
|
|
28
|
+
## Usage Examples
|
|
29
|
+
|
|
30
|
+
### Basic Connection
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
// Initialize a socket connection
|
|
34
|
+
dphelper.socket.connect('wss://example.com/socket', 'myConnection');
|
|
35
|
+
|
|
36
|
+
// Set up message receiver
|
|
37
|
+
dphelper.socket.receive('#messageContainer', 'myConnection');
|
|
38
|
+
|
|
39
|
+
// Send a message
|
|
40
|
+
dphelper.socket.send('Hello World', 'message', 'myConnection');
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Complete Real-time Chat
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
// Initialize chat connection
|
|
47
|
+
function initChat() {
|
|
48
|
+
const server = 'wss://chat.example.com/ws';
|
|
49
|
+
const name = 'chat';
|
|
50
|
+
|
|
51
|
+
// Connect to server
|
|
52
|
+
dphelper.socket.connect(server, name);
|
|
53
|
+
|
|
54
|
+
// Set up message handler
|
|
55
|
+
dphelper.socket.receive('#chatMessages', name);
|
|
56
|
+
|
|
57
|
+
// Keep connection alive
|
|
58
|
+
dphelper.socket.keepAlive(name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Send message
|
|
62
|
+
function sendMessage(text) {
|
|
63
|
+
dphelper.socket.send(text, 'chat', 'chat');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// HTML: <div id="chatMessages"></div>
|
|
67
|
+
// HTML: <input type="text" id="chatInput">
|
|
68
|
+
// HTML: <button onclick="sendMessage(document.getElementById('chatInput').value)">Send</button>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Multiple Socket Connections
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
// Create multiple named connections
|
|
75
|
+
dphelper.socket.connect('wss://api.example.com/notifications', 'notifications');
|
|
76
|
+
dphelper.socket.connect('wss://api.example.com/updates', 'updates');
|
|
77
|
+
dphelper.socket.connect('wss://api.example.com/chat', 'chat');
|
|
78
|
+
|
|
79
|
+
// Send to specific connection
|
|
80
|
+
dphelper.socket.send('New user', 'notification', 'notifications');
|
|
81
|
+
dphelper.socket.send('Update data', 'update', 'updates');
|
|
82
|
+
|
|
83
|
+
// List all active connections
|
|
84
|
+
const connections = dphelper.socket.list();
|
|
85
|
+
console.log(`Active connections: ${connections.length}`);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Keep-Alive Implementation
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
// Maintain connection with automatic ping/pong
|
|
92
|
+
dphelper.socket.keepAlive('mainConnection');
|
|
93
|
+
|
|
94
|
+
// Manual ping
|
|
95
|
+
dphelper.socket.ping('mainConnection');
|
|
96
|
+
|
|
97
|
+
// Check connection health
|
|
98
|
+
dphelper.socket.check();
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Form Submission via Socket
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
// Send form data through socket
|
|
105
|
+
document.querySelector('form').addEventListener('submit', (e) => {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
|
|
108
|
+
const formData = new FormData(e.target);
|
|
109
|
+
const data = Object.fromEntries(formData);
|
|
110
|
+
|
|
111
|
+
dphelper.socket.send(JSON.stringify(data), 'form', 'mainConnection');
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Security Features
|
|
116
|
+
|
|
117
|
+
- **TLS Enforcement** - Only allows secure WebSocket connections (wss://)
|
|
118
|
+
- **URL Validation** - Prevents arbitrary origin connections
|
|
119
|
+
- **Same-origin fallback** - Supports relative URLs
|
|
120
|
+
|
|
121
|
+
> [!IMPORTANT]
|
|
122
|
+
> **Input Validation Required:** Callers must validate and sanitize URLs before passing them to socket functions. Use `dphelper.sanitize.url()` for URL validation.
|
|
123
|
+
|
|
124
|
+
## Details
|
|
125
|
+
|
|
126
|
+
- **Author:** Dario Passariello
|
|
127
|
+
- **Version:** 0.0.2
|
|
128
|
+
- **Creation Date:** 20210101
|
|
129
|
+
- **Last Modified:** 20260329
|
|
130
|
+
- **Environment:** Client-side only (browser)
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# sse
|
|
2
|
+
|
|
3
|
+
Server-Sent Events (SSE) client for real-time streaming data.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `open` | Open SSE connection with custom options | `dphelper.sse.open('/api/stream', options)` |
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
Server-Sent Events client:
|
|
14
|
+
- **Streaming** - Receive real-time updates from server
|
|
15
|
+
- **Custom Headers** - POST requests, authentication
|
|
16
|
+
- **Event Types** - message, error, open handlers
|
|
17
|
+
- **Auto Reconnect** - Built-in connection handling
|
|
18
|
+
|
|
19
|
+
## Usage Examples
|
|
20
|
+
|
|
21
|
+
### Basic SSE Connection
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Open SSE connection
|
|
25
|
+
const sse = dphelper.sse.open('/api/stream');
|
|
26
|
+
|
|
27
|
+
// Listen for messages
|
|
28
|
+
sse.on('message', (data) => {
|
|
29
|
+
console.log('Received:', data);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Handle errors
|
|
33
|
+
sse.on('error', (err) => {
|
|
34
|
+
console.error('SSE Error:', err);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Connection opened
|
|
38
|
+
sse.on('open', (info) => {
|
|
39
|
+
console.log('Connected:', info.status);
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### POST Request with Headers
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
// SSE with authentication
|
|
47
|
+
const sse = dphelper.sse.open('/api/stream', {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: {
|
|
50
|
+
'Authorization': 'Bearer token',
|
|
51
|
+
'Content-Type': 'application/json'
|
|
52
|
+
},
|
|
53
|
+
body: JSON.stringify({ query: 'updates' })
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
sse.on('message', (data) => {
|
|
57
|
+
updateUI(data);
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Complete Real-time Updates
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
class RealtimeUpdater {
|
|
65
|
+
constructor(url, options = {}) {
|
|
66
|
+
this.url = url;
|
|
67
|
+
this.options = options;
|
|
68
|
+
this.connection = null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
connect() {
|
|
72
|
+
this.connection = dphelper.sse.open(this.url, this.options);
|
|
73
|
+
|
|
74
|
+
this.connection.on('message', (data) => {
|
|
75
|
+
this.handleMessage(data);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
this.connection.on('error', (err) => {
|
|
79
|
+
console.error('Connection error:', err);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
this.connection.on('open', (info) => {
|
|
83
|
+
console.log('Connected:', info.status);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
handleMessage(data) {
|
|
88
|
+
console.log('Update:', data);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
disconnect() {
|
|
92
|
+
if (this.connection) {
|
|
93
|
+
this.connection.close();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Usage
|
|
99
|
+
const updater = new RealtimeUpdater('/api/updates', {
|
|
100
|
+
headers: { 'X-API-Key': 'secret' }
|
|
101
|
+
});
|
|
102
|
+
updater.connect();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Security Notes
|
|
106
|
+
|
|
107
|
+
> [!IMPORTANT]
|
|
108
|
+
> **Input Validation Required:** SSE connections require URL validation by the caller. Use `dphelper.sanitize.url()` before opening connections.
|
|
109
|
+
|
|
110
|
+
## Details
|
|
111
|
+
|
|
112
|
+
- **Author:** Dario Passariello
|
|
113
|
+
- **Version:** 0.0.2
|
|
114
|
+
- **Creation Date:** 20260221
|
|
115
|
+
- **Last Modified:** 20260329
|
|
116
|
+
- **Environment:** Client-side only (browser)
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# svg
|
|
2
|
+
|
|
3
|
+
SVG manipulation utilities for creating connections, diagrams, and converting elements to SVG format.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `init` | Initialize SVG connection between elements | `dphelper.svg.init(container, [el1, 'right'], [el2, 'left'])` |
|
|
10
|
+
| `check` | Check SVG browser support | `dphelper.svg.check()` |
|
|
11
|
+
| `update` | Update SVG connection positions | `dphelper.svg.update(rect1, rect2, path)` |
|
|
12
|
+
| `getCurve` | Calculate curve path between points | `dphelper.svg.getCurve([x1,y1], [x2,y2], distance)` |
|
|
13
|
+
| `getIntersection` | Calculate element intersection point | `dphelper.svg.getIntersection(dx, dy, cx, cy, w, h)` |
|
|
14
|
+
| `setConnector` | Set connector point on element | `dphelper.svg.setConnector(element, 'right')` |
|
|
15
|
+
| `removeConnection` | Remove SVG connection from container | `dphelper.svg.removeConnection(container)` |
|
|
16
|
+
| `makeScrollable` | Update connection on scroll | `dphelper.svg.makeScrollable(svg, scroll, el1, el2, rect1, rect2)` |
|
|
17
|
+
| `makeDraggable` | Make SVG element draggable | `dphelper.svg.makeDraggable(event)` |
|
|
18
|
+
| `toggle` | Toggle SVG connection on/off | `dphelper.svg.toggle(event, container, el1, el2)` |
|
|
19
|
+
| `convert` | Convert HTML element to SVG | `dphelper.svg.convert({ children: '#myDiv' })` |
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
Complete SVG toolkit:
|
|
24
|
+
- **Connection Drawing** - Create visual links between elements
|
|
25
|
+
- **Geometry Calculations** - Curves, intersections, positions
|
|
26
|
+
- **Interactivity** - Draggable elements, scroll handling
|
|
27
|
+
- **Conversion** - Transform HTML to SVG
|
|
28
|
+
|
|
29
|
+
## Usage Examples
|
|
30
|
+
|
|
31
|
+
### Creating Connections
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
// HTML structure
|
|
35
|
+
// <div id="container">
|
|
36
|
+
// <div id="element1">Source</div>
|
|
37
|
+
// <div id="element2">Target</div>
|
|
38
|
+
// </div>
|
|
39
|
+
|
|
40
|
+
const container = document.getElementById('container');
|
|
41
|
+
const el1 = document.getElementById('element1');
|
|
42
|
+
const el2 = document.getElementById('element2');
|
|
43
|
+
|
|
44
|
+
// Initialize connection from right of el1 to left of el2
|
|
45
|
+
dphelper.svg.init(container, [el1, 'right'], [el2, 'left']);
|
|
46
|
+
|
|
47
|
+
// Connection uses bezier curves
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Connection Sides
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
// Available connection points
|
|
54
|
+
dphelper.svg.init(container, [el1, 'top'], [el2, 'bottom']);
|
|
55
|
+
dphelper.svg.init(container, [el1, 'right'], [el2, 'left']);
|
|
56
|
+
dphelper.svg.init(container, [el1, 'left'], [el2, 'right']);
|
|
57
|
+
dphelper.svg.init(container, [el1, 'bottom'], [el2, 'top']);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Toggle Connection
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
// Toggle connection with checkbox
|
|
64
|
+
const checkbox = document.getElementById('toggleConnection');
|
|
65
|
+
const container = document.getElementById('diagram');
|
|
66
|
+
const source1 = document.getElementById('node1');
|
|
67
|
+
const source2 = document.getElementById('node2');
|
|
68
|
+
|
|
69
|
+
checkbox.addEventListener('change', (e) => {
|
|
70
|
+
dphelper.svg.toggle(e, container, source1, source2);
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### HTML to SVG Conversion
|
|
75
|
+
|
|
76
|
+
```javascript
|
|
77
|
+
// Convert a div to SVG
|
|
78
|
+
dphelper.svg.convert({
|
|
79
|
+
children: '#myContent', // Element to convert
|
|
80
|
+
active: true,
|
|
81
|
+
size: [1920, 1080], // ViewBox size
|
|
82
|
+
fit: ['100%', '100%'], // Display size
|
|
83
|
+
preserveAspectRatio: 'xMidYMid meet'
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Creates SVG with foreignObject containing the HTML
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Check SVG Support
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
// Check if browser supports SVG
|
|
93
|
+
if (dphelper.svg.check()) {
|
|
94
|
+
console.log('SVG supported');
|
|
95
|
+
} else {
|
|
96
|
+
console.log('SVG not supported - fallback to canvas');
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Remove Connections
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
// Remove all SVG connections from container
|
|
104
|
+
dphelper.svg.removeConnection(document.getElementById('container'));
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Advanced Usage
|
|
108
|
+
|
|
109
|
+
### Flowchart Builder
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
class FlowchartBuilder {
|
|
113
|
+
constructor(containerId) {
|
|
114
|
+
this.container = document.getElementById(containerId);
|
|
115
|
+
this.connections = [];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
addNode(id, x, y, label) {
|
|
119
|
+
const node = document.createElement('div');
|
|
120
|
+
node.id = id;
|
|
121
|
+
node.className = 'flow-node';
|
|
122
|
+
node.style.left = x + 'px';
|
|
123
|
+
node.style.top = y + 'px';
|
|
124
|
+
node.textContent = label;
|
|
125
|
+
this.container.appendChild(node);
|
|
126
|
+
return node;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
connect(fromId, toId) {
|
|
130
|
+
const from = document.getElementById(fromId);
|
|
131
|
+
const to = document.getElementById(toId);
|
|
132
|
+
|
|
133
|
+
dphelper.svg.init(this.container, [from, 'right'], [to, 'left']);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Usage
|
|
138
|
+
const flowchart = new FlowchartBuilder('canvas');
|
|
139
|
+
flowchart.addNode('start', 10, 50, 'Start');
|
|
140
|
+
flowchart.addNode('process', 200, 50, 'Process');
|
|
141
|
+
flowchart.addNode('end', 400, 50, 'End');
|
|
142
|
+
|
|
143
|
+
flowchart.connect('start', 'process');
|
|
144
|
+
flowchart.connect('process', 'end');
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Draggable SVG Elements
|
|
148
|
+
|
|
149
|
+
```javascript
|
|
150
|
+
// Make SVG elements draggable
|
|
151
|
+
const svgElement = document.querySelector('#mySvg circle');
|
|
152
|
+
dphelper.svg.makeDraggable(svgElement);
|
|
153
|
+
|
|
154
|
+
// Enables mouse drag functionality on SVG elements
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Details
|
|
158
|
+
|
|
159
|
+
- **Author:** Dario Passariello
|
|
160
|
+
- **Version:** 0.0.2
|
|
161
|
+
- **Creation Date:** 20210101
|
|
162
|
+
- **Last Modified:** 20260220
|
|
163
|
+
- **Environment:** Client-side only (browser)
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# sync
|
|
2
|
+
|
|
3
|
+
Modern state synchronization and browser storage helpers.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `tab` | Sync data between tabs | `dphelper.sync.tab(channel, callback)` |
|
|
10
|
+
| `storageProxy` | Auto-syncing localStorage proxy | `dphelper.sync.storageProxy(key, defaultValue)` |
|
|
11
|
+
| `pulse` | Low-latency cross-tab event bus | `dphelper.sync.pulse(channel, callback)` |
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
Cross-tab synchronization:
|
|
16
|
+
- **BroadcastChannel** - Native browser API for tab communication
|
|
17
|
+
- **Storage Proxy** - Automatic localStorage synchronization
|
|
18
|
+
- **Event Bus** - Real-time messaging between tabs
|
|
19
|
+
- **Security** - Same-origin validation, prototype pollution protection
|
|
20
|
+
|
|
21
|
+
## Usage Examples
|
|
22
|
+
|
|
23
|
+
### Cross-Tab Communication
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
// Open two tabs and communicate between them
|
|
27
|
+
|
|
28
|
+
// In Tab 1: Listen for messages
|
|
29
|
+
const sync = dphelper.sync.tab('chat', (data) => {
|
|
30
|
+
console.log('Received:', data);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// In Tab 1: Send message to other tabs
|
|
34
|
+
sync.post({ message: 'Hello from Tab 1!' });
|
|
35
|
+
|
|
36
|
+
// When done, close the channel
|
|
37
|
+
sync.close();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Real-time Updates Across Tabs
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
// Sync user preferences across tabs
|
|
44
|
+
const prefs = dphelper.sync.tab('user_prefs', (data) => {
|
|
45
|
+
console.log('Preferences updated:', data);
|
|
46
|
+
applyTheme(data.theme);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Update preferences (sends to all other tabs)
|
|
50
|
+
prefs.post({ theme: 'dark', notifications: true });
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Auto-syncing localStorage
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// Create auto-syncing storage proxy
|
|
57
|
+
const settings = dphelper.sync.storageProxy('app_settings', {
|
|
58
|
+
theme: 'light',
|
|
59
|
+
language: 'en',
|
|
60
|
+
notifications: true
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Changes automatically sync to localStorage
|
|
64
|
+
settings.theme = 'dark';
|
|
65
|
+
// localStorage now has: { "app_settings": "{\"theme\":\"dark\",...}" }
|
|
66
|
+
|
|
67
|
+
// Changes sync across tabs (with StorageEvent listener)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### With Encryption
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
// Create encrypted storage proxy
|
|
74
|
+
const secureSettings = dphelper.sync.storageProxy('secure_data', {
|
|
75
|
+
apiKey: 'secret-key',
|
|
76
|
+
token: 'auth-token'
|
|
77
|
+
}, 'my-secret-key');
|
|
78
|
+
|
|
79
|
+
// Data is encrypted in localStorage
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Pulse Event Bus
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
// Low-latency messaging with pulse
|
|
86
|
+
const pulse = dphelper.sync.pulse('notifications', (data) => {
|
|
87
|
+
showNotification(data);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Send notification
|
|
91
|
+
pulse.emit({ type: 'info', message: 'New message!' });
|
|
92
|
+
|
|
93
|
+
// Stop listening
|
|
94
|
+
pulse.stop();
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Complete Real-time App
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
// Multi-tab state management
|
|
101
|
+
class TabSync {
|
|
102
|
+
constructor(channel) {
|
|
103
|
+
this.channel = channel;
|
|
104
|
+
this.connection = null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
connect() {
|
|
108
|
+
this.connection = dphelper.sync.tab(this.channel, (data) => {
|
|
109
|
+
this.handleMessage(data);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
handleMessage(data) {
|
|
114
|
+
console.log('Sync:', data);
|
|
115
|
+
// Update UI
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
broadcast(action, payload) {
|
|
119
|
+
if (this.connection) {
|
|
120
|
+
this.connection.post({ action, payload, timestamp: Date.now() });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
disconnect() {
|
|
125
|
+
if (this.connection) {
|
|
126
|
+
this.connection.close();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Usage
|
|
132
|
+
const sync = new TabSync('app_state');
|
|
133
|
+
sync.connect();
|
|
134
|
+
sync.broadcast('UPDATE_USER', { name: 'John' });
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Details
|
|
138
|
+
|
|
139
|
+
- **Author:** Dario Passariello & Jo
|
|
140
|
+
- **Version:** 0.0.2
|
|
141
|
+
- **Creation Date:** 20260220
|
|
142
|
+
- **Last Modified:** 20260221
|
|
143
|
+
- **Environment:** client (browser)
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# system
|
|
2
|
+
|
|
3
|
+
Utilities for extending system-level functionality.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `multiSplit` | Split string by multiple delimiters | `dphelper.system.multiSplit(str, tokens)` |
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
System-level utilities:
|
|
14
|
+
- **Multi-Split** - Split a string using multiple delimiters at once
|
|
15
|
+
- **Safe** - No prototype pollution, clean implementation
|
|
16
|
+
|
|
17
|
+
## Usage Examples
|
|
18
|
+
|
|
19
|
+
### Multi-Split
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
// Split by multiple delimiters
|
|
23
|
+
const str = "apple,pear:banana;orange";
|
|
24
|
+
const fruits = dphelper.system.multiSplit(str, [',', ':', ';']);
|
|
25
|
+
// Result: ["apple", "pear", "banana", "orange"]
|
|
26
|
+
|
|
27
|
+
// Parse CSV with mixed delimiters
|
|
28
|
+
const data = "name,email:phone;address";
|
|
29
|
+
const parts = dphelper.system.multiSplit(data, [',', ':', ';']);
|
|
30
|
+
// ["name", "email", "phone", "address"]
|
|
31
|
+
|
|
32
|
+
// Parse log line
|
|
33
|
+
const log = "ERROR|WARNING|INFO:message here";
|
|
34
|
+
const sections = dphelper.system.multiSplit(log, ['|', ':']);
|
|
35
|
+
// ["ERROR", "WARNING", "INFO", "message here"]
|
|
36
|
+
|
|
37
|
+
// URL parsing
|
|
38
|
+
const url = "protocol:host/path?query=value";
|
|
39
|
+
const urlParts = dphelper.system.multiSplit(url, ['://', '/', '?', '=']);
|
|
40
|
+
// More complex parsing
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Parse Complex Data
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
// Parse mixed delimiter data
|
|
47
|
+
function parseData(input) {
|
|
48
|
+
const delimiters = [',', ';', '|', '\t'];
|
|
49
|
+
return dphelper.system.multiSplit(input.trim(), delimiters);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
console.log(parseData("a,b;c|d"));
|
|
53
|
+
// ["a", "b", "c", "d"]
|
|
54
|
+
|
|
55
|
+
console.log(parseData("item1\titem2,item3;item4"));
|
|
56
|
+
// ["item1", "item2", "item3", "item4"]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### CSV Header Processing
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
// Process CSV with various delimiters
|
|
63
|
+
const csv = "name,age,city;country";
|
|
64
|
+
const headers = dphelper.system.multiSplit(csv, [',', ';']);
|
|
65
|
+
// ["name", "age", "city", "country"]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Details
|
|
69
|
+
|
|
70
|
+
- **Author:** Dario Passariello
|
|
71
|
+
- **Version:** 0.0.2
|
|
72
|
+
- **Creation Date:** 20231121
|
|
73
|
+
- **Last Modified:** 20260220
|
|
74
|
+
- **Environment:** both (browser + Node.js)
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
*Automatically generated document*
|