@metamask/utils 2.1.0 → 3.0.0

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.
@@ -0,0 +1,797 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OBJECT_MIXED_WITH_UNDEFINED_VALUES = exports.ARRAY_OF_MIXED_SPECIAL_OBJECTS = exports.ARRAY_OF_DIFFRENT_KINDS_OF_NUMBERS = exports.NON_SERIALIZABLE_NESTED_OBJECT = exports.COMPLEX_OBJECT = exports.JSON_RPC_RESPONSE_FIXTURES = exports.JSON_RPC_FAILURE_FIXTURES = exports.JSON_RPC_SUCCESS_FIXTURES = exports.JSON_RPC_REQUEST_FIXTURES = exports.JSON_RPC_NOTIFICATION_FIXTURES = exports.JSON_FIXTURES = void 0;
4
+ exports.JSON_FIXTURES = {
5
+ valid: [
6
+ null,
7
+ { a: 1 },
8
+ ['a', 2, null],
9
+ [{ a: null, b: 2, c: [{ foo: 'bar' }] }],
10
+ ],
11
+ invalid: [
12
+ undefined,
13
+ Symbol('bar'),
14
+ Promise.resolve(),
15
+ () => 'foo',
16
+ [{ a: undefined }],
17
+ ],
18
+ };
19
+ exports.JSON_RPC_NOTIFICATION_FIXTURES = {
20
+ valid: [
21
+ {
22
+ jsonrpc: '2.0',
23
+ method: 'notify',
24
+ },
25
+ {
26
+ jsonrpc: '2.0',
27
+ method: 'notify',
28
+ params: {
29
+ foo: 'bar',
30
+ },
31
+ },
32
+ {
33
+ jsonrpc: '2.0',
34
+ method: 'notify',
35
+ params: ['foo'],
36
+ },
37
+ ],
38
+ invalid: [
39
+ {},
40
+ [],
41
+ true,
42
+ false,
43
+ null,
44
+ undefined,
45
+ 1,
46
+ 'foo',
47
+ {
48
+ id: 1,
49
+ jsonrpc: '2.0',
50
+ method: 'notify',
51
+ },
52
+ {
53
+ jsonrpc: '1.0',
54
+ method: 'notify',
55
+ },
56
+ {
57
+ jsonrpc: 2.0,
58
+ method: 'notify',
59
+ },
60
+ {
61
+ jsonrpc: '2.0',
62
+ method: {},
63
+ },
64
+ {
65
+ jsonrpc: '2.0',
66
+ method: [],
67
+ },
68
+ {
69
+ jsonrpc: '2.0',
70
+ method: true,
71
+ },
72
+ {
73
+ jsonrpc: '2.0',
74
+ method: false,
75
+ },
76
+ {
77
+ jsonrpc: '2.0',
78
+ method: null,
79
+ },
80
+ {
81
+ jsonrpc: '2.0',
82
+ method: undefined,
83
+ },
84
+ {
85
+ jsonrpc: '2.0',
86
+ method: 1,
87
+ },
88
+ {
89
+ jsonrpc: '2.0',
90
+ method: 'notify',
91
+ params: true,
92
+ },
93
+ {
94
+ jsonrpc: '2.0',
95
+ method: 'notify',
96
+ params: false,
97
+ },
98
+ {
99
+ jsonrpc: '2.0',
100
+ method: 'notify',
101
+ params: null,
102
+ },
103
+ {
104
+ jsonrpc: '2.0',
105
+ method: 'notify',
106
+ params: 1,
107
+ },
108
+ {
109
+ jsonrpc: '2.0',
110
+ method: 'notify',
111
+ params: '',
112
+ },
113
+ ],
114
+ };
115
+ exports.JSON_RPC_REQUEST_FIXTURES = {
116
+ valid: [
117
+ {
118
+ jsonrpc: '2.0',
119
+ method: 'notify',
120
+ id: 1,
121
+ },
122
+ {
123
+ jsonrpc: '2.0',
124
+ method: 'notify',
125
+ id: '1',
126
+ params: {
127
+ foo: 'bar',
128
+ },
129
+ },
130
+ {
131
+ jsonrpc: '2.0',
132
+ method: 'notify',
133
+ id: 'foo',
134
+ params: ['foo'],
135
+ },
136
+ {
137
+ jsonrpc: '2.0',
138
+ method: 'notify',
139
+ id: null,
140
+ },
141
+ ],
142
+ invalid: [
143
+ {},
144
+ [],
145
+ true,
146
+ false,
147
+ null,
148
+ undefined,
149
+ 1,
150
+ 'foo',
151
+ {
152
+ id: 1,
153
+ jsonrpc: '1.0',
154
+ method: 'notify',
155
+ },
156
+ {
157
+ id: 1,
158
+ jsonrpc: 2.0,
159
+ method: 'notify',
160
+ },
161
+ {
162
+ id: 1,
163
+ jsonrpc: '2.0',
164
+ method: {},
165
+ },
166
+ {
167
+ id: 1,
168
+ jsonrpc: '2.0',
169
+ method: [],
170
+ },
171
+ {
172
+ id: 1,
173
+ jsonrpc: '2.0',
174
+ method: true,
175
+ },
176
+ {
177
+ id: 1,
178
+ jsonrpc: '2.0',
179
+ method: false,
180
+ },
181
+ {
182
+ id: 1,
183
+ jsonrpc: '2.0',
184
+ method: null,
185
+ },
186
+ {
187
+ id: 1,
188
+ jsonrpc: '2.0',
189
+ method: undefined,
190
+ },
191
+ {
192
+ id: 1,
193
+ jsonrpc: '2.0',
194
+ method: 1,
195
+ },
196
+ {
197
+ id: 1,
198
+ jsonrpc: '2.0',
199
+ method: 'notify',
200
+ params: true,
201
+ },
202
+ {
203
+ id: 1,
204
+ jsonrpc: '2.0',
205
+ method: 'notify',
206
+ params: false,
207
+ },
208
+ {
209
+ id: 1,
210
+ jsonrpc: '2.0',
211
+ method: 'notify',
212
+ params: null,
213
+ },
214
+ {
215
+ id: 1,
216
+ jsonrpc: '2.0',
217
+ method: 'notify',
218
+ params: 1,
219
+ },
220
+ {
221
+ id: 1,
222
+ jsonrpc: '2.0',
223
+ method: 'notify',
224
+ params: '',
225
+ },
226
+ ],
227
+ };
228
+ exports.JSON_RPC_SUCCESS_FIXTURES = {
229
+ valid: [
230
+ {
231
+ id: 1,
232
+ jsonrpc: '2.0',
233
+ result: 'foo',
234
+ },
235
+ {
236
+ id: '1',
237
+ jsonrpc: '2.0',
238
+ result: {
239
+ foo: 'bar',
240
+ },
241
+ },
242
+ {
243
+ id: 'foo',
244
+ jsonrpc: '2.0',
245
+ result: null,
246
+ },
247
+ {
248
+ id: 1,
249
+ jsonrpc: '2.0',
250
+ result: [
251
+ {
252
+ foo: 'bar',
253
+ },
254
+ ],
255
+ },
256
+ ],
257
+ invalid: [
258
+ {},
259
+ [],
260
+ true,
261
+ false,
262
+ null,
263
+ undefined,
264
+ 1,
265
+ 'foo',
266
+ {
267
+ jsonrpc: '2.0',
268
+ result: 'foo',
269
+ },
270
+ {
271
+ id: 1,
272
+ result: 'foo',
273
+ },
274
+ {
275
+ id: 1,
276
+ jsonrpc: '2.0',
277
+ },
278
+ {
279
+ id: 1,
280
+ jsonrpc: '1.0',
281
+ result: 'foo',
282
+ },
283
+ {
284
+ id: 1,
285
+ jsonrpc: 2.0,
286
+ result: 'foo',
287
+ },
288
+ {
289
+ id: 1,
290
+ jsonrpc: '2.0',
291
+ result: undefined,
292
+ },
293
+ {
294
+ id: {},
295
+ jsonrpc: '2.0',
296
+ result: 'foo',
297
+ },
298
+ {
299
+ id: [],
300
+ jsonrpc: '2.0',
301
+ result: 'foo',
302
+ },
303
+ {
304
+ id: true,
305
+ jsonrpc: '2.0',
306
+ result: 'foo',
307
+ },
308
+ {
309
+ id: false,
310
+ jsonrpc: '2.0',
311
+ result: 'foo',
312
+ },
313
+ {
314
+ id: undefined,
315
+ jsonrpc: '2.0',
316
+ result: 'foo',
317
+ },
318
+ ],
319
+ };
320
+ exports.JSON_RPC_FAILURE_FIXTURES = {
321
+ valid: [
322
+ {
323
+ id: 1,
324
+ jsonrpc: '2.0',
325
+ error: {
326
+ code: -32000,
327
+ message: 'Internal error',
328
+ },
329
+ },
330
+ {
331
+ id: '1',
332
+ jsonrpc: '2.0',
333
+ error: {
334
+ code: -32001,
335
+ message: 'Internal error',
336
+ data: {
337
+ foo: 'bar',
338
+ },
339
+ },
340
+ },
341
+ {
342
+ id: 'foo',
343
+ jsonrpc: '2.0',
344
+ error: {
345
+ code: -32002,
346
+ message: 'Internal error',
347
+ data: ['foo'],
348
+ stack: 'bar',
349
+ },
350
+ },
351
+ {
352
+ id: 'foo',
353
+ jsonrpc: '2.0',
354
+ error: {
355
+ code: -32000,
356
+ message: 'Internal error',
357
+ data: 'foo',
358
+ },
359
+ },
360
+ {
361
+ id: 'foo',
362
+ jsonrpc: '2.0',
363
+ error: {
364
+ code: -32000,
365
+ message: 'Internal error',
366
+ data: 1,
367
+ },
368
+ },
369
+ ],
370
+ invalid: [
371
+ {},
372
+ [],
373
+ true,
374
+ false,
375
+ null,
376
+ undefined,
377
+ 1,
378
+ 'foo',
379
+ {
380
+ jsonrpc: '2.0',
381
+ error: {
382
+ code: -32000,
383
+ message: 'Internal error',
384
+ },
385
+ },
386
+ {
387
+ id: 1,
388
+ error: {
389
+ code: -32000,
390
+ message: 'Internal error',
391
+ },
392
+ },
393
+ {
394
+ id: 1,
395
+ jsonrpc: '2.0',
396
+ },
397
+ {
398
+ id: {},
399
+ jsonrpc: '2.0',
400
+ error: {
401
+ code: -32000,
402
+ message: 'Internal error',
403
+ },
404
+ },
405
+ {
406
+ id: [],
407
+ jsonrpc: '2.0',
408
+ error: {
409
+ code: -32000,
410
+ message: 'Internal error',
411
+ },
412
+ },
413
+ {
414
+ id: true,
415
+ jsonrpc: '2.0',
416
+ error: {
417
+ code: -32000,
418
+ message: 'Internal error',
419
+ },
420
+ },
421
+ {
422
+ id: false,
423
+ jsonrpc: '2.0',
424
+ error: {
425
+ code: -32000,
426
+ message: 'Internal error',
427
+ },
428
+ },
429
+ {
430
+ id: undefined,
431
+ jsonrpc: '2.0',
432
+ error: {
433
+ code: -32000,
434
+ message: 'Internal error',
435
+ },
436
+ },
437
+ {
438
+ id: 1,
439
+ jsonrpc: '1.0',
440
+ error: {
441
+ code: -32000,
442
+ message: 'Internal error',
443
+ },
444
+ },
445
+ {
446
+ id: 1,
447
+ jsonrpc: 2.0,
448
+ error: {
449
+ code: -32000,
450
+ message: 'Internal error',
451
+ },
452
+ },
453
+ {
454
+ id: 1,
455
+ jsonrpc: {},
456
+ error: {
457
+ code: -32000,
458
+ message: 'Internal error',
459
+ },
460
+ },
461
+ {
462
+ id: 1,
463
+ jsonrpc: [],
464
+ error: {
465
+ code: -32000,
466
+ message: 'Internal error',
467
+ },
468
+ },
469
+ {
470
+ id: 1,
471
+ jsonrpc: true,
472
+ error: {
473
+ code: -32000,
474
+ message: 'Internal error',
475
+ },
476
+ },
477
+ {
478
+ id: 1,
479
+ jsonrpc: false,
480
+ error: {
481
+ code: -32000,
482
+ message: 'Internal error',
483
+ },
484
+ },
485
+ {
486
+ id: 1,
487
+ jsonrpc: null,
488
+ error: {
489
+ code: -32000,
490
+ message: 'Internal error',
491
+ },
492
+ },
493
+ {
494
+ id: 1,
495
+ jsonrpc: undefined,
496
+ error: {
497
+ code: -32000,
498
+ message: 'Internal error',
499
+ },
500
+ },
501
+ {
502
+ id: 1,
503
+ jsonrpc: '2.0',
504
+ error: {
505
+ code: -32000,
506
+ },
507
+ },
508
+ {
509
+ id: 1,
510
+ jsonrpc: '2.0',
511
+ error: {
512
+ message: 'Internal error',
513
+ },
514
+ },
515
+ {
516
+ id: 1,
517
+ jsonrpc: '2.0',
518
+ error: [],
519
+ },
520
+ {
521
+ id: 1,
522
+ jsonrpc: '2.0',
523
+ error: {},
524
+ },
525
+ {
526
+ id: 1,
527
+ jsonrpc: '2.0',
528
+ error: true,
529
+ },
530
+ {
531
+ id: 1,
532
+ jsonrpc: '2.0',
533
+ error: false,
534
+ },
535
+ {
536
+ id: 1,
537
+ jsonrpc: '2.0',
538
+ error: null,
539
+ },
540
+ {
541
+ id: 1,
542
+ jsonrpc: '2.0',
543
+ error: undefined,
544
+ },
545
+ {
546
+ id: 1,
547
+ jsonrpc: '2.0',
548
+ error: 'foo',
549
+ },
550
+ {
551
+ id: 1,
552
+ jsonrpc: '2.0',
553
+ error: 1,
554
+ },
555
+ {
556
+ id: 1,
557
+ jsonrpc: '2.0',
558
+ error: {
559
+ code: {},
560
+ message: 'Internal error',
561
+ },
562
+ },
563
+ {
564
+ id: 1,
565
+ jsonrpc: '2.0',
566
+ error: {
567
+ code: [],
568
+ message: 'Internal error',
569
+ },
570
+ },
571
+ {
572
+ id: 1,
573
+ jsonrpc: '2.0',
574
+ error: {
575
+ code: true,
576
+ message: 'Internal error',
577
+ },
578
+ },
579
+ {
580
+ id: 1,
581
+ jsonrpc: '2.0',
582
+ error: {
583
+ code: false,
584
+ message: 'Internal error',
585
+ },
586
+ },
587
+ {
588
+ id: 1,
589
+ jsonrpc: '2.0',
590
+ error: {
591
+ code: null,
592
+ message: 'Internal error',
593
+ },
594
+ },
595
+ {
596
+ id: 1,
597
+ jsonrpc: '2.0',
598
+ error: {
599
+ code: undefined,
600
+ message: 'Internal error',
601
+ },
602
+ },
603
+ {
604
+ id: 1,
605
+ jsonrpc: '2.0',
606
+ error: {
607
+ code: 'foo',
608
+ message: 'Internal error',
609
+ },
610
+ },
611
+ {
612
+ id: 1,
613
+ jsonrpc: '2.0',
614
+ error: {
615
+ code: -32000,
616
+ message: {},
617
+ },
618
+ },
619
+ {
620
+ id: 1,
621
+ jsonrpc: '2.0',
622
+ error: {
623
+ code: -32000,
624
+ message: [],
625
+ },
626
+ },
627
+ {
628
+ id: 1,
629
+ jsonrpc: '2.0',
630
+ error: {
631
+ code: -32000,
632
+ message: true,
633
+ },
634
+ },
635
+ {
636
+ id: 1,
637
+ jsonrpc: '2.0',
638
+ error: {
639
+ code: -32000,
640
+ message: false,
641
+ },
642
+ },
643
+ {
644
+ id: 1,
645
+ jsonrpc: '2.0',
646
+ error: {
647
+ code: -32000,
648
+ message: null,
649
+ },
650
+ },
651
+ {
652
+ id: 1,
653
+ jsonrpc: '2.0',
654
+ error: {
655
+ code: -32000,
656
+ message: undefined,
657
+ },
658
+ },
659
+ ],
660
+ };
661
+ exports.JSON_RPC_RESPONSE_FIXTURES = {
662
+ valid: [
663
+ ...exports.JSON_RPC_SUCCESS_FIXTURES.valid,
664
+ ...exports.JSON_RPC_FAILURE_FIXTURES.valid,
665
+ ],
666
+ invalid: [
667
+ ...exports.JSON_RPC_SUCCESS_FIXTURES.invalid,
668
+ ...exports.JSON_RPC_FAILURE_FIXTURES.invalid,
669
+ ],
670
+ };
671
+ exports.COMPLEX_OBJECT = {
672
+ data: {
673
+ account: {
674
+ __typename: 'Account',
675
+ registrations: [
676
+ {
677
+ __typename: 'Registration',
678
+ domain: {
679
+ __typename: 'Domain',
680
+ isMigrated: true,
681
+ labelName: 'mycrypto',
682
+ labelhash: '0x9a781ca0d227debc3ee76d547c960b0803a6c9f58c6d3b4722f12ede7e6ef7c9',
683
+ name: 'mycrypto.eth',
684
+ parent: { __typename: 'Domain', name: 'eth' },
685
+ },
686
+ expiryDate: '1754111315',
687
+ },
688
+ ],
689
+ },
690
+ moreComplexity: {
691
+ numbers: [
692
+ -5e-11,
693
+ 5e-9,
694
+ 0.000000000001,
695
+ -0.00000000009,
696
+ 100000.00000008,
697
+ -100.88888,
698
+ 0.333,
699
+ 1000000000000,
700
+ ],
701
+ moreNestedObjects: {
702
+ nestedAgain: {
703
+ nestedAgain: {
704
+ andAgain: {
705
+ andAgain: {
706
+ value: true,
707
+ again: {
708
+ value: false,
709
+ },
710
+ },
711
+ },
712
+ },
713
+ },
714
+ },
715
+ differentEncodings: {
716
+ ascii: '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~',
717
+ utf8: 'šđćčžЀЂЇЄЖФћΣΩδλ',
718
+ mixed: 'ABCDEFGHIJ KLMNOPQRST UVWXYZšđćč žЀЂЇЄЖФћΣΩδλ',
719
+ specialCharacters: '"\\\n\r\t',
720
+ stringWithSpecialEscapedCharacters: "this\nis\nsome\"'string\r\nwith\tspecial\\escaped\tcharacters'",
721
+ },
722
+ specialObjectsTypesAndValues: {
723
+ t: [true, true, true],
724
+ f: [false, false, false],
725
+ nulls: [null, null, null],
726
+ undef: undefined,
727
+ mixed: [
728
+ null,
729
+ undefined,
730
+ null,
731
+ undefined,
732
+ null,
733
+ true,
734
+ null,
735
+ false,
736
+ null,
737
+ undefined,
738
+ ],
739
+ inObject: {
740
+ valueOne: null,
741
+ valueTwo: undefined,
742
+ t: true,
743
+ f: false,
744
+ },
745
+ dates: {
746
+ someDate: new Date(),
747
+ someOther: new Date(2022, 0, 2, 15, 4, 5),
748
+ invalidDate: new Date('bad-date-format'),
749
+ },
750
+ },
751
+ },
752
+ },
753
+ };
754
+ exports.NON_SERIALIZABLE_NESTED_OBJECT = {
755
+ levelOne: {
756
+ levelTwo: {
757
+ levelThree: {
758
+ levelFour: {
759
+ levelFive: () => {
760
+ return 'anything';
761
+ },
762
+ },
763
+ },
764
+ },
765
+ },
766
+ };
767
+ exports.ARRAY_OF_DIFFRENT_KINDS_OF_NUMBERS = [
768
+ -5e-11,
769
+ 5e-9,
770
+ 0.000000000001,
771
+ -0.00000000009,
772
+ 100000.00000008,
773
+ -100.88888,
774
+ 0.333,
775
+ 1000000000000,
776
+ ];
777
+ exports.ARRAY_OF_MIXED_SPECIAL_OBJECTS = [
778
+ null,
779
+ undefined,
780
+ null,
781
+ undefined,
782
+ undefined,
783
+ undefined,
784
+ null,
785
+ null,
786
+ null,
787
+ undefined,
788
+ ];
789
+ exports.OBJECT_MIXED_WITH_UNDEFINED_VALUES = {
790
+ a: undefined,
791
+ b: 'b',
792
+ c: undefined,
793
+ d: 'd',
794
+ e: undefined,
795
+ f: 'f',
796
+ };
797
+ //# sourceMappingURL=json.js.map