@osimatic/helpers-js 1.4.24 → 1.4.26

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 (68) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/chartjs.js +1 -1
  3. package/date_time.js +25 -16
  4. package/draw.js +3 -2
  5. package/duration.js +176 -130
  6. package/event_bus.js +2 -2
  7. package/file.js +20 -5
  8. package/form_helper.js +1 -1
  9. package/google_charts.js +2 -1
  10. package/http_client.js +2 -0
  11. package/jwt.js +18 -6
  12. package/location.js +5 -1
  13. package/media.js +7 -7
  14. package/multi_files_input.js +3 -1
  15. package/number.js +2 -3
  16. package/package.json +4 -2
  17. package/paging.js +2 -2
  18. package/social_network.js +5 -0
  19. package/string.js +11 -2
  20. package/tests/__mocks__/socket.io-client.js +13 -0
  21. package/tests/chartjs.test.js +273 -0
  22. package/tests/count_down.test.js +580 -0
  23. package/tests/date_time/DatePeriod.test.js +179 -0
  24. package/tests/date_time/DateTime.test.js +492 -0
  25. package/tests/date_time/SqlDate.test.js +205 -0
  26. package/tests/date_time/SqlDateTime.test.js +326 -0
  27. package/tests/date_time/SqlTime.test.js +162 -0
  28. package/tests/date_time/TimestampUnix.test.js +262 -0
  29. package/tests/details_sub_array.test.js +367 -0
  30. package/tests/draw.test.js +271 -0
  31. package/tests/duration.test.js +365 -0
  32. package/tests/event_bus.test.js +268 -0
  33. package/tests/file.test.js +568 -0
  34. package/tests/flash_message.test.js +297 -0
  35. package/tests/form_date.test.js +1559 -0
  36. package/tests/form_helper.test.js +1065 -0
  37. package/tests/google_charts.test.js +768 -0
  38. package/tests/google_maps.test.js +655 -0
  39. package/tests/google_recaptcha.test.js +441 -0
  40. package/tests/http_client.test.js +570 -0
  41. package/tests/import_from_csv.test.js +797 -0
  42. package/tests/jwt.test.js +804 -0
  43. package/tests/list_box.test.js +255 -0
  44. package/tests/location.test.js +86 -0
  45. package/tests/media.test.js +473 -0
  46. package/tests/multi_files_input.test.js +1015 -0
  47. package/tests/multiple_action_in_table.test.js +477 -0
  48. package/tests/network.test.js +489 -0
  49. package/tests/number.test.js +448 -0
  50. package/tests/open_street_map.test.js +388 -0
  51. package/tests/paging.test.js +646 -0
  52. package/tests/select_all.test.js +360 -0
  53. package/tests/shopping_cart.test.js +355 -0
  54. package/tests/social_network.test.js +333 -0
  55. package/tests/sortable_list.test.js +602 -0
  56. package/tests/string.test.js +489 -0
  57. package/tests/user.test.js +204 -0
  58. package/tests/util.test.js +99 -0
  59. package/tests/visitor.test.js +508 -0
  60. package/tests/web_rtc.test.js +458 -0
  61. package/tests/web_socket.test.js +538 -0
  62. package/visitor.js +2 -2
  63. package/tmpclaude-0fa4-cwd +0 -1
  64. package/tmpclaude-104f-cwd +0 -1
  65. package/tmpclaude-1468-cwd +0 -1
  66. package/tmpclaude-324b-cwd +0 -1
  67. package/tmpclaude-35d3-cwd +0 -1
  68. package/tmpclaude-4aa8-cwd +0 -1
@@ -0,0 +1,448 @@
1
+ require('../number');
2
+
3
+ describe('NumberFormatter', () => {
4
+ const { NumberFormatter } = require('../number');
5
+
6
+ describe('getDecimalFormatter', () => {
7
+ test('should create and cache decimal formatter', () => {
8
+ const formatter1 = NumberFormatter.getDecimalFormatter('fr-FR', 2);
9
+ const formatter2 = NumberFormatter.getDecimalFormatter('fr-FR', 2);
10
+ expect(formatter1).toBe(formatter2); // Should return cached instance
11
+ expect(formatter1).toBeInstanceOf(Intl.NumberFormat);
12
+ });
13
+
14
+ test('should create different formatters for different locales', () => {
15
+ const formatterFr = NumberFormatter.getDecimalFormatter('fr-FR', 2);
16
+ const formatterEn = NumberFormatter.getDecimalFormatter('en-US', 2);
17
+ expect(formatterFr).not.toBe(formatterEn);
18
+ });
19
+
20
+ test('should create different formatters for different digits', () => {
21
+ const formatter2 = NumberFormatter.getDecimalFormatter('fr-FR', 2);
22
+ const formatter3 = NumberFormatter.getDecimalFormatter('fr-FR', 3);
23
+ expect(formatter2).not.toBe(formatter3);
24
+ });
25
+ });
26
+
27
+ describe('getCurrencyFormatter', () => {
28
+ test('should create and cache currency formatter', () => {
29
+ const formatter1 = NumberFormatter.getCurrencyFormatter('fr-FR', 'EUR', 2);
30
+ const formatter2 = NumberFormatter.getCurrencyFormatter('fr-FR', 'EUR', 2);
31
+ expect(formatter1).toBe(formatter2); // Should return cached instance
32
+ expect(formatter1).toBeInstanceOf(Intl.NumberFormat);
33
+ });
34
+
35
+ test('should create different formatters for different currencies', () => {
36
+ const formatterEur = NumberFormatter.getCurrencyFormatter('fr-FR', 'EUR', 2);
37
+ const formatterUsd = NumberFormatter.getCurrencyFormatter('fr-FR', 'USD', 2);
38
+ expect(formatterEur).not.toBe(formatterUsd);
39
+ });
40
+
41
+ test('should create different formatters for different locales', () => {
42
+ const formatterFr = NumberFormatter.getCurrencyFormatter('fr-FR', 'EUR', 2);
43
+ const formatterEn = NumberFormatter.getCurrencyFormatter('en-US', 'EUR', 2);
44
+ expect(formatterFr).not.toBe(formatterEn);
45
+ });
46
+ });
47
+
48
+ describe('getPercentFormatter', () => {
49
+ test('should create and cache percent formatter', () => {
50
+ const formatter1 = NumberFormatter.getPercentFormatter('fr-FR', 2);
51
+ const formatter2 = NumberFormatter.getPercentFormatter('fr-FR', 2);
52
+ expect(formatter1).toBe(formatter2); // Should return cached instance
53
+ expect(formatter1).toBeInstanceOf(Intl.NumberFormat);
54
+ });
55
+
56
+ test('should create different formatters for different locales', () => {
57
+ const formatterFr = NumberFormatter.getPercentFormatter('fr-FR', 2);
58
+ const formatterEn = NumberFormatter.getPercentFormatter('en-US', 2);
59
+ expect(formatterFr).not.toBe(formatterEn);
60
+ });
61
+
62
+ test('should create different formatters for different digits', () => {
63
+ const formatter2 = NumberFormatter.getPercentFormatter('fr-FR', 2);
64
+ const formatter3 = NumberFormatter.getPercentFormatter('fr-FR', 3);
65
+ expect(formatter2).not.toBe(formatter3);
66
+ });
67
+ });
68
+ });
69
+
70
+ describe('Number formatting methods', () => {
71
+ describe('Number.prototype.format', () => {
72
+ test('should format number with default parameters', () => {
73
+ const result = (1234.567).format();
74
+ expect(result).toContain('1');
75
+ expect(result).toContain('234');
76
+ expect(result).toContain('57');
77
+ });
78
+
79
+ test('should format number with custom decimals', () => {
80
+ const result = (1234.567).format(3);
81
+ expect(result).toContain('567');
82
+ });
83
+
84
+ test('should format number with en-US locale', () => {
85
+ const result = (1234.567).format(2, 'en-US');
86
+ expect(result).toContain('1,234');
87
+ expect(result).toContain('57');
88
+ });
89
+
90
+ test('should format zero', () => {
91
+ const result = (0).format(2);
92
+ expect(result).toBeTruthy();
93
+ });
94
+
95
+ test('should format negative numbers', () => {
96
+ const result = (-1234.567).format(2);
97
+ expect(result).toContain('1');
98
+ expect(result).toContain('234');
99
+ });
100
+ });
101
+
102
+ describe('Number.format', () => {
103
+ test('should format number as static method', () => {
104
+ const result = Number.format(1234.567, 2, 'fr-FR');
105
+ expect(result).toContain('1');
106
+ expect(result).toContain('234');
107
+ });
108
+
109
+ test('should format with default parameters', () => {
110
+ const result = Number.format(1234.567);
111
+ expect(result).toContain('234');
112
+ });
113
+
114
+ test('should format integer', () => {
115
+ const result = Number.format(1234, 0);
116
+ expect(result).toContain('1');
117
+ });
118
+ });
119
+
120
+ describe('Number.prototype.formatCurrency', () => {
121
+ test('should format currency with EUR', () => {
122
+ const result = (1234.56).formatCurrency('EUR');
123
+ expect(result).toContain('1');
124
+ expect(result).toContain('234');
125
+ expect(result).toContain('56');
126
+ expect(result).toContain('€');
127
+ });
128
+
129
+ test('should format currency with USD', () => {
130
+ const result = (1234.56).formatCurrency('USD', 2, 'en-US');
131
+ expect(result).toContain('$');
132
+ expect(result).toContain('1,234');
133
+ });
134
+
135
+ test('should format zero currency', () => {
136
+ const result = (0).formatCurrency('EUR');
137
+ expect(result).toContain('0');
138
+ });
139
+
140
+ test('should format negative currency', () => {
141
+ const result = (-1234.56).formatCurrency('EUR');
142
+ expect(result).toContain('1');
143
+ expect(result).toContain('234');
144
+ });
145
+
146
+ test('should format with custom decimals', () => {
147
+ const result = (1234.567).formatCurrency('EUR', 3);
148
+ expect(result).toContain('567');
149
+ });
150
+ });
151
+
152
+ describe('Number.formatCurrency', () => {
153
+ test('should format currency as static method', () => {
154
+ const result = Number.formatCurrency(1234.56, 'EUR', 2, 'fr-FR');
155
+ expect(result).toContain('1');
156
+ expect(result).toContain('234');
157
+ expect(result).toContain('€');
158
+ });
159
+
160
+ test('should format with different currencies', () => {
161
+ const resultEur = Number.formatCurrency(100, 'EUR');
162
+ const resultUsd = Number.formatCurrency(100, 'USD');
163
+ expect(resultEur).not.toBe(resultUsd);
164
+ });
165
+ });
166
+
167
+ describe('Number.prototype.formatPercent', () => {
168
+ test('should format percent', () => {
169
+ const result = (0.1234).formatPercent();
170
+ expect(result).toContain('12');
171
+ expect(result).toContain('%');
172
+ });
173
+
174
+ test('should format percent with custom decimals', () => {
175
+ const result = (0.1234).formatPercent(3);
176
+ expect(result).toContain('%');
177
+ });
178
+
179
+ test('should format 100%', () => {
180
+ const result = (1).formatPercent(0);
181
+ expect(result).toContain('100');
182
+ expect(result).toContain('%');
183
+ });
184
+
185
+ test('should format zero percent', () => {
186
+ const result = (0).formatPercent();
187
+ expect(result).toContain('0');
188
+ expect(result).toContain('%');
189
+ });
190
+
191
+ test('should format with different locales', () => {
192
+ const resultFr = (0.1234).formatPercent(2, 'fr-FR');
193
+ const resultEn = (0.1234).formatPercent(2, 'en-US');
194
+ expect(resultFr).toContain('%');
195
+ expect(resultEn).toContain('%');
196
+ });
197
+ });
198
+
199
+ describe('Number.formatPercent', () => {
200
+ test('should format percent as static method', () => {
201
+ const result = Number.formatPercent(0.1234, 2, 'fr-FR');
202
+ expect(result).toContain('%');
203
+ });
204
+
205
+ test('should format percentage values', () => {
206
+ const result = Number.formatPercent(0.5, 0);
207
+ expect(result).toContain('50');
208
+ });
209
+ });
210
+
211
+ describe('Number.prototype.formatForDisplay', () => {
212
+ test('should format with default parameters (3 digit groups)', () => {
213
+ const result = (1234567.89).formatForDisplay(2, ' ', ',');
214
+ expect(result).toBe('1 234 567,89');
215
+ });
216
+
217
+ test('should format with no decimals', () => {
218
+ const result = (1234567).formatForDisplay(0, ' ', ',');
219
+ expect(result).toBe('1 234 567');
220
+ });
221
+
222
+ test('should format with custom section length', () => {
223
+ const result = (12345678).formatForDisplay(0, '-', ',', 4);
224
+ expect(result).toBe('1234-5678');
225
+ });
226
+
227
+ test('should format small numbers', () => {
228
+ const result = (123.45).formatForDisplay(2, ' ', ',');
229
+ expect(result).toBe('123,45');
230
+ });
231
+
232
+ test('should handle negative numbers', () => {
233
+ const result = (-1234.56).formatForDisplay(2, ' ', ',');
234
+ expect(result).toContain('1 234');
235
+ expect(result).toContain('56');
236
+ });
237
+
238
+ test('should format with default decimal separator (dot)', () => {
239
+ const result = (1234.56).formatForDisplay(2, ' ');
240
+ expect(result).toBe('1 234.56');
241
+ });
242
+
243
+ test('should handle zero', () => {
244
+ const result = (0).formatForDisplay(2, ' ', ',');
245
+ expect(result).toBe('0,00');
246
+ });
247
+ });
248
+
249
+ describe('Number.prototype.truncate', () => {
250
+ test('should truncate positive decimal numbers', () => {
251
+ expect((3.7).truncate()).toBe(3);
252
+ expect((3.2).truncate()).toBe(3);
253
+ });
254
+
255
+ test('should truncate negative decimal numbers', () => {
256
+ expect((-3.7).truncate()).toBe(-3);
257
+ expect((-3.2).truncate()).toBe(-3);
258
+ });
259
+
260
+ test('should handle integer numbers', () => {
261
+ expect((5).truncate()).toBe(5);
262
+ expect((-5).truncate()).toBe(-5);
263
+ });
264
+
265
+ test('should handle zero', () => {
266
+ expect((0).truncate()).toBe(0);
267
+ });
268
+
269
+ test('should truncate large decimals', () => {
270
+ expect((123.999).truncate()).toBe(123);
271
+ expect((-123.999).truncate()).toBe(-123);
272
+ });
273
+ });
274
+
275
+ describe('Number.prototype.padLeft2', () => {
276
+ test('should pad single digit numbers', () => {
277
+ expect((0).padLeft2()).toBe('00');
278
+ expect((1).padLeft2()).toBe('01');
279
+ expect((5).padLeft2()).toBe('05');
280
+ expect((9).padLeft2()).toBe('09');
281
+ });
282
+
283
+ test('should not pad double digit numbers', () => {
284
+ expect((10).padLeft2()).toBe('10');
285
+ expect((99).padLeft2()).toBe('99');
286
+ expect((50).padLeft2()).toBe('50');
287
+ });
288
+
289
+ test('should not pad numbers greater than 99', () => {
290
+ expect((100).padLeft2()).toBe('100');
291
+ expect((999).padLeft2()).toBe('999');
292
+ });
293
+ });
294
+
295
+ describe('Number.padLeft2', () => {
296
+ test('should pad single digit numbers as static method', () => {
297
+ expect(Number.padLeft2(0)).toBe('00');
298
+ expect(Number.padLeft2(5)).toBe('05');
299
+ expect(Number.padLeft2(9)).toBe('09');
300
+ });
301
+
302
+ test('should not pad double digit numbers', () => {
303
+ expect(Number.padLeft2(10)).toBe('10');
304
+ expect(Number.padLeft2(99)).toBe('99');
305
+ });
306
+
307
+ test('should handle large numbers', () => {
308
+ expect(Number.padLeft2(100)).toBe('100');
309
+ });
310
+ });
311
+
312
+ describe('Number.prototype.roundDecimal', () => {
313
+ test('should round to 2 decimals by default', () => {
314
+ expect((1.234).roundDecimal()).toBe(1.23);
315
+ expect((1.235).roundDecimal()).toBe(1.24);
316
+ expect((1.236).roundDecimal()).toBe(1.24);
317
+ });
318
+
319
+ test('should round to custom precision', () => {
320
+ expect((1.234).roundDecimal(1)).toBe(1.2);
321
+ expect((1.235).roundDecimal(1)).toBe(1.2);
322
+ expect((1.236).roundDecimal(1)).toBe(1.2);
323
+ });
324
+
325
+ test('should round to 3 decimals', () => {
326
+ expect((1.2345).roundDecimal(3)).toBe(1.235);
327
+ expect((1.2344).roundDecimal(3)).toBe(1.234);
328
+ });
329
+
330
+ test('should round negative numbers', () => {
331
+ expect((-1.235).roundDecimal(2)).toBe(-1.24);
332
+ expect((-1.234).roundDecimal(2)).toBe(-1.23);
333
+ });
334
+
335
+ test('should round to 0 decimals', () => {
336
+ expect((1.5).roundDecimal(0)).toBe(2);
337
+ expect((1.4).roundDecimal(0)).toBe(1);
338
+ });
339
+
340
+ test('should handle integers', () => {
341
+ expect((5).roundDecimal(2)).toBe(5);
342
+ });
343
+
344
+ test('should handle zero', () => {
345
+ expect((0).roundDecimal(2)).toBe(0);
346
+ });
347
+ });
348
+
349
+ describe('Number.roundDecimal', () => {
350
+ test('should round as static method', () => {
351
+ expect(Number.roundDecimal(1.234, 2)).toBe(1.23);
352
+ expect(Number.roundDecimal(1.235, 2)).toBe(1.24);
353
+ });
354
+
355
+ test('should use default precision of 2', () => {
356
+ expect(Number.roundDecimal(1.2345)).toBe(1.23);
357
+ });
358
+
359
+ test('should round with different precisions', () => {
360
+ expect(Number.roundDecimal(1.2345, 1)).toBe(1.2);
361
+ expect(Number.roundDecimal(1.2345, 3)).toBe(1.235);
362
+ });
363
+ });
364
+ });
365
+
366
+ describe('Math.getDecimals', () => {
367
+ test('should extract decimal part', () => {
368
+ expect(Math.getDecimals(1.5)).toBe(5);
369
+ expect(Math.getDecimals(1.234)).toBe(234);
370
+ expect(Math.getDecimals(3.14159)).toBe(14159);
371
+ });
372
+
373
+ test('should return 0 for integers', () => {
374
+ expect(Math.getDecimals(5)).toBe(0);
375
+ expect(Math.getDecimals(100)).toBe(0);
376
+ });
377
+
378
+ test('should handle zero', () => {
379
+ expect(Math.getDecimals(0)).toBe(0);
380
+ });
381
+
382
+ test('should handle negative numbers', () => {
383
+ expect(Math.getDecimals(-1.5)).toBe(5);
384
+ expect(Math.getDecimals(-3.14)).toBe(14);
385
+ });
386
+
387
+ test('should handle numbers with single decimal', () => {
388
+ expect(Math.getDecimals(1.0)).toBe(0);
389
+ expect(Math.getDecimals(1.1)).toBe(1);
390
+ });
391
+
392
+ test('should handle very small decimals', () => {
393
+ expect(Math.getDecimals(0.001)).toBe(1);
394
+ expect(Math.getDecimals(0.01)).toBe(1);
395
+ expect(Math.getDecimals(0.1)).toBe(1);
396
+ });
397
+ });
398
+
399
+ describe('Number.random', () => {
400
+ test('should generate number within range', () => {
401
+ for (let i = 0; i < 100; i++) {
402
+ const result = Number.random(1, 10);
403
+ expect(result).toBeGreaterThanOrEqual(1);
404
+ expect(result).toBeLessThanOrEqual(10);
405
+ }
406
+ });
407
+
408
+ test('should generate number in range [0, 0]', () => {
409
+ expect(Number.random(0, 0)).toBe(0);
410
+ });
411
+
412
+ test('should generate number in range [5, 5]', () => {
413
+ expect(Number.random(5, 5)).toBe(5);
414
+ });
415
+
416
+ test('should generate numbers in range [1, 2]', () => {
417
+ const results = new Set();
418
+ for (let i = 0; i < 50; i++) {
419
+ results.add(Number.random(1, 2));
420
+ }
421
+ expect(results.has(1) || results.has(2)).toBe(true);
422
+ expect(results.size).toBeGreaterThanOrEqual(1);
423
+ expect(results.size).toBeLessThanOrEqual(2);
424
+ });
425
+
426
+ test('should generate integers only', () => {
427
+ for (let i = 0; i < 50; i++) {
428
+ const result = Number.random(1, 10);
429
+ expect(result).toBe(Math.floor(result));
430
+ }
431
+ });
432
+
433
+ test('should handle negative ranges', () => {
434
+ for (let i = 0; i < 50; i++) {
435
+ const result = Number.random(-10, -1);
436
+ expect(result).toBeGreaterThanOrEqual(-10);
437
+ expect(result).toBeLessThanOrEqual(-1);
438
+ }
439
+ });
440
+
441
+ test('should handle range crossing zero', () => {
442
+ for (let i = 0; i < 50; i++) {
443
+ const result = Number.random(-5, 5);
444
+ expect(result).toBeGreaterThanOrEqual(-5);
445
+ expect(result).toBeLessThanOrEqual(5);
446
+ }
447
+ });
448
+ });