@lokalise/node-core 9.15.0 → 9.16.1

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 (40) hide show
  1. package/dist/src/logging/commonLogger.d.ts +13 -0
  2. package/package.json +1 -1
  3. package/dist/src/config/ConfigScope.spec.d.ts +0 -1
  4. package/dist/src/config/ConfigScope.spec.js +0 -587
  5. package/dist/src/config/ConfigScope.spec.js.map +0 -1
  6. package/dist/src/config/configTransformers.spec.d.ts +0 -1
  7. package/dist/src/config/configTransformers.spec.js +0 -28
  8. package/dist/src/config/configTransformers.spec.js.map +0 -1
  9. package/dist/src/errors/PublicNonRecoverableError.spec.d.ts +0 -1
  10. package/dist/src/errors/PublicNonRecoverableError.spec.js +0 -13
  11. package/dist/src/errors/PublicNonRecoverableError.spec.js.map +0 -1
  12. package/dist/src/errors/errorTypeGuards.spec.d.ts +0 -1
  13. package/dist/src/errors/errorTypeGuards.spec.js +0 -23
  14. package/dist/src/errors/errorTypeGuards.spec.js.map +0 -1
  15. package/dist/src/errors/globalErrorHandler.spec.d.ts +0 -1
  16. package/dist/src/errors/globalErrorHandler.spec.js +0 -30
  17. package/dist/src/errors/globalErrorHandler.spec.js.map +0 -1
  18. package/dist/src/http/httpClient.spec.d.ts +0 -1
  19. package/dist/src/http/httpClient.spec.js +0 -777
  20. package/dist/src/http/httpClient.spec.js.map +0 -1
  21. package/dist/src/http/mock-data/mockProduct1.json +0 -12
  22. package/dist/src/http/mock-data/mockProductsLimit3.json +0 -38
  23. package/dist/src/logging/loggerConfigResolver.spec.d.ts +0 -1
  24. package/dist/src/logging/loggerConfigResolver.spec.js +0 -34
  25. package/dist/src/logging/loggerConfigResolver.spec.js.map +0 -1
  26. package/dist/src/utils/arrayUtils.spec.d.ts +0 -1
  27. package/dist/src/utils/arrayUtils.spec.js +0 -60
  28. package/dist/src/utils/arrayUtils.spec.js.map +0 -1
  29. package/dist/src/utils/objectUtils.spec.d.ts +0 -1
  30. package/dist/src/utils/objectUtils.spec.js +0 -996
  31. package/dist/src/utils/objectUtils.spec.js.map +0 -1
  32. package/dist/src/utils/typeUtils.spec.d.ts +0 -1
  33. package/dist/src/utils/typeUtils.spec.js +0 -115
  34. package/dist/src/utils/typeUtils.spec.js.map +0 -1
  35. package/dist/src/utils/waitUtils.spec.d.ts +0 -1
  36. package/dist/src/utils/waitUtils.spec.js +0 -50
  37. package/dist/src/utils/waitUtils.spec.js.map +0 -1
  38. package/dist/vitest.config.d.mts +0 -2
  39. package/dist/vitest.config.mjs +0 -34
  40. package/dist/vitest.config.mjs.map +0 -1
@@ -1,996 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const objectUtils_1 = require("./objectUtils");
4
- describe('objectUtils', () => {
5
- describe('copyWithoutUndefined', () => {
6
- it('Does nothing when there are no undefined fields', () => {
7
- const result = (0, objectUtils_1.copyWithoutUndefined)({
8
- a: 'a',
9
- b: '',
10
- c: ' ',
11
- d: null,
12
- e: {},
13
- });
14
- expect(result).toMatchSnapshot();
15
- });
16
- it('Removes undefined fields', () => {
17
- const result = (0, objectUtils_1.copyWithoutUndefined)({
18
- a: undefined,
19
- b: 'a',
20
- c: '',
21
- d: undefined,
22
- e: ' ',
23
- f: null,
24
- g: {
25
- someParam: 12,
26
- },
27
- h: undefined,
28
- });
29
- const varWithNarrowedType = result;
30
- const bValue = varWithNarrowedType.b;
31
- const gValue = varWithNarrowedType.g;
32
- expect(bValue).toBe('a');
33
- expect(gValue).toEqual({
34
- someParam: 12,
35
- });
36
- expect(result).toMatchSnapshot();
37
- });
38
- });
39
- describe('copyWithoutEmpty', () => {
40
- it('Does nothing when there are no empty fields', () => {
41
- const result = (0, objectUtils_1.copyWithoutEmpty)({
42
- a: 'a',
43
- b: ' t ',
44
- c: ' tt',
45
- d: 'tt ',
46
- e: {},
47
- y: 88,
48
- z: 0,
49
- });
50
- expect(result).toMatchInlineSnapshot(`
51
- {
52
- "a": "a",
53
- "b": " t ",
54
- "c": " tt",
55
- "d": "tt ",
56
- "e": {},
57
- "y": 88,
58
- "z": 0,
59
- }
60
- `);
61
- });
62
- it('Removes empty fields', () => {
63
- const result = (0, objectUtils_1.copyWithoutEmpty)({
64
- a: undefined,
65
- b: 'a',
66
- c: '',
67
- d: undefined,
68
- e: ' ',
69
- f: null,
70
- g: {
71
- someParam: 12,
72
- },
73
- h: undefined,
74
- y: 88,
75
- z: 0,
76
- });
77
- const varWithNarrowedType = result;
78
- const bValue = varWithNarrowedType.b;
79
- const gValue = varWithNarrowedType.g;
80
- expect(bValue).toBe('a');
81
- expect(gValue).toEqual({
82
- someParam: 12,
83
- });
84
- expect(result).toMatchInlineSnapshot(`
85
- {
86
- "b": "a",
87
- "g": {
88
- "someParam": 12,
89
- },
90
- "y": 88,
91
- "z": 0,
92
- }
93
- `);
94
- });
95
- });
96
- describe('pick', () => {
97
- it('Picks specified fields', () => {
98
- const result = (0, objectUtils_1.pick)({
99
- a: 'a',
100
- b: '',
101
- c: ' ',
102
- d: null,
103
- e: {},
104
- }, ['a', 'c', 'e']);
105
- expect(result).toStrictEqual({ a: 'a', c: ' ', e: {} });
106
- });
107
- it('Ignores missing fields', () => {
108
- const result = (0, objectUtils_1.pick)({
109
- a: 'a',
110
- b: '',
111
- c: ' ',
112
- d: null,
113
- e: {},
114
- }, ['a', 'f', 'g']);
115
- expect(result).toStrictEqual({ a: 'a' });
116
- });
117
- it('Includes undefined fields', () => {
118
- const result = (0, objectUtils_1.pick)({
119
- a: 'a',
120
- b: undefined,
121
- c: {},
122
- }, ['a', 'b']);
123
- expect(result).toStrictEqual({ a: 'a', b: undefined });
124
- });
125
- });
126
- describe('pickWithoutUndefined', () => {
127
- it('Picks specified fields', () => {
128
- const result = (0, objectUtils_1.pickWithoutUndefined)({
129
- a: 'a',
130
- b: '',
131
- c: ' ',
132
- d: null,
133
- e: {},
134
- }, ['a', 'c', 'e']);
135
- expect(result).toMatchObject({ a: 'a', c: ' ', e: {} });
136
- });
137
- it('Ignores missing fields', () => {
138
- const result = (0, objectUtils_1.pickWithoutUndefined)({
139
- a: 'a',
140
- b: '',
141
- c: ' ',
142
- d: null,
143
- e: {},
144
- }, ['a', 'f', 'g']);
145
- expect(result).toStrictEqual({ a: 'a' });
146
- });
147
- it('Skips undefined fields', () => {
148
- const result = (0, objectUtils_1.pickWithoutUndefined)({
149
- a: 'a',
150
- b: undefined,
151
- c: {},
152
- }, ['a', 'b']);
153
- expect(result).toStrictEqual({ a: 'a' });
154
- });
155
- });
156
- describe('isEmptyObject', () => {
157
- it('Returns true for completely empty object', () => {
158
- const params = {};
159
- const result = (0, objectUtils_1.isEmptyObject)(params);
160
- expect(result).toBe(true);
161
- });
162
- it('Returns true for object with only undefined fields', () => {
163
- const params = { a: undefined };
164
- const result = (0, objectUtils_1.isEmptyObject)(params);
165
- expect(result).toBe(true);
166
- });
167
- it('Returns false for object with null', () => {
168
- const params = { a: null };
169
- const result = (0, objectUtils_1.isEmptyObject)(params);
170
- expect(result).toBe(false);
171
- });
172
- it('Returns false for non-empty object', () => {
173
- const params = { a: '' };
174
- const result = (0, objectUtils_1.isEmptyObject)(params);
175
- expect(result).toBe(false);
176
- });
177
- });
178
- describe('groupBy', () => {
179
- it('Empty array', () => {
180
- const array = [];
181
- const result = (0, objectUtils_1.groupBy)(array, 'id');
182
- expect(Object.keys(result)).length(0);
183
- });
184
- it('Correctly groups by string values', () => {
185
- const input = [
186
- {
187
- id: 1,
188
- name: 'a',
189
- bool: true,
190
- nested: { code: 100 },
191
- },
192
- {
193
- id: 2,
194
- name: 'c',
195
- bool: true,
196
- nested: { code: 200 },
197
- },
198
- {
199
- id: 3,
200
- name: 'b',
201
- bool: true,
202
- nested: { code: 300 },
203
- },
204
- {
205
- id: 4,
206
- name: 'a',
207
- bool: true,
208
- nested: { code: 400 },
209
- },
210
- ];
211
- const result = (0, objectUtils_1.groupBy)(input, 'name');
212
- expect(result).toStrictEqual({
213
- a: [
214
- {
215
- id: 1,
216
- name: 'a',
217
- bool: true,
218
- nested: { code: 100 },
219
- },
220
- {
221
- id: 4,
222
- name: 'a',
223
- bool: true,
224
- nested: { code: 400 },
225
- },
226
- ],
227
- b: [
228
- {
229
- id: 3,
230
- name: 'b',
231
- bool: true,
232
- nested: { code: 300 },
233
- },
234
- ],
235
- c: [
236
- {
237
- id: 2,
238
- name: 'c',
239
- bool: true,
240
- nested: { code: 200 },
241
- },
242
- ],
243
- });
244
- });
245
- it('Correctly groups by number values', () => {
246
- const input = [
247
- {
248
- id: 1,
249
- name: 'a',
250
- bool: true,
251
- },
252
- {
253
- id: 1,
254
- name: 'b',
255
- bool: false,
256
- },
257
- {
258
- id: 2,
259
- name: 'c',
260
- bool: false,
261
- },
262
- {
263
- id: 3,
264
- name: 'd',
265
- bool: false,
266
- },
267
- ];
268
- const result = (0, objectUtils_1.groupBy)(input, 'id');
269
- expect(result).toStrictEqual({
270
- 1: [
271
- {
272
- id: 1,
273
- name: 'a',
274
- bool: true,
275
- },
276
- {
277
- id: 1,
278
- name: 'b',
279
- bool: false,
280
- },
281
- ],
282
- 2: [
283
- {
284
- id: 2,
285
- name: 'c',
286
- bool: false,
287
- },
288
- ],
289
- 3: [
290
- {
291
- id: 3,
292
- name: 'd',
293
- bool: false,
294
- },
295
- ],
296
- });
297
- });
298
- it('Correctly handles undefined and null', () => {
299
- const input = [
300
- {
301
- id: 1,
302
- name: 'a',
303
- bool: true,
304
- },
305
- {
306
- name: 'c',
307
- bool: true,
308
- },
309
- {
310
- id: null,
311
- name: 'd',
312
- bool: true,
313
- },
314
- {
315
- id: 1,
316
- name: 'b',
317
- bool: true,
318
- },
319
- ];
320
- const result = (0, objectUtils_1.groupBy)(input, 'id');
321
- expect(result).toStrictEqual({
322
- 1: [
323
- {
324
- id: 1,
325
- name: 'a',
326
- bool: true,
327
- },
328
- {
329
- id: 1,
330
- name: 'b',
331
- bool: true,
332
- },
333
- ],
334
- });
335
- });
336
- });
337
- describe('groupByPath', () => {
338
- it('Empty array', () => {
339
- const array = [];
340
- const result = (0, objectUtils_1.groupByPath)(array, 'id.nestedId');
341
- expect(Object.keys(result)).length(0);
342
- });
343
- it('Correctly groups by string values', () => {
344
- const input = [
345
- {
346
- id: 1,
347
- name: 'a',
348
- bool: true,
349
- nested: { code: 100 },
350
- },
351
- {
352
- id: 2,
353
- name: 'c',
354
- bool: true,
355
- nested: { code: 200 },
356
- },
357
- {
358
- id: 3,
359
- name: 'b',
360
- bool: true,
361
- nested: { code: 300 },
362
- },
363
- {
364
- id: 4,
365
- name: 'a',
366
- bool: true,
367
- nested: { code: 400 },
368
- },
369
- ];
370
- const result = (0, objectUtils_1.groupByPath)(input, 'name');
371
- expect(result).toStrictEqual({
372
- a: [
373
- {
374
- id: 1,
375
- name: 'a',
376
- bool: true,
377
- nested: { code: 100 },
378
- },
379
- {
380
- id: 4,
381
- name: 'a',
382
- bool: true,
383
- nested: { code: 400 },
384
- },
385
- ],
386
- b: [
387
- {
388
- id: 3,
389
- name: 'b',
390
- bool: true,
391
- nested: { code: 300 },
392
- },
393
- ],
394
- c: [
395
- {
396
- id: 2,
397
- name: 'c',
398
- bool: true,
399
- nested: { code: 200 },
400
- },
401
- ],
402
- });
403
- });
404
- it('Correctly groups by nested string values', () => {
405
- const input = [
406
- {
407
- id: 1,
408
- name: 'a',
409
- bool: true,
410
- nested: { code: 100 },
411
- },
412
- {
413
- id: 2,
414
- name: 'c',
415
- bool: true,
416
- nested: { code: 200 },
417
- },
418
- {
419
- id: 3,
420
- name: 'b',
421
- bool: true,
422
- nested: { code: 300 },
423
- },
424
- {
425
- id: 4,
426
- name: 'a',
427
- bool: true,
428
- nested: { code: 100 },
429
- },
430
- ];
431
- const result = (0, objectUtils_1.groupByPath)(input, 'nested.code');
432
- expect(result).toStrictEqual({
433
- 100: [
434
- {
435
- id: 1,
436
- name: 'a',
437
- bool: true,
438
- nested: { code: 100 },
439
- },
440
- {
441
- id: 4,
442
- name: 'a',
443
- bool: true,
444
- nested: { code: 100 },
445
- },
446
- ],
447
- 300: [
448
- {
449
- id: 3,
450
- name: 'b',
451
- bool: true,
452
- nested: { code: 300 },
453
- },
454
- ],
455
- 200: [
456
- {
457
- id: 2,
458
- name: 'c',
459
- bool: true,
460
- nested: { code: 200 },
461
- },
462
- ],
463
- });
464
- });
465
- it('return empty record for nested array key', () => {
466
- const input = [
467
- {
468
- id: 1,
469
- name: 'a',
470
- bool: true,
471
- nested: [{ code: 100 }],
472
- },
473
- ];
474
- const result = (0, objectUtils_1.groupByPath)(input, 'nested.code');
475
- expect(result).toStrictEqual({});
476
- });
477
- it('Correctly groups by number values', () => {
478
- const input = [
479
- {
480
- id: 1,
481
- name: 'a',
482
- bool: true,
483
- },
484
- {
485
- id: 1,
486
- name: 'b',
487
- bool: false,
488
- },
489
- {
490
- id: 2,
491
- name: 'c',
492
- bool: false,
493
- },
494
- {
495
- id: 3,
496
- name: 'd',
497
- bool: false,
498
- },
499
- ];
500
- const result = (0, objectUtils_1.groupByPath)(input, 'id');
501
- expect(result).toStrictEqual({
502
- 1: [
503
- {
504
- id: 1,
505
- name: 'a',
506
- bool: true,
507
- },
508
- {
509
- id: 1,
510
- name: 'b',
511
- bool: false,
512
- },
513
- ],
514
- 2: [
515
- {
516
- id: 2,
517
- name: 'c',
518
- bool: false,
519
- },
520
- ],
521
- 3: [
522
- {
523
- id: 3,
524
- name: 'd',
525
- bool: false,
526
- },
527
- ],
528
- });
529
- });
530
- it('Correctly handles undefined and null', () => {
531
- const input = [
532
- {
533
- id: 1,
534
- name: 'a',
535
- bool: true,
536
- },
537
- {
538
- name: 'c',
539
- bool: true,
540
- },
541
- {
542
- id: null,
543
- name: 'd',
544
- bool: true,
545
- },
546
- {
547
- id: 1,
548
- name: 'b',
549
- bool: true,
550
- },
551
- ];
552
- const result = (0, objectUtils_1.groupByPath)(input, 'id');
553
- expect(result).toStrictEqual({
554
- 1: [
555
- {
556
- id: 1,
557
- name: 'a',
558
- bool: true,
559
- },
560
- {
561
- id: 1,
562
- name: 'b',
563
- bool: true,
564
- },
565
- ],
566
- });
567
- });
568
- });
569
- describe('groupByUnique', () => {
570
- it('Empty array', () => {
571
- const array = [];
572
- const result = (0, objectUtils_1.groupByUnique)(array, 'id');
573
- expect(Object.keys(result)).length(0);
574
- });
575
- it('Correctly groups by string values', () => {
576
- const input = [
577
- {
578
- id: 1,
579
- name: 'a',
580
- bool: true,
581
- nested: { code: 100 },
582
- },
583
- {
584
- id: 2,
585
- name: 'b',
586
- bool: true,
587
- nested: { code: 200 },
588
- },
589
- ];
590
- const result = (0, objectUtils_1.groupByUnique)(input, 'name');
591
- expect(result).toStrictEqual({
592
- a: {
593
- id: 1,
594
- name: 'a',
595
- bool: true,
596
- nested: { code: 100 },
597
- },
598
- b: {
599
- id: 2,
600
- name: 'b',
601
- bool: true,
602
- nested: { code: 200 },
603
- },
604
- });
605
- });
606
- it('Correctly groups by number values', () => {
607
- const input = [
608
- {
609
- id: 1,
610
- name: 'a',
611
- bool: true,
612
- nested: { code: 100 },
613
- },
614
- {
615
- id: 2,
616
- name: 'b',
617
- bool: true,
618
- nested: { code: 200 },
619
- },
620
- ];
621
- const result = (0, objectUtils_1.groupByUnique)(input, 'id');
622
- expect(result).toStrictEqual({
623
- 1: {
624
- id: 1,
625
- name: 'a',
626
- bool: true,
627
- nested: { code: 100 },
628
- },
629
- 2: {
630
- id: 2,
631
- name: 'b',
632
- bool: true,
633
- nested: { code: 200 },
634
- },
635
- });
636
- });
637
- it('Correctly handles undefined', () => {
638
- const input = [
639
- {
640
- id: 1,
641
- name: 'name',
642
- bool: true,
643
- nested: { code: 100 },
644
- },
645
- {
646
- name: 'invalid',
647
- bool: true,
648
- nested: { code: 100 },
649
- },
650
- {
651
- id: 3,
652
- name: 'name 2',
653
- bool: true,
654
- nested: { code: 100 },
655
- },
656
- ];
657
- const result = (0, objectUtils_1.groupByUnique)(input, 'id');
658
- expect(result).toStrictEqual({
659
- 1: {
660
- id: 1,
661
- name: 'name',
662
- bool: true,
663
- nested: { code: 100 },
664
- },
665
- 3: {
666
- id: 3,
667
- name: 'name 2',
668
- bool: true,
669
- nested: { code: 100 },
670
- },
671
- });
672
- });
673
- it('throws on duplicated value', () => {
674
- const input = [
675
- {
676
- id: 1,
677
- name: 'test',
678
- },
679
- {
680
- id: 2,
681
- name: 'work',
682
- },
683
- {
684
- id: 3,
685
- name: 'test',
686
- },
687
- ];
688
- expect(() => (0, objectUtils_1.groupByUnique)(input, 'name')).toThrowError('Duplicated item for selector name with value test');
689
- });
690
- });
691
- describe('convertDateFieldsToIsoString', () => {
692
- it('Empty object', () => {
693
- expect((0, objectUtils_1.convertDateFieldsToIsoString)({})).toStrictEqual({});
694
- });
695
- it('simple object', () => {
696
- const date = new Date();
697
- const input = {
698
- id: 1,
699
- date,
700
- value: 'test',
701
- reason: 'reason',
702
- code: 100,
703
- };
704
- const output = (0, objectUtils_1.convertDateFieldsToIsoString)(input);
705
- expect(output).toStrictEqual({
706
- id: 1,
707
- date: date.toISOString(),
708
- value: 'test',
709
- code: 100,
710
- reason: 'reason',
711
- });
712
- });
713
- it('simple array', () => {
714
- const date1 = new Date();
715
- const date2 = new Date();
716
- const input = [
717
- {
718
- id: 1,
719
- date: date1,
720
- value: 'test',
721
- reason: 'reason',
722
- code: 100,
723
- },
724
- {
725
- id: 2,
726
- date: date2,
727
- value: 'test 2',
728
- reason: 'reason 2',
729
- code: 200,
730
- },
731
- ];
732
- const output = (0, objectUtils_1.convertDateFieldsToIsoString)(input);
733
- expect(output).toStrictEqual([
734
- {
735
- id: 1,
736
- date: date1.toISOString(),
737
- value: 'test',
738
- code: 100,
739
- reason: 'reason',
740
- },
741
- {
742
- id: 2,
743
- date: date2.toISOString(),
744
- value: 'test 2',
745
- code: 200,
746
- reason: 'reason 2',
747
- },
748
- ]);
749
- });
750
- it('handles undefined and null', () => {
751
- const date = new Date();
752
- const input = {
753
- id: 1,
754
- date,
755
- value: 'test',
756
- code: 100,
757
- reason: null,
758
- other: undefined,
759
- };
760
- const output = (0, objectUtils_1.convertDateFieldsToIsoString)(input);
761
- expect(output).toStrictEqual({
762
- id: 1,
763
- date: date.toISOString(),
764
- value: 'test',
765
- code: 100,
766
- reason: null,
767
- other: undefined,
768
- });
769
- });
770
- it('properly handles all types of arrays', () => {
771
- const date = new Date();
772
- const input = {
773
- array1: [date, date],
774
- array2: [1, 2],
775
- array3: ['a', 'b'],
776
- array4: [
777
- { id: 1, value: 'value', date, code: 100 },
778
- { id: 2, value: 'value2', date, code: 200 },
779
- ],
780
- array5: [1, date, 'a', { id: 1, value: 'value', date, code: 100 }],
781
- };
782
- const output = (0, objectUtils_1.convertDateFieldsToIsoString)(input);
783
- expect(output).toStrictEqual({
784
- array1: [date.toISOString(), date.toISOString()],
785
- array2: [1, 2],
786
- array3: ['a', 'b'],
787
- array4: [
788
- { id: 1, value: 'value', date: date.toISOString(), code: 100 },
789
- { id: 2, value: 'value2', date: date.toISOString(), code: 200 },
790
- ],
791
- array5: [
792
- 1,
793
- date.toISOString(),
794
- 'a',
795
- { id: 1, value: 'value', date: date.toISOString(), code: 100 },
796
- ],
797
- });
798
- });
799
- it('nested objects and array', () => {
800
- const date1 = new Date();
801
- const date2 = new Date();
802
- date2.setFullYear(1990);
803
- const input = {
804
- id: 1,
805
- date: date1,
806
- value: 'test',
807
- code: 100,
808
- reason: 'reason',
809
- other: {
810
- id: 2,
811
- value: 'test 2',
812
- date: date2,
813
- code: 200,
814
- reason: null,
815
- other: undefined,
816
- },
817
- array: [
818
- {
819
- id: 1,
820
- createdAt: date1,
821
- },
822
- {
823
- id: 2,
824
- createdAt: date2,
825
- },
826
- ],
827
- };
828
- const output = (0, objectUtils_1.convertDateFieldsToIsoString)(input);
829
- expect(output).toMatchObject({
830
- id: 1,
831
- date: date1.toISOString(),
832
- value: 'test',
833
- code: 100,
834
- reason: 'reason',
835
- other: {
836
- id: 2,
837
- value: 'test 2',
838
- date: date2.toISOString(),
839
- code: 200,
840
- reason: null,
841
- other: undefined,
842
- },
843
- array: [
844
- {
845
- id: 1,
846
- createdAt: date1.toISOString(),
847
- },
848
- {
849
- id: 2,
850
- createdAt: date2.toISOString(),
851
- },
852
- ],
853
- });
854
- });
855
- });
856
- describe('deepClone', () => {
857
- it('will deep clone an object', () => {
858
- const object = {
859
- names: [
860
- {
861
- name: 'Cameron',
862
- },
863
- {
864
- name: 'Alexander',
865
- },
866
- {
867
- name: 'Smith',
868
- },
869
- ],
870
- date: new Date(),
871
- isEnabled: true,
872
- age: 12,
873
- };
874
- const clonedObject = (0, objectUtils_1.deepClone)(object);
875
- object.names = [];
876
- object.age = 22;
877
- object.isEnabled = false;
878
- expect(clonedObject.date).instanceof(Date);
879
- expect(clonedObject.date).not.toBe(object.date);
880
- expect(clonedObject.names).toStrictEqual([
881
- {
882
- name: 'Cameron',
883
- },
884
- {
885
- name: 'Alexander',
886
- },
887
- {
888
- name: 'Smith',
889
- },
890
- ]);
891
- expect(clonedObject.isEnabled).toBe(true);
892
- expect(clonedObject.age).toBe(12);
893
- });
894
- it('will return null or undefined if no object is provided', () => {
895
- expect((0, objectUtils_1.deepClone)(undefined)).toBeUndefined();
896
- expect((0, objectUtils_1.deepClone)(null)).toBeNull();
897
- });
898
- });
899
- describe('transformToKebabCase', () => {
900
- it('handle simple null and undefined', () => {
901
- const result1 = (0, objectUtils_1.transformToKebabCase)(null);
902
- expect(result1).toBe(null);
903
- const result2 = (0, objectUtils_1.transformToKebabCase)(undefined);
904
- expect(result2).toBe(undefined);
905
- });
906
- it('handle null and undefined in object', () => {
907
- const input = {
908
- my_first_undefined: undefined,
909
- mySecondUndefined: 1,
910
- my_first_null: null,
911
- mySecondNull: 2,
912
- nested: {
913
- my_first_undefined: undefined,
914
- mySecondUndefined: 3,
915
- my_first_null: null,
916
- mySecondNull: 4,
917
- },
918
- };
919
- const result = (0, objectUtils_1.transformToKebabCase)(input);
920
- expect(result).toEqual({
921
- 'my-first-undefined': undefined,
922
- 'my-second-undefined': 1,
923
- 'my-first-null': null,
924
- 'my-second-null': 2,
925
- nested: {
926
- 'my-first-undefined': undefined,
927
- 'my-second-undefined': 3,
928
- 'my-first-null': null,
929
- 'my-second-null': 4,
930
- },
931
- });
932
- });
933
- it('handle arrays', () => {
934
- const input = [
935
- { helloWorld: 'world', my_normal_array: [1, 2] },
936
- { goodBy: 'world', my_object_array: [{ myFriend: true }, { myLaptop: false }] },
937
- ];
938
- const result = (0, objectUtils_1.transformToKebabCase)(input);
939
- expect(result).toEqual([
940
- { 'hello-world': 'world', 'my-normal-array': [1, 2] },
941
- { 'good-by': 'world', 'my-object-array': [{ 'my-friend': true }, { 'my-laptop': false }] },
942
- ]);
943
- });
944
- describe('camelCase', () => {
945
- it('works with simple objects', () => {
946
- const input = { myProp: 'example', mySecondProp: 1, extra: 'extra' };
947
- const result = (0, objectUtils_1.transformToKebabCase)(input);
948
- expect(result).toEqual({
949
- 'my-prop': 'example',
950
- 'my-second-prop': 1,
951
- extra: 'extra',
952
- });
953
- });
954
- it('works with sub objects', () => {
955
- const input = { myProp: 'example', mySecondProp: { thirdProp: 1, extra: 1 } };
956
- const result = (0, objectUtils_1.transformToKebabCase)(input);
957
- expect(result).toEqual({
958
- 'my-prop': 'example',
959
- 'my-second-prop': { 'third-prop': 1, extra: 1 },
960
- });
961
- });
962
- it('abbreviations', () => {
963
- const input = { myHTTPKey: 'myValue' };
964
- const result = (0, objectUtils_1.transformToKebabCase)(input);
965
- expect(result).toEqual({
966
- 'my-http-key': 'myValue',
967
- });
968
- });
969
- it('handling non-alphanumeric symbols', () => {
970
- const input = { myProp: 'example', 'my_second.prop:example': 1 };
971
- const result = (0, objectUtils_1.transformToKebabCase)(input);
972
- expect(result).toEqual({ 'my-prop': 'example', 'my-second.prop:example': 1 });
973
- });
974
- });
975
- describe('snake_case', () => {
976
- it('snake_case works with simple objects', () => {
977
- const input = { my_prop: 'example', my_second_prop: 1, extra: 'extra' };
978
- const result = (0, objectUtils_1.transformToKebabCase)(input);
979
- expect(result).toEqual({
980
- 'my-prop': 'example',
981
- 'my-second-prop': 1,
982
- extra: 'extra',
983
- });
984
- });
985
- it('works with sub objects', () => {
986
- const input = { my_prop: 'example', my_second_prop: { third_prop: 1, extra: 1 } };
987
- const result = (0, objectUtils_1.transformToKebabCase)(input);
988
- expect(result).toEqual({
989
- 'my-prop': 'example',
990
- 'my-second-prop': { 'third-prop': 1, extra: 1 },
991
- });
992
- });
993
- });
994
- });
995
- });
996
- //# sourceMappingURL=objectUtils.spec.js.map