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.
Files changed (63) hide show
  1. package/README.md +0 -21
  2. package/docs/README.md +385 -0
  3. package/docs/SUMMARY.md +83 -0
  4. package/docs/_config.yml +1 -0
  5. package/docs/markdown/ai.md +345 -0
  6. package/docs/markdown/anchor.md +156 -0
  7. package/docs/markdown/array.md +208 -0
  8. package/docs/markdown/audio.md +113 -0
  9. package/docs/markdown/avoid.md +53 -0
  10. package/docs/markdown/biometric.md +338 -0
  11. package/docs/markdown/browser.md +203 -0
  12. package/docs/markdown/check.md +65 -0
  13. package/docs/markdown/color.md +159 -0
  14. package/docs/markdown/compress.md +310 -0
  15. package/docs/markdown/cookie.md +115 -0
  16. package/docs/markdown/coords.md +127 -0
  17. package/docs/markdown/credits.md +56 -0
  18. package/docs/markdown/date.md +260 -0
  19. package/docs/markdown/disable.md +109 -0
  20. package/docs/markdown/dispatch.md +108 -0
  21. package/docs/markdown/element.md +53 -0
  22. package/docs/markdown/event.md +85 -0
  23. package/docs/markdown/fetch.md +122 -0
  24. package/docs/markdown/form.md +302 -0
  25. package/docs/markdown/format.md +122 -0
  26. package/docs/markdown/i18n.md +292 -0
  27. package/docs/markdown/image.md +298 -0
  28. package/docs/markdown/json.md +269 -0
  29. package/docs/markdown/load.md +133 -0
  30. package/docs/markdown/logging.md +99 -0
  31. package/docs/markdown/math.md +172 -0
  32. package/docs/markdown/memory.md +85 -0
  33. package/docs/markdown/navigation.md +152 -0
  34. package/docs/markdown/net.md +60 -0
  35. package/docs/markdown/obj.md +242 -0
  36. package/docs/markdown/path.md +46 -0
  37. package/docs/markdown/promise.md +94 -0
  38. package/docs/markdown/sanitize.md +118 -0
  39. package/docs/markdown/screen.md +78 -0
  40. package/docs/markdown/scrollbar.md +82 -0
  41. package/docs/markdown/security.md +289 -0
  42. package/docs/markdown/shortcut.md +100 -0
  43. package/docs/markdown/socket.md +134 -0
  44. package/docs/markdown/sse.md +120 -0
  45. package/docs/markdown/svg.md +167 -0
  46. package/docs/markdown/sync.md +147 -0
  47. package/docs/markdown/system.md +78 -0
  48. package/docs/markdown/terminal.md +73 -0
  49. package/docs/markdown/text.md +245 -0
  50. package/docs/markdown/timer.md +98 -0
  51. package/docs/markdown/tools.md +111 -0
  52. package/docs/markdown/translators.md +65 -0
  53. package/docs/markdown/trigger.md +99 -0
  54. package/docs/markdown/triggers.md +133 -0
  55. package/docs/markdown/type.md +109 -0
  56. package/docs/markdown/types.md +102 -0
  57. package/docs/markdown/ui.md +45 -0
  58. package/docs/markdown/window.md +211 -0
  59. package/docs/markdown/worker.md +223 -0
  60. package/index.cjs +1 -1
  61. package/index.js +1 -1
  62. package/package.json +4 -6
  63. package/types/dphelper.d.ts +0 -15
@@ -0,0 +1,53 @@
1
+ # element
2
+
3
+ Element manipulation utilities for scaling and responsive design.
4
+
5
+ ## Functions
6
+
7
+ | Function | Description | Example |
8
+ |----------|-------------|---------|
9
+ | `fitScale` | Scale element based on window size | `dphelper.element.fitScale('#container', 1, true)` |
10
+ | `scaleBasedOnWindow` | Scale element to fit window | `dphelper.element.scaleBasedOnWindow('#chart', 1, false)` |
11
+
12
+ ## Description
13
+
14
+ Element scaling and responsive utilities:
15
+ - **Auto Scaling** - Scale elements with window resize
16
+ - **Fit to Window** - Scale to fit or fill viewport
17
+ - **Responsive** - Maintain aspect ratio
18
+
19
+ ## Usage Examples
20
+
21
+ ### Scale Element
22
+
23
+ ```javascript
24
+ // Basic scaling
25
+ dphelper.element.fitScale('#myElement', 1);
26
+
27
+ // Scale to fit window
28
+ dphelper.element.fitScale('#chart', 1, true);
29
+
30
+ // Custom scale
31
+ dphelper.element.fitScale('#preview', 0.5);
32
+ ```
33
+
34
+ ### Responsive Charts
35
+
36
+ ```javascript
37
+ // Make chart responsive
38
+ dphelper.element.fitScale('#chart-container', 1, true);
39
+
40
+ // Element scales automatically on window resize
41
+ ```
42
+
43
+ ## Details
44
+
45
+ - **Author:** Dario Passariello
46
+ - **Version:** 0.0.2
47
+ - **Creation Date:** 20230527
48
+ - **Last Modified:** 20230527
49
+ - **Environment:** Client-side only (browser)
50
+
51
+ ---
52
+
53
+ *Automatically generated document*
@@ -0,0 +1,85 @@
1
+ # event
2
+
3
+ Event handling utilities for DOM events, drag, and keyboard.
4
+
5
+ ## Functions
6
+
7
+ | Function | Description | Example |
8
+ |----------|-------------|---------|
9
+ | `list` | Show attached event listeners | `dphelper.event.list(element)` |
10
+ | `multi` | Attach multiple events | `dphelper.event.multi(element, 'click hover', handler)` |
11
+ | `copy` | Click copy element text | to `dphelper.event.copy('#element')` |
12
+ | `onDrag` | Handle element dragging | `dphelper.event.onDrag('.popup')` |
13
+ | `keys` | Get keyboard event properties | `dphelper.event.keys(e)` |
14
+
15
+ ## Description
16
+
17
+ Complete event utilities:
18
+ - **Multi Events** - Attach multiple events at once
19
+ - **Drag** - Drag and drop handling
20
+ - **Copy** - Click to copy to clipboard
21
+ - **Keyboard** - Key event properties
22
+
23
+ ## Usage Examples
24
+
25
+ ### Multiple Event Listeners
26
+
27
+ ```javascript
28
+ // Attach multiple events
29
+ dphelper.event.multi(
30
+ document.querySelector('#button'),
31
+ 'click hover focus',
32
+ (e) => console.log(e.type)
33
+ );
34
+ ```
35
+
36
+ ### Copy to Clipboard
37
+
38
+ ```javascript
39
+ // Click element to copy its text
40
+ dphelper.event.copy('#text-to-copy');
41
+
42
+ // User clicks, text is copied to clipboard
43
+ ```
44
+
45
+ ### Keyboard Events
46
+
47
+ ```javascript
48
+ // Get keyboard event properties
49
+ document.addEventListener('keydown', (e) => {
50
+ const keys = dphelper.event.keys(e);
51
+
52
+ console.log(keys.key); // 'a', 'Enter', 'Escape'
53
+ console.log(keys.ctrl); // true/false
54
+ console.log(keys.alt); // true/false
55
+ console.log(keys.shift); // true/false
56
+
57
+ // Check for shortcuts
58
+ if (keys.ctrl && keys.key === 's') {
59
+ e.preventDefault();
60
+ save();
61
+ }
62
+ });
63
+ ```
64
+
65
+ ### Drag and Drop
66
+
67
+ ```javascript
68
+ // Enable dragging
69
+ dphelper.event.onDrag('.draggable-popup');
70
+
71
+ // Element can now be dragged
72
+ // Position saved to localStorage
73
+ ```
74
+
75
+ ## Details
76
+
77
+ - **Author:** Dario Passariello
78
+ - **Version:** 0.0.2
79
+ - **Creation Date:** 20210101
80
+ - **Last Modified:** 20260220
81
+ - **Environment:** Client-side only (browser)
82
+
83
+ ---
84
+
85
+ *Automatically generated document*
@@ -0,0 +1,122 @@
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*
@@ -0,0 +1,302 @@
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*
@@ -0,0 +1,122 @@
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*