dphelper 3.5.5 → 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/README.md +0 -21
- 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 +4 -6
- package/types/dphelper.d.ts +0 -15
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# terminal
|
|
2
|
+
|
|
3
|
+
Creates a terminal-like interface in the browser console or a DOM element.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `terminal` | Create terminal in DOM element | `dphelper.terminal(parentDom)` |
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
In-browser terminal:
|
|
14
|
+
- **Console Redirect** - Redirect console methods to DOM
|
|
15
|
+
- **Visual Output** - See logs in a visual terminal
|
|
16
|
+
- **Debugging** - Great for debugging web apps
|
|
17
|
+
- **Interactive** - Create terminal-like interface
|
|
18
|
+
|
|
19
|
+
## Usage Examples
|
|
20
|
+
|
|
21
|
+
### Create Terminal
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Create terminal in a div
|
|
25
|
+
const terminalDiv = document.getElementById('terminal');
|
|
26
|
+
dphelper.terminal(terminalDiv);
|
|
27
|
+
|
|
28
|
+
// Now console.log, console.error etc. appear in the div
|
|
29
|
+
console.log("Hello Terminal!");
|
|
30
|
+
console.error("Error message");
|
|
31
|
+
console.warn("Warning");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Debug Panel
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// Add debug terminal to page
|
|
38
|
+
<div id="debug-terminal" style="background: #000; color: #0f0; padding: 10px;"></div>
|
|
39
|
+
|
|
40
|
+
dphelper.terminal('#debug-terminal');
|
|
41
|
+
|
|
42
|
+
// All console output now goes to the terminal
|
|
43
|
+
console.log('App started');
|
|
44
|
+
console.debug('Debug info');
|
|
45
|
+
console.error('Something went wrong');
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Application Logging
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
// Use as application log viewer
|
|
52
|
+
function initDebugTerminal() {
|
|
53
|
+
const terminal = document.getElementById('terminal');
|
|
54
|
+
dphelper.terminal(terminal);
|
|
55
|
+
|
|
56
|
+
// Your app logs now appear visually
|
|
57
|
+
console.log('[APP] Initializing...');
|
|
58
|
+
console.log('[APP] Loading data...');
|
|
59
|
+
console.error('[APP] Failed to load');
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Details
|
|
64
|
+
|
|
65
|
+
- **Author:** Dario Passariello
|
|
66
|
+
- **Version:** 0.0.1
|
|
67
|
+
- **Creation Date:** 20240525
|
|
68
|
+
- **Last Modified:** 20240525
|
|
69
|
+
- **Environment:** client (browser)
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
# text
|
|
2
|
+
|
|
3
|
+
Utilities for text and string manipulation.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `trim` | Trim specific characters from string | `dphelper.text.trim(s, c, b, e)` |
|
|
10
|
+
| `capitalize` | Capitalize first letter of each word | `dphelper.text.capitalize(txt)` |
|
|
11
|
+
| `lower` | Convert string to lowercase | `dphelper.text.lower(txt)` |
|
|
12
|
+
| `upper` | Convert string to uppercase | `dphelper.text.upper(txt)` |
|
|
13
|
+
| `nl2br` | Convert newlines to `<br>` tags | `dphelper.text.nl2br(str)` |
|
|
14
|
+
| `sanitize` | Remove HTML tags from string | `dphelper.text.sanitize(str)` |
|
|
15
|
+
| `camelCase.toSpace` | Convert camelCase to space-separated | `dphelper.text.camelCase.toSpace(str)` |
|
|
16
|
+
| `camelCase.toUnderscore` | Convert camelCase to underscore | `dphelper.text.camelCase.toUnderscore(str)` |
|
|
17
|
+
| `fitContainer` | Auto-adjust font size to fit container | `dphelper.text.fitContainer(selector)` |
|
|
18
|
+
| `keywords` | Extract keywords from sentence | `dphelper.text.keywords(sentence)` |
|
|
19
|
+
| `replaceText` | Replace multiple patterns in text | `dphelper.text.replaceText(text, replacements)` |
|
|
20
|
+
|
|
21
|
+
## Description
|
|
22
|
+
|
|
23
|
+
Comprehensive text manipulation utilities:
|
|
24
|
+
- **Case Conversion** - lower, upper, capitalize
|
|
25
|
+
- **HTML Conversion** - nl2br, sanitize HTML tags
|
|
26
|
+
- **camelCase** - Convert to/from space or underscore
|
|
27
|
+
- **Text Extraction** - Extract keywords from text
|
|
28
|
+
- **Pattern Replacement** - Multi-replacement operations
|
|
29
|
+
|
|
30
|
+
## Usage Examples
|
|
31
|
+
|
|
32
|
+
### Capitalize
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// Capitalize each word
|
|
36
|
+
const text = 'hello world from dpHelper';
|
|
37
|
+
const capitalized = dphelper.text.capitalize(text);
|
|
38
|
+
// Output: "Hello World From DpHelper"
|
|
39
|
+
|
|
40
|
+
// Use for titles
|
|
41
|
+
const title = 'the quick brown fox';
|
|
42
|
+
console.log(dphelper.text.capitalize(title));
|
|
43
|
+
// "The Quick Brown Fox"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Lower/Upper Case
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
// Convert to lowercase
|
|
50
|
+
const upper = 'HELLO WORLD';
|
|
51
|
+
console.log(dphelper.text.lower(upper));
|
|
52
|
+
// "hello world"
|
|
53
|
+
|
|
54
|
+
// Convert to uppercase
|
|
55
|
+
const lower = 'hello world';
|
|
56
|
+
console.log(dphelper.text.upper(lower));
|
|
57
|
+
// "HELLO WORLD"
|
|
58
|
+
|
|
59
|
+
// Normalize user input
|
|
60
|
+
const username = ' JohnDoe ';
|
|
61
|
+
console.log(dphelper.text.lower(username.trim()));
|
|
62
|
+
// "johndoe"
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Newlines to BR Tags
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// Convert newlines to HTML <br>
|
|
69
|
+
const text = 'Line 1\nLine 2\nLine 3';
|
|
70
|
+
const html = dphelper.text.nl2br(text);
|
|
71
|
+
// Output: "Line 1<br>Line 2<br>Line 3"
|
|
72
|
+
|
|
73
|
+
// Display user textarea content
|
|
74
|
+
function displayTextareaContent(textareaValue) {
|
|
75
|
+
return dphelper.text.nl2br(textareaValue);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Preserve whitespace
|
|
79
|
+
const poem = 'Roses are red\nViolets are blue\nSugar is sweet\nAnd so are you';
|
|
80
|
+
document.getElementById('poem').innerHTML = dphelper.text.nl2br(poem);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Remove HTML Tags
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
// Strip HTML tags
|
|
87
|
+
const html = '<p>Hello <b>World</b></p>';
|
|
88
|
+
const plain = dphelper.text.sanitize(html);
|
|
89
|
+
// Output: "Hello World"
|
|
90
|
+
|
|
91
|
+
// Get plain text from rich editor
|
|
92
|
+
function getPlainText(htmlContent) {
|
|
93
|
+
return dphelper.text.sanitize(htmlContent);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Extract text from HTML
|
|
97
|
+
const article = '<article><h1>Title</h1><p>Content here</p></article>';
|
|
98
|
+
console.log(dphelper.text.sanitize(article));
|
|
99
|
+
// "TitleContent here"
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### camelCase Conversions
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
// camelCase to space-separated
|
|
106
|
+
const camel = 'userNameFirst';
|
|
107
|
+
const spaced = dphelper.text.camelCase.toSpace(camel);
|
|
108
|
+
// Output: "User Name First"
|
|
109
|
+
|
|
110
|
+
// camelCase to underscore
|
|
111
|
+
const underscored = dphelper.text.camelCase.toUnderscore(camel);
|
|
112
|
+
// Output: "user_name_first"
|
|
113
|
+
|
|
114
|
+
// Use for readable labels
|
|
115
|
+
function createLabel(key) {
|
|
116
|
+
return dphelper.text.camelCase.toSpace(key);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
console.log(createLabel('firstName')); // "First Name"
|
|
120
|
+
console.log(createLabel('lastName')); // "Last Name"
|
|
121
|
+
console.log(createLabel('emailAddress')); // "Email Address"
|
|
122
|
+
|
|
123
|
+
// Database to UI
|
|
124
|
+
const dbColumn = 'createdAtDate';
|
|
125
|
+
console.log(dphelper.text.camelCase.toSpace(dbColumn));
|
|
126
|
+
// "Created At Date"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Extract Keywords
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
// Extract keywords from text (words > 3 chars, title case)
|
|
133
|
+
const sentence = 'The JavaScript Programming Language is Amazing';
|
|
134
|
+
const keywords = dphelper.text.keywords(sentence);
|
|
135
|
+
// Output: ["javascript", "programming", "language", "amazing"]
|
|
136
|
+
|
|
137
|
+
// Analyze text content
|
|
138
|
+
function analyzeContent(text) {
|
|
139
|
+
return {
|
|
140
|
+
keywords: dphelper.text.keywords(text),
|
|
141
|
+
wordCount: text.split(/\s+/).length
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Tag generation
|
|
146
|
+
const article = 'React is a JavaScript library for building user interfaces';
|
|
147
|
+
const tags = dphelper.text.keywords(article);
|
|
148
|
+
// ["react", "javascript", "library", "building", "user", "interfaces"]
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Replace Multiple Patterns
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
// Replace multiple patterns at once
|
|
155
|
+
const text = 'Copyright (c) 2024 by Company (r)';
|
|
156
|
+
const result = dphelper.text.replaceText(text, {
|
|
157
|
+
'(c)': '©',
|
|
158
|
+
'(r)': '®',
|
|
159
|
+
'(tm)': '™'
|
|
160
|
+
});
|
|
161
|
+
// Output: "Copyright © 2024 by Company ®"
|
|
162
|
+
|
|
163
|
+
// Symbol replacement
|
|
164
|
+
const legal = 'Copyright (c) 2024 (r) All Rights Reserved (tm)';
|
|
165
|
+
console.log(dphelper.text.replaceText(legal, {
|
|
166
|
+
'(c)': '©',
|
|
167
|
+
'(r)': '®',
|
|
168
|
+
'(tm)': '™'
|
|
169
|
+
}));
|
|
170
|
+
// "Copyright © 2024 ® All Rights Reserved ™"
|
|
171
|
+
|
|
172
|
+
// Emoticon replacement
|
|
173
|
+
const message = 'Hello :) Have a great day !';
|
|
174
|
+
const emoticons = dphelper.text.replaceText(message, {
|
|
175
|
+
':)': '😊',
|
|
176
|
+
'(:': '😊',
|
|
177
|
+
':(': '😢',
|
|
178
|
+
'):': '😢',
|
|
179
|
+
'!': '❗'
|
|
180
|
+
});
|
|
181
|
+
// "Hello 😊 Have a great day ❗"
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Auto-fit Text to Container
|
|
185
|
+
|
|
186
|
+
```javascript
|
|
187
|
+
// Automatically adjust font size to fit container width
|
|
188
|
+
// HTML: <div id="title">Long Title Text Here</div>
|
|
189
|
+
|
|
190
|
+
dphelper.text.fitContainer('#title');
|
|
191
|
+
|
|
192
|
+
// The font-size will auto-adjust based on container width
|
|
193
|
+
// Responds to window resize events
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Complete Form Processor
|
|
197
|
+
|
|
198
|
+
```javascript
|
|
199
|
+
class TextProcessor {
|
|
200
|
+
static formatTitle(text) {
|
|
201
|
+
return dphelper.text.capitalize(dphelper.text.lower(text.trim()));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
static toSlug(text) {
|
|
205
|
+
const spaced = dphelper.text.camelCase.toUnderscore(text);
|
|
206
|
+
return dphelper.text.lower(spaced).replace(/\s+/g, '-');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static extractSearchTerms(text) {
|
|
210
|
+
return dphelper.text.keywords(text);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
static prepareForDisplay(text) {
|
|
214
|
+
return dphelper.text.nl2br(
|
|
215
|
+
dphelper.text.sanitize(text)
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
static replaceSymbols(text, symbols) {
|
|
220
|
+
return dphelper.text.replaceText(text, symbols);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Usage
|
|
225
|
+
console.log(TextProcessor.formatTitle('HELLO WORLD'));
|
|
226
|
+
// "Hello world"
|
|
227
|
+
|
|
228
|
+
console.log(TextProcessor.toSlug('User Name First'));
|
|
229
|
+
// "user_name_first"
|
|
230
|
+
|
|
231
|
+
console.log(TextProcessor.extractSearchTerms('React and Vue are Frameworks'));
|
|
232
|
+
// ["react", "vue", "frameworks"]
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## Details
|
|
236
|
+
|
|
237
|
+
- **Author:** Dario Passariello
|
|
238
|
+
- **Version:** 0.0.2
|
|
239
|
+
- **Creation Date:** 20210101
|
|
240
|
+
- **Last Modified:** 20260220
|
|
241
|
+
- **Environment:** both (browser + Node.js)
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# timer
|
|
2
|
+
|
|
3
|
+
Management of timers, delays, and intervals.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `sleep` | Pause execution for milliseconds | `dphelper.timer.sleep(ms)` |
|
|
10
|
+
| `percentage` | Calculate time percentage between dates | `dphelper.timer.percentage(start, end)` |
|
|
11
|
+
|
|
12
|
+
## Description
|
|
13
|
+
|
|
14
|
+
Timer utilities:
|
|
15
|
+
- **Sleep** - Async pause/delay
|
|
16
|
+
- **Percentage** - Calculate elapsed time percentage
|
|
17
|
+
|
|
18
|
+
## Usage Examples
|
|
19
|
+
|
|
20
|
+
### Sleep/Delay
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
// Async delay
|
|
24
|
+
await dphelper.timer.sleep(1000);
|
|
25
|
+
// Pauses for 1 second
|
|
26
|
+
|
|
27
|
+
// In async functions
|
|
28
|
+
async function delayedAction() {
|
|
29
|
+
console.log('Start');
|
|
30
|
+
await dphelper.timer.sleep(2000);
|
|
31
|
+
console.log('After 2 seconds');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Retry with delay
|
|
35
|
+
async function retryWithBackoff(fn, maxRetries = 3) {
|
|
36
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
37
|
+
try {
|
|
38
|
+
return await fn();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (i < maxRetries - 1) {
|
|
41
|
+
await dphelper.timer.sleep(1000 * Math.pow(2, i));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Time Percentage
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
// Calculate progress percentage
|
|
52
|
+
const start = new Date('2024-01-01');
|
|
53
|
+
const end = new Date('2024-12-31');
|
|
54
|
+
const now = new Date('2024-06-15');
|
|
55
|
+
|
|
56
|
+
const progress = dphelper.timer.percentage(start, end);
|
|
57
|
+
// Returns percentage of year complete (approximately 50%)
|
|
58
|
+
|
|
59
|
+
// Countdown timer
|
|
60
|
+
const eventStart = new Date('2024-12-25');
|
|
61
|
+
const today = new Date();
|
|
62
|
+
|
|
63
|
+
const percentComplete = dphelper.timer.percentage(today, eventStart);
|
|
64
|
+
console.log(`${percentComplete}% until event`);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Progress Tracking
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
// Track operation progress
|
|
71
|
+
function trackProgress(startTime, duration) {
|
|
72
|
+
const now = Date.now();
|
|
73
|
+
const elapsed = now - startTime;
|
|
74
|
+
return dphelper.timer.percentage(startTime, startTime + duration);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const operationDuration = 10000; // 10 seconds
|
|
78
|
+
const start = Date.now();
|
|
79
|
+
|
|
80
|
+
// In a loop
|
|
81
|
+
setInterval(() => {
|
|
82
|
+
const progress = trackProgress(start, operationDuration);
|
|
83
|
+
console.log(`${progress}% complete`);
|
|
84
|
+
if (progress >= 100) clearInterval(this);
|
|
85
|
+
}, 500);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Details
|
|
89
|
+
|
|
90
|
+
- **Author:** Dario Passariello
|
|
91
|
+
- **Version:** 0.0.2
|
|
92
|
+
- **Creation Date:** 20210101
|
|
93
|
+
- **Last Modified:** 20260220
|
|
94
|
+
- **Environment:** both (browser + Node.js)
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# tools
|
|
2
|
+
|
|
3
|
+
Miscellaneous developer utilities for common programming tasks.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `byteSize` | Converts bytes to human-readable format (KB, MB, GB, etc.) | `dphelper.tools.byteSize(1024)` |
|
|
10
|
+
| `zIndex` | Finds the highest z-index value in the DOM | `dphelper.tools.zIndex()` |
|
|
11
|
+
| `zeroToFalse` | Converts zero to false, otherwise returns the value | `dphelper.tools.zeroToFalse(0)` |
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
This module provides various utility functions that are commonly needed in web development projects. It includes byte size conversion, DOM z-index detection, and value transformation utilities.
|
|
16
|
+
|
|
17
|
+
## Usage Examples
|
|
18
|
+
|
|
19
|
+
### Byte Size Conversion
|
|
20
|
+
|
|
21
|
+
Convert file sizes from bytes to human-readable format:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
// Convert bytes to KB, MB, GB, etc.
|
|
25
|
+
console.log(dphelper.tools.byteSize(500)); // "500b"
|
|
26
|
+
console.log(dphelper.tools.byteSize(1024)); // "1.0Kb"
|
|
27
|
+
console.log(dphelper.tools.byteSize(1048576)); // "1.0Mb"
|
|
28
|
+
console.log(dphelper.tools.byteSize(1073741824)); // "1.0Gb"
|
|
29
|
+
|
|
30
|
+
// Useful for displaying file sizes
|
|
31
|
+
const fileSize = 15728640; // 15 MB in bytes
|
|
32
|
+
console.log(dphelper.tools.byteSize(fileSize)); // "15.0Mb"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Z-Index Detection
|
|
36
|
+
|
|
37
|
+
Find the highest z-index in the document to ensure new elements appear on top:
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
// Get the highest z-index in the DOM
|
|
41
|
+
const highestZ = dphelper.tools.zIndex();
|
|
42
|
+
console.log(highestZ); // e.g., 100
|
|
43
|
+
|
|
44
|
+
// Create a new modal on top of all other elements
|
|
45
|
+
const modal = document.createElement('div');
|
|
46
|
+
modal.style.zIndex = highestZ + 1;
|
|
47
|
+
modal.style.position = 'absolute';
|
|
48
|
+
document.body.appendChild(modal);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Zero to False Conversion
|
|
52
|
+
|
|
53
|
+
Convert numeric zero to boolean false for conditional logic:
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
// Returns false when value is 0
|
|
57
|
+
console.log(dphelper.tools.zeroToFalse(0)); // false
|
|
58
|
+
console.log(dphelper.tools.zeroToFalse(1)); // 1
|
|
59
|
+
console.log(dphelper.tools.zeroToFalse(42)); // 42
|
|
60
|
+
console.log(dphelper.tools.zeroToFalse(-5)); // -5
|
|
61
|
+
|
|
62
|
+
// Useful in form validation
|
|
63
|
+
const count = 0;
|
|
64
|
+
if (dphelper.tools.zeroToFalse(count)) {
|
|
65
|
+
console.log('Count is valid');
|
|
66
|
+
} else {
|
|
67
|
+
console.log('Count is zero or invalid');
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Advanced Usage
|
|
72
|
+
|
|
73
|
+
### Creating a File Size Display Component
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
function formatFileSize(bytes) {
|
|
77
|
+
return dphelper.tools.byteSize(bytes);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Display various file sizes
|
|
81
|
+
const files = [256, 1024, 1024 * 50, 1024 * 1024, 1024 * 1024 * 2];
|
|
82
|
+
files.forEach(size => {
|
|
83
|
+
console.log(`${size} bytes = ${formatFileSize(size)}`);
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Modal Management
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
function openModal(content) {
|
|
91
|
+
const highestZ = dphelper.tools.zIndex();
|
|
92
|
+
const modal = document.createElement('div');
|
|
93
|
+
modal.className = 'modal-overlay';
|
|
94
|
+
modal.style.zIndex = highestZ + 1;
|
|
95
|
+
modal.innerHTML = content;
|
|
96
|
+
document.body.appendChild(modal);
|
|
97
|
+
return modal;
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Details
|
|
102
|
+
|
|
103
|
+
- **Author:** Dario Passariello
|
|
104
|
+
- **Version:** 0.0.2
|
|
105
|
+
- **Creation Date:** 20210101
|
|
106
|
+
- **Last Modified:** 20260220
|
|
107
|
+
- **Environment:** Works in both client and server environments
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# translators
|
|
2
|
+
|
|
3
|
+
Utilities for transformation conversions.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `convertMatrixToScale` | Convert CSS matrix to scale values | `dphelper.translators.convertMatrixToScale(matrix)` |
|
|
10
|
+
|
|
11
|
+
## Description
|
|
12
|
+
|
|
13
|
+
CSS transformation utilities:
|
|
14
|
+
- **Matrix to Scale** - Parse CSS transform matrix
|
|
15
|
+
- **Extract Values** - Get scaleX, scaleY from matrix
|
|
16
|
+
|
|
17
|
+
## Usage Examples
|
|
18
|
+
|
|
19
|
+
### Convert Matrix to Scale
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
// Get element's transform matrix
|
|
23
|
+
const element = document.getElementById('myElement');
|
|
24
|
+
const style = window.getComputedStyle(element);
|
|
25
|
+
const matrix = style.transform;
|
|
26
|
+
|
|
27
|
+
// Convert matrix to scale values
|
|
28
|
+
const scale = dphelper.translators.convertMatrixToScale({ value: matrix });
|
|
29
|
+
// Returns { scaleX, scaleY }
|
|
30
|
+
|
|
31
|
+
// Example with known matrix
|
|
32
|
+
const result = dphelper.translators.convertMatrixToScale({
|
|
33
|
+
value: 'matrix(2, 0, 0, 2, 0, 0)'
|
|
34
|
+
});
|
|
35
|
+
// { scaleX: 2, scaleY: 2 }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Animation Scaling
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// Track element scale during animation
|
|
42
|
+
function getScale(element) {
|
|
43
|
+
const style = window.getComputedStyle(element);
|
|
44
|
+
return dphelper.translators.convertMatrixToScale({ value: style.transform });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Monitor scale changes
|
|
48
|
+
const element = document.querySelector('.scaling-element');
|
|
49
|
+
setInterval(() => {
|
|
50
|
+
const scale = getScale(element);
|
|
51
|
+
console.log(`Current scale: ${scale.scaleX}x${scale.scaleY}`);
|
|
52
|
+
}, 100);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Details
|
|
56
|
+
|
|
57
|
+
- **Author:** Dario Passariello
|
|
58
|
+
- **Version:** 0.0.1
|
|
59
|
+
- **Creation Date:** 20210101
|
|
60
|
+
- **Last Modified:** 20210101
|
|
61
|
+
- **Environment:** client (browser)
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
*Automatically generated document*
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# trigger
|
|
2
|
+
|
|
3
|
+
Programmatic DOM event triggers.
|
|
4
|
+
|
|
5
|
+
## Functions
|
|
6
|
+
|
|
7
|
+
| Function | Description | Example |
|
|
8
|
+
|----------|-------------|---------|
|
|
9
|
+
| `click` | Trigger click event | `dphelper.trigger.click(element)` |
|
|
10
|
+
| `change` | Trigger change event | `dphelper.trigger.change(element)` |
|
|
11
|
+
| `input` | Trigger input event | `dphelper.trigger.input(element)` |
|
|
12
|
+
|
|
13
|
+
## Description
|
|
14
|
+
|
|
15
|
+
Programmatic event triggering:
|
|
16
|
+
- **Click** - Simulate user clicks
|
|
17
|
+
- **Change** - Trigger value change events
|
|
18
|
+
- **Input** - Trigger input events
|
|
19
|
+
- **Testing** - Useful for automated testing
|
|
20
|
+
|
|
21
|
+
## Usage Examples
|
|
22
|
+
|
|
23
|
+
### Trigger Click
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
// Click an element
|
|
27
|
+
const button = document.getElementById('submit');
|
|
28
|
+
dphelper.trigger.click(button);
|
|
29
|
+
|
|
30
|
+
// Click first element in collection
|
|
31
|
+
const links = document.querySelectorAll('.nav-link');
|
|
32
|
+
if (links.length > 0) {
|
|
33
|
+
dphelper.trigger.click(links[0]);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Trigger Change
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
// Trigger change on input
|
|
41
|
+
const input = document.getElementById('username');
|
|
42
|
+
input.value = 'newvalue';
|
|
43
|
+
dphelper.trigger.change(input);
|
|
44
|
+
|
|
45
|
+
// Trigger change on select
|
|
46
|
+
const select = document.getElementById('country');
|
|
47
|
+
select.value = 'US';
|
|
48
|
+
dphelper.trigger.change(select);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Trigger Input
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
// Trigger input event
|
|
55
|
+
const input = document.getElementById('search');
|
|
56
|
+
input.value = 'search term';
|
|
57
|
+
dphelper.trigger.input(input);
|
|
58
|
+
|
|
59
|
+
// For autocomplete/typeahead
|
|
60
|
+
function simulateTyping(element, text) {
|
|
61
|
+
element.value = '';
|
|
62
|
+
text.split('').forEach((char, i) => {
|
|
63
|
+
element.value += char;
|
|
64
|
+
dphelper.trigger.input(element);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Form Automation
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// Fill and submit form programmatically
|
|
73
|
+
function fillForm(data) {
|
|
74
|
+
Object.entries(data).forEach(([field, value]) => {
|
|
75
|
+
const input = document.querySelector(`[name="${field}"]`);
|
|
76
|
+
if (input) {
|
|
77
|
+
input.value = value;
|
|
78
|
+
dphelper.trigger.input(input);
|
|
79
|
+
dphelper.trigger.change(input);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Submit
|
|
84
|
+
const submitBtn = document.querySelector('button[type="submit"]');
|
|
85
|
+
dphelper.trigger.click(submitBtn);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Details
|
|
90
|
+
|
|
91
|
+
- **Author:** Dario Passariello
|
|
92
|
+
- **Version:** 0.0.1
|
|
93
|
+
- **Creation Date:** 20210101
|
|
94
|
+
- **Last Modified:** 20241001
|
|
95
|
+
- **Environment:** client (browser)
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
*Automatically generated document*
|