dphelper 4.2.0 → 4.2.3

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.
Files changed (59) hide show
  1. package/README.md +6 -5
  2. package/index.cjs +1 -1
  3. package/index.js +1 -1
  4. package/package.json +3 -3
  5. package/markdown/ai.md +0 -345
  6. package/markdown/anchor.md +0 -156
  7. package/markdown/array.md +0 -208
  8. package/markdown/audio.md +0 -113
  9. package/markdown/avoid.md +0 -53
  10. package/markdown/biometric.md +0 -338
  11. package/markdown/browser.md +0 -203
  12. package/markdown/check.md +0 -65
  13. package/markdown/color.md +0 -159
  14. package/markdown/compress.md +0 -310
  15. package/markdown/cookie.md +0 -115
  16. package/markdown/coords.md +0 -127
  17. package/markdown/credits.md +0 -56
  18. package/markdown/date.md +0 -260
  19. package/markdown/disable.md +0 -109
  20. package/markdown/dispatch.md +0 -108
  21. package/markdown/element.md +0 -53
  22. package/markdown/event.md +0 -85
  23. package/markdown/fetch.md +0 -122
  24. package/markdown/form.md +0 -302
  25. package/markdown/format.md +0 -122
  26. package/markdown/i18n.md +0 -292
  27. package/markdown/image.md +0 -298
  28. package/markdown/json.md +0 -269
  29. package/markdown/load.md +0 -133
  30. package/markdown/logging.md +0 -99
  31. package/markdown/math.md +0 -172
  32. package/markdown/memory.md +0 -85
  33. package/markdown/navigation.md +0 -152
  34. package/markdown/net.md +0 -60
  35. package/markdown/obj.md +0 -242
  36. package/markdown/path.md +0 -46
  37. package/markdown/promise.md +0 -94
  38. package/markdown/sanitize.md +0 -118
  39. package/markdown/screen.md +0 -78
  40. package/markdown/scrollbar.md +0 -82
  41. package/markdown/security.md +0 -289
  42. package/markdown/shortcut.md +0 -100
  43. package/markdown/socket.md +0 -134
  44. package/markdown/sse.md +0 -120
  45. package/markdown/svg.md +0 -167
  46. package/markdown/sync.md +0 -147
  47. package/markdown/system.md +0 -78
  48. package/markdown/terminal.md +0 -73
  49. package/markdown/text.md +0 -245
  50. package/markdown/timer.md +0 -98
  51. package/markdown/tools.md +0 -111
  52. package/markdown/translators.md +0 -65
  53. package/markdown/trigger.md +0 -99
  54. package/markdown/triggers.md +0 -133
  55. package/markdown/type.md +0 -109
  56. package/markdown/types.md +0 -102
  57. package/markdown/ui.md +0 -45
  58. package/markdown/window.md +0 -211
  59. package/markdown/worker.md +0 -223
package/markdown/fetch.md DELETED
@@ -1,122 +0,0 @@
1
- # fetch
2
-
3
- HTTP fetch utilities with automatic retry and exponential backoff.
4
-
5
- ## Functions
6
-
7
- | Function | Description | Example |
8
- |----------|-------------|---------|
9
- | `get` | Perform GET request with retry | `dphelper.fetch.get(url, options)` |
10
- | `post` | Perform POST request with JSON | `dphelper.fetch.post(url, body, options)` |
11
-
12
- ## Description
13
-
14
- HTTP request utilities:
15
- - **GET** - Fetch data with automatic retries
16
- - **POST** - Send JSON data with automatic JSON headers
17
- - **Retry** - Exponential backoff on failure
18
- - **Error Handling** - Automatic retry on network errors
19
-
20
- ## Usage Examples
21
-
22
- ### GET Request
23
-
24
- ```javascript
25
- // Simple GET request
26
- const response = await dphelper.fetch.get('https://api.example.com/data');
27
- const data = await response.json();
28
-
29
- // GET with options
30
- const users = await dphelper.fetch.get('/api/users', {
31
- headers: { 'Authorization': 'Bearer token' }
32
- });
33
- ```
34
-
35
- ### POST Request
36
-
37
- ```javascript
38
- // POST JSON data
39
- const response = await dphelper.fetch.post('/api/users', {
40
- name: 'John',
41
- email: 'john@example.com'
42
- });
43
-
44
- // POST with custom headers
45
- const response = await dphelper.fetch.post('/api/upload', formData, {
46
- headers: { 'X-Custom-Header': 'value' }
47
- });
48
- ```
49
-
50
- ### Error Handling with Retry
51
-
52
- ```javascript
53
- // Automatic retry on failure
54
- async function fetchWithRetry(url, options = {}) {
55
- try {
56
- const response = await dphelper.fetch.get(url, options);
57
- return await response.json();
58
- } catch (error) {
59
- console.error('Fetch failed:', error);
60
- return null;
61
- }
62
- }
63
- ```
64
-
65
- ### API Integration
66
-
67
- ```javascript
68
- class ApiClient {
69
- constructor(baseUrl) {
70
- this.baseUrl = baseUrl;
71
- }
72
-
73
- async get(endpoint) {
74
- const response = await dphelper.fetch.get(`${this.baseUrl}${endpoint}`);
75
- return response.json();
76
- }
77
-
78
- async post(endpoint, data) {
79
- const response = await dphelper.fetch.post(`${this.baseUrl}${endpoint}`, data);
80
- return response.json();
81
- }
82
- }
83
-
84
- const api = new ApiClient('https://api.example.com');
85
- const data = await api.get('/items');
86
- ```
87
-
88
- ## Security Notes
89
-
90
- > [!IMPORTANT]
91
- > Network functions (`fetch`, `SSE`, `socket`) require **input validation** by the caller.
92
-
93
- This library provides networking primitives **by design**:
94
- - HTTP/HTTPS requests
95
- - Server-Sent Events
96
- - WebSocket connections
97
-
98
- As a devtools library, these features are essential for modern web development. **Callers are responsible for validating URLs and data** before passing them to these functions.
99
-
100
- ### Best Practices
101
-
102
- ```javascript
103
- // ALWAYS validate and sanitize user input
104
- const sanitizedUrl = dphelper.sanitize.url(userInput);
105
- const validatedData = dphelper.sanitize.html(userData);
106
-
107
- await dphelper.fetch.get(sanitizedUrl);
108
- ```
109
-
110
- ---
111
-
112
- ## Details
113
-
114
- - **Author:** Dario Passariello
115
- - **Version:** 0.0.2
116
- - **Creation Date:** 20260221
117
- - **Last Modified:** 20260329
118
- - **Environment:** both (browser + Node.js)
119
-
120
- ---
121
-
122
- *Automatically generated document*
package/markdown/form.md DELETED
@@ -1,302 +0,0 @@
1
- # form
2
-
3
- Comprehensive form utilities for validation, serialization, and input management.
4
-
5
- ## Functions
6
-
7
- ### Serialization
8
-
9
- | Function | Description | Example |
10
- |----------|-------------|---------|
11
- | `serialize` | Converts form data to JavaScript object | `dphelper.form.serialize('#myForm')` |
12
-
13
- ### Validation
14
-
15
- | Function | Description | Example |
16
- |----------|-------------|---------|
17
- | `confirmType` | Validates value against a specific type | `dphelper.form.confirmType('email', 'test@example.com')` |
18
- | `required` | Checks if a value is present | `dphelper.form.required(value)` |
19
- | `minLength` | Validates minimum string length | `dphelper.form.minLength('hello', 3)` |
20
- | `maxLength` | Validates maximum string length | `dphelper.form.maxLength('hello', 10)` |
21
- | `maxPhoneNumber` | Validates phone number length | `dphelper.form.maxPhoneNumber('1234567890', 10)` |
22
- | `isNumeric` | Checks if value is numeric | `dphelper.form.isNumeric(42)` |
23
- | `isEmail` | Validates email format | `dphelper.form.isEmail('test@example.com')` |
24
-
25
- ### Input Control
26
-
27
- | Function | Description | Example |
28
- |----------|-------------|---------|
29
- | `pattern` | Validates input against type-specific pattern | `dphelper.form.pattern(event)` |
30
- | `noSpecialChars` | Blocks special characters in input | `dphelper.form.noSpecialChars(event)` |
31
-
32
- ### Utilities
33
-
34
- | Function | Description | Example |
35
- |----------|-------------|---------|
36
- | `table` | Generates an editable data table | `dphelper.form.table([7, 24], 'tableId', element)` |
37
- | `sanitize` | Removes dangerous characters from input | `dphelper.form.sanitize(userInput)` |
38
-
39
- ## Description
40
-
41
- Complete form management solution:
42
- - **Data Serialization** - Form to object conversion with type handling
43
- - **Validation** - Required fields, length, email, numeric, patterns
44
- - **Input Filtering** - Block special characters, pattern enforcement
45
- - **Table Generation** - Create editable data grids
46
- - **Security** - Input sanitization for XSS prevention
47
-
48
- ## Usage Examples
49
-
50
- ### Form Serialization
51
-
52
- ```javascript
53
- // HTML form
54
- // <form id="myForm">
55
- // <input name="username" value="john">
56
- // <input name="age" value="30">
57
- // <input name="active" value="true">
58
- // </form>
59
-
60
- const data = dphelper.form.serialize('#myForm');
61
- console.log(data);
62
- // { username: "john", age: 30, active: true }
63
-
64
- // Handles nested names
65
- // <input name="user[name]" value="John">
66
- // <input name="user[email]" value="john@example.com">
67
-
68
- const userData = dphelper.form.serialize('#myForm');
69
- console.log(userData);
70
- // { user: { name: "John", email: "john@example.com" } }
71
-
72
- // Array handling
73
- // <input name="tags[]" value="javascript">
74
- // <input name="tags[]" value="typescript">
75
-
76
- const tagsData = dphelper.form.serialize('#myForm');
77
- // { tags: ["javascript", "typescript"] }
78
- ```
79
-
80
- ### Form Validation
81
-
82
- ```javascript
83
- // Required field
84
- console.log(dphelper.form.required("hello")); // undefined (valid)
85
- console.log(dphelper.form.required("")); // "Required"
86
- console.log(dphelper.form.required(null)); // "Required"
87
- console.log(dphelper.form.required(undefined)); // "Required"
88
-
89
- // Minimum length
90
- console.log(dphelper.form.minLength("hello", 3)); // undefined (valid)
91
- console.log(dphelper.form.minLength("hi", 3)); // "Must Enter a Value"
92
-
93
- // Maximum length
94
- console.log(dphelper.form.maxLength("hello", 10)); // undefined (valid)
95
- console.log(dphelper.form.maxLength("hello world", 5)); // "Exceeds Max Length"
96
-
97
- // Phone number validation
98
- console.log(dphelper.form.maxPhoneNumber("1234567890", 10)); // undefined
99
- console.log(dphelper.form.maxPhoneNumber("12345678901", 10)); // "Exceeds Max Length"
100
-
101
- // Type confirmation
102
- console.log(dphelper.form.confirmType("number", "123")); // true
103
- console.log(dphelper.form.confirmType("number", "abc")); // false
104
- console.log(dphelper.form.confirmType("email", "test@example.com")); // true
105
- ```
106
-
107
- ### Email Validation
108
-
109
- ```javascript
110
- // Basic email validation
111
- console.log(dphelper.form.isEmail("test@example.com")); // true
112
- console.log(dphelper.form.isEmail("john.doe@company.co.uk")); // true
113
- console.log(dphelper.form.isEmail("invalid")); // false
114
- console.log(dphelper.form.isEmail("@example.com")); // false
115
- console.log(dphelper.form.isEmail("test@")); // false
116
-
117
- // Use in form validation
118
- function validateForm(formData) {
119
- const errors = {};
120
-
121
- if (dphelper.form.required(formData.email)) {
122
- errors.email = "Email is required";
123
- } else if (!dphelper.form.isEmail(formData.email)) {
124
- errors.email = "Invalid email format";
125
- }
126
-
127
- if (dphelper.form.minLength(formData.password, 8)) {
128
- errors.password = "Password must be at least 8 characters";
129
- }
130
-
131
- return errors;
132
- }
133
- ```
134
-
135
- ### Numeric Validation
136
-
137
- ```javascript
138
- // Check if value is numeric
139
- console.log(dphelper.form.isNumeric(123)); // true
140
- console.log(dphelper.form.isNumeric("123")); // true
141
- console.log(dphelper.form.isNumeric("12.34")); // true
142
- console.log(dphelper.form.isNumeric("abc")); // false
143
- console.log(dphelper.form.isNumeric(NaN)); // false
144
- ```
145
-
146
- ### Input Event Handlers
147
-
148
- ```javascript
149
- // Pattern validation on input change
150
- // <input type="text" onchange="dphelper.form.pattern(event)">
151
- document.querySelector('input[type="text"]').addEventListener('change', dphelper.form.pattern);
152
-
153
- // Block special characters
154
- // <input onkeyup="dphelper.form.noSpecialChars(event)">
155
- document.querySelector('input').addEventListener('keyup', dphelper.form.noSpecialChars);
156
-
157
- // Example: Username input
158
- const usernameInput = document.getElementById('username');
159
- usernameInput.addEventListener('input', (e) => {
160
- // Only allow letters, numbers, and underscores
161
- const original = e.target.value;
162
- const cleaned = original.replace(/[^a-zA-Z0-9_]/g, '');
163
- if (cleaned !== original) {
164
- e.target.value = cleaned;
165
- }
166
- });
167
- ```
168
-
169
- ### Table Generation
170
-
171
- ```javascript
172
- // Generate a data entry table
173
- const container = document.getElementById('tableContainer');
174
-
175
- // Default 7 columns x 24 rows
176
- dphelper.form.table([7, 24], 'dataTable', container);
177
-
178
- // Custom size: 5 columns x 10 rows
179
- dphelper.form.table([5, 10], 'myTable', container);
180
-
181
- // Creates an editable table with:
182
- // - Column headers (1-5)
183
- // - Row numbers (1-10)
184
- // - Number inputs in each cell
185
- // - Random values (0-99)
186
- // - Tab navigation (column + row based)
187
- ```
188
-
189
- ### Input Sanitization
190
-
191
- ```javascript
192
- // Remove dangerous characters
193
- console.log(dphelper.form.sanitize("<script>alert('xss')</script>"));
194
- // "scriptalertxssscript"
195
-
196
- // Remove special characters but keep spaces
197
- console.log(dphelper.form.sanitize("Hello World! @#$%"));
198
- // "Hello World "
199
-
200
- // Use for form input
201
- function handleFormSubmit(e) {
202
- e.preventDefault();
203
-
204
- const formData = {};
205
- const inputs = e.target.querySelectorAll('input');
206
-
207
- inputs.forEach(input => {
208
- formData[input.name] = dphelper.form.sanitize(input.value);
209
- });
210
-
211
- // Now safe to process
212
- console.log(formData);
213
- }
214
- ```
215
-
216
- ## Advanced Usage
217
-
218
- ### Complete Form Validation
219
-
220
- ```javascript
221
- class FormValidator {
222
- constructor() {
223
- this.errors = {};
224
- }
225
-
226
- validate(field, value, rules) {
227
- this.errors[field] = undefined;
228
-
229
- if (rules.required) {
230
- const error = dphelper.form.required(value);
231
- if (error) {
232
- this.errors[field] = error;
233
- return false;
234
- }
235
- }
236
-
237
- if (rules.minLength) {
238
- const error = dphelper.form.minLength(value, rules.minLength);
239
- if (error) {
240
- this.errors[field] = error;
241
- return false;
242
- }
243
- }
244
-
245
- if (rules.maxLength) {
246
- const error = dphelper.form.maxLength(value, rules.maxLength);
247
- if (error) {
248
- this.errors[field] = error;
249
- return false;
250
- }
251
- }
252
-
253
- if (rules.email && !dphelper.form.isEmail(value)) {
254
- this.errors[field] = "Invalid email address";
255
- return false;
256
- }
257
-
258
- if (rules.numeric && !dphelper.form.isNumeric(value)) {
259
- this.errors[field] = "Must be a number";
260
- return false;
261
- }
262
-
263
- return true;
264
- }
265
-
266
- getErrors() {
267
- return this.errors;
268
- }
269
-
270
- hasErrors() {
271
- return Object.values(this.errors).some(e => e !== undefined);
272
- }
273
- }
274
-
275
- // Usage
276
- const validator = new FormValidator();
277
-
278
- validator.validate('username', 'john', {
279
- required: true,
280
- minLength: 3,
281
- maxLength: 20
282
- });
283
-
284
- validator.validate('email', 'john@example.com', {
285
- required: true,
286
- email: true
287
- });
288
-
289
- console.log(validator.getErrors());
290
- ```
291
-
292
- ## Details
293
-
294
- - **Author:** Dario Passariello
295
- - **Version:** 0.0.2
296
- - **Creation Date:** 20210101
297
- - **Last Modified:** 20260220
298
- - **Environment:** Client-side only (browser)
299
-
300
- ---
301
-
302
- *Automatically generated document*
@@ -1,122 +0,0 @@
1
- # format
2
-
3
- Utilities for data formatting like currency and phone numbers.
4
-
5
- ## Functions
6
-
7
- | Function | Description | Example |
8
- |----------|-------------|---------|
9
- | `currency` | Format a number as currency | `dphelper.format.currency(value, locale, currency)` |
10
- | `phoneNumber` | Format a string as a phone number | `dphelper.format.phoneNumber(value, countryCode)` |
11
-
12
- ## Description
13
-
14
- Data formatting utilities:
15
- - **Currency** - Format numbers with locale-specific currency symbols using Intl API
16
- - **Phone Numbers** - Format phone numbers by country code
17
- - **Localization** - Supports multiple locales (en-US, de-DE, ja-JPY, etc.)
18
-
19
- ## Usage Examples
20
-
21
- ### Currency Formatting
22
-
23
- ```javascript
24
- // Basic USD currency (default)
25
- const price = dphelper.format.currency(1234.56);
26
- // Output: "$1,234.56"
27
-
28
- // Euro currency with German locale
29
- const euro = dphelper.format.currency(1234.56, 'de-DE', 'EUR');
30
- // Output: "1.234,56 €"
31
-
32
- // Japanese Yen
33
- const yen = dphelper.format.currency(5000, 'ja-JPY', 'JPY');
34
- // Output: "¥5,000"
35
-
36
- // British Pound
37
- const pound = dphelper.format.currency(99.99, 'en-GB', 'GBP');
38
- // Output: "£99.99"
39
-
40
- // Swiss Franc
41
- const franc = dphelper.format.currency(1500, 'de-CH', 'CHF');
42
- // Output: "CHF 1'500.00"
43
- ```
44
-
45
- ### Phone Number Formatting
46
-
47
- ```javascript
48
- // US phone number
49
- const usPhone = dphelper.format.phoneNumber('5551234567', 'US');
50
- // Output: "(555) 123-4567"
51
-
52
- // Invalid format returns original
53
- const invalid = dphelper.format.phoneNumber('123', 'US');
54
- // Output: "123"
55
- ```
56
-
57
- ### E-commerce Price Display
58
-
59
- ```javascript
60
- function formatProductPrice(product, locale = 'en-US', currency = 'USD') {
61
- return dphelper.format.currency(product.price, locale, currency);
62
- }
63
-
64
- const products = [
65
- { name: 'Laptop', price: 1299.99 },
66
- { name: 'Phone', price: 899.00 },
67
- { name: 'Tablet', price: 549.50 },
68
- { name: 'Headphones', price: 199.99 }
69
- ];
70
-
71
- products.forEach(p => {
72
- console.log(`${p.name}: ${formatProductPrice(p)}`);
73
- });
74
- // Laptop: $1,299.99
75
- // Phone: $899.00
76
- // Tablet: $549.50
77
- // Headphones: $199.99
78
- ```
79
-
80
- ### International Checkout
81
-
82
- ```javascript
83
- const locales = {
84
- US: { locale: 'en-US', currency: 'USD', symbol: '$' },
85
- DE: { locale: 'de-DE', currency: 'EUR', symbol: '€' },
86
- JP: { locale: 'ja-JPY', currency: 'JPY', symbol: '¥' },
87
- GB: { locale: 'en-GB', currency: 'GBP', symbol: '£' },
88
- IT: { locale: 'it-IT', currency: 'EUR', symbol: '€' }
89
- };
90
-
91
- function formatByRegion(region, amount) {
92
- const config = locales[region];
93
- if (!config) return amount;
94
- return dphelper.format.currency(amount, config.locale, config.currency);
95
- }
96
-
97
- // Format total cart for different regions
98
- const cart = [
99
- { item: 'Product A', price: 100 },
100
- { item: 'Product B', price: 50 },
101
- { item: 'Shipping', price: 10 }
102
- ];
103
-
104
- const total = cart.reduce((sum, item) => sum + item.price, 0);
105
-
106
- console.log('US Total:', formatByRegion('US', total)); // $160.00
107
- console.log('DE Total:', formatByRegion('DE', total)); // 160,00 €
108
- console.log('JP Total:', formatByRegion('JP', total)); // ¥160
109
- console.log('GB Total:', formatByRegion('GB', total)); // £160.00
110
- ```
111
-
112
- ## Details
113
-
114
- - **Author:** Dario Passariello
115
- - **Version:** 0.0.2
116
- - **Creation Date:** 20210101
117
- - **Last Modified:** 20260220
118
- - **Environment:** both (browser + Node.js)
119
-
120
- ---
121
-
122
- *Automatically generated document*