@rsdk/common 4.0.0-next.13 → 4.0.0-next.15

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/CHANGELOG.md +40 -14
  2. package/dist/convert/convert.class.js.map +1 -1
  3. package/dist/functions/obj-normalization.js.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +1 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/observable/index.d.ts +1 -0
  8. package/dist/observable/index.js +18 -0
  9. package/dist/observable/index.js.map +1 -0
  10. package/dist/observable/observable-to-async-iterable.d.ts +7 -0
  11. package/dist/observable/observable-to-async-iterable.js +109 -0
  12. package/dist/observable/observable-to-async-iterable.js.map +1 -0
  13. package/dist/size/size.class.js.map +1 -1
  14. package/dist/strings/get-random-bytes.d.ts +6 -0
  15. package/dist/strings/get-random-bytes.js +19 -0
  16. package/dist/strings/get-random-bytes.js.map +1 -0
  17. package/dist/strings/index.d.ts +1 -0
  18. package/dist/strings/index.js +1 -0
  19. package/dist/strings/index.js.map +1 -1
  20. package/dist/strings/text.fn.js.map +1 -1
  21. package/dist/time/repeat.fn.js.map +1 -1
  22. package/dist/time/stopwatch.class.js.map +1 -1
  23. package/dist/time/timespan.class.js.map +1 -1
  24. package/dist/types/assert.class.js.map +1 -1
  25. package/dist/types/error-like.type.js.map +1 -1
  26. package/jest.config.e2e.js +1 -0
  27. package/jest.config.js +1 -5
  28. package/jest.config.unit.js +1 -0
  29. package/package.json +2 -2
  30. package/src/convert/convert.spec.ts +367 -61
  31. package/src/functions/misc.spec.ts +44 -29
  32. package/src/functions/obj-normalization.spec.ts +11 -1
  33. package/src/index.ts +1 -0
  34. package/src/observable/index.ts +1 -0
  35. package/src/observable/observable-to-async-iterable.ts +117 -0
  36. package/src/size/size.spec.ts +1 -1
  37. package/src/strings/get-random-bytes.ts +16 -0
  38. package/src/strings/index.ts +1 -0
  39. package/src/types/deep-partial.type.ts +10 -10
  40. package/src/types/error-like.type.ts +1 -0
@@ -61,31 +61,146 @@ describe('Convert', () => {
61
61
 
62
62
  const tt: Case[] = [
63
63
  // Positive
64
- { name: 'Correct integer (string)', input: '123', success: true, output: 123 },
65
- { name: 'Correct integer (number)', input: 123, success: true, output: 123 },
66
- { name: 'Correct negative integer (number)', input: -123, success: true, output: -123 },
67
- { name: 'Correct negative integer (string)', input: '-123', success: true, output: -123 },
68
- { name: 'Correct float (string)', input: '123.1', success: true, output: 123.1 },
69
- { name: 'Correct float (number)', input: 123.1, success: true, output: 123.1 },
70
- { name: 'Correct negative float (number)', input: -123.4, success: true, output: -123.4 },
71
- { name: 'Correct negative float (string)', input: '-123.4', success: true, output: -123.4 },
72
- { name: 'Zero', input: 0, success: true, output: 0 },
73
- { name: 'Zero string', input: '0', success: true, output: 0 },
64
+ {
65
+ name: 'Correct integer (string)',
66
+ input: '123',
67
+ success: true,
68
+ output: 123
69
+ },
70
+ {
71
+ name: 'Correct integer (number)',
72
+ input: 123,
73
+ success: true,
74
+ output: 123
75
+ },
76
+ {
77
+ name: 'Correct negative integer (number)',
78
+ input: -123,
79
+ success: true,
80
+ output: -123
81
+ },
82
+ {
83
+ name: 'Correct negative integer (string)',
84
+ input: '-123',
85
+ success: true,
86
+ output: -123
87
+ },
88
+ {
89
+ name: 'Correct float (string)',
90
+ input: '123.1',
91
+ success: true,
92
+ output: 123.1
93
+ },
94
+ {
95
+ name: 'Correct float (number)',
96
+ input: 123.1,
97
+ success: true,
98
+ output: 123.1
99
+ },
100
+ {
101
+ name: 'Correct negative float (number)',
102
+ input: -123.4,
103
+ success: true,
104
+ output: -123.4
105
+ },
106
+ {
107
+ name: 'Correct negative float (string)',
108
+ input: '-123.4',
109
+ success: true,
110
+ output: -123.4
111
+ },
112
+ {
113
+ name: 'Zero',
114
+ input: 0,
115
+ success: true,
116
+ output: 0
117
+ },
118
+ {
119
+ name: 'Zero string',
120
+ input: '0',
121
+ success: true,
122
+ output: 0
123
+ },
74
124
 
75
125
  // Negative
76
- { name: 'Incorrect float (string)', input: '123,1', success: false, output: null },
77
- { name: 'Empty string', input: '', success: false, output: null },
78
- { name: 'True (boolean)', input: true, success: false, output: null },
79
- { name: 'True (string lowercase)', input: 'true', success: false, output: null },
80
- { name: 'True (string mixedcase)', input: 'TrUe', success: false, output: null },
81
- { name: 'False (boolean)', input: false, success: false, output: null },
82
- { name: 'False (string lowercase)', input: 'false', success: false, output: null },
83
- { name: 'False (string mixedcase)', input: 'FalSe', success: false, output: null },
84
- { name: 'Trash (string)', input: 'sdfg', success: false, output: null },
85
- { name: 'Trash (object)', input: { a: 1 }, success: false, output: null },
86
- { name: 'Trash (object)', input: { a: 1 }, success: false, output: null },
87
- { name: 'null', input: null, success: false, output: null },
88
- { name: 'undefined', input: undefined, success: false, output: null },
126
+ {
127
+ name: 'Incorrect float (string)',
128
+ input: '123,1',
129
+ success: false,
130
+ output: null
131
+ },
132
+ {
133
+ name: 'Empty string',
134
+ input: '',
135
+ success: false,
136
+ output: null
137
+ },
138
+ {
139
+ name: 'True (boolean)',
140
+ input: true,
141
+ success: false,
142
+ output: null
143
+ },
144
+ {
145
+ name: 'True (string lowercase)',
146
+ input: 'true',
147
+ success: false,
148
+ output: null
149
+ },
150
+ {
151
+ name: 'True (string mixedcase)',
152
+ input: 'TrUe',
153
+ success: false,
154
+ output: null
155
+ },
156
+ {
157
+ name: 'False (boolean)',
158
+ input: false,
159
+ success: false,
160
+ output: null
161
+ },
162
+ {
163
+ name: 'False (string lowercase)',
164
+ input: 'false',
165
+ success: false,
166
+ output: null
167
+ },
168
+ {
169
+ name: 'False (string mixedcase)',
170
+ input: 'FalSe',
171
+ success: false,
172
+ output: null
173
+ },
174
+ {
175
+ name: 'Trash (string)',
176
+ input: 'sdfg',
177
+ success: false,
178
+ output: null
179
+ },
180
+ {
181
+ name: 'Trash (object)',
182
+ input: { a: 1 },
183
+ success: false,
184
+ output: null
185
+ },
186
+ {
187
+ name: 'Trash (object)',
188
+ input: { a: 1 },
189
+ success: false,
190
+ output: null
191
+ },
192
+ {
193
+ name: 'null',
194
+ input: null,
195
+ success: false,
196
+ output: null
197
+ },
198
+ {
199
+ name: 'undefined',
200
+ input: undefined,
201
+ success: false,
202
+ output: null
203
+ },
89
204
  ];
90
205
 
91
206
  for (const { name, input, success, output } of tt) {
@@ -143,6 +258,7 @@ describe('Convert', () => {
143
258
  KEY_1,
144
259
  KEY_2,
145
260
  }
261
+
146
262
  enum Numeric {
147
263
  KEY_1 = 0,
148
264
  KEY_2 = 1,
@@ -173,12 +289,42 @@ describe('Convert', () => {
173
289
 
174
290
  const common: Subcase[] = [
175
291
  // All negative!
176
- { name: 'Random string', input: 'sadfasdf', success: false, output: null },
177
- { name: 'Random number', input: 123, success: false, output: null },
178
- { name: 'Random boolean', input: true, success: false, output: null },
179
- { name: 'Random object', input: { a: 1 }, success: false, output: null },
180
- { name: 'null', input: null, success: false, output: null },
181
- { name: 'undefined', input: undefined, success: false, output: null },
292
+ {
293
+ name: 'Random string',
294
+ input: 'sadfasdf',
295
+ success: false,
296
+ output: null
297
+ },
298
+ {
299
+ name: 'Random number',
300
+ input: 123,
301
+ success: false,
302
+ output: null
303
+ },
304
+ {
305
+ name: 'Random boolean',
306
+ input: true,
307
+ success: false,
308
+ output: null
309
+ },
310
+ {
311
+ name: 'Random object',
312
+ input: { a: 1 },
313
+ success: false,
314
+ output: null
315
+ },
316
+ {
317
+ name: 'null',
318
+ input: null,
319
+ success: false,
320
+ output: null
321
+ },
322
+ {
323
+ name: 'undefined',
324
+ input: undefined,
325
+ success: false,
326
+ output: null
327
+ },
182
328
  ];
183
329
 
184
330
  const tt: Case[] = [
@@ -187,16 +333,56 @@ describe('Convert', () => {
187
333
  e: Implicit,
188
334
  subcases: [
189
335
  // Positive
190
- { name: 'Zero (number)', input: 0, success: true, output: Implicit.KEY_1 },
191
- { name: 'Zero (string)', input: '0', success: true, output: Implicit.KEY_1 },
192
- { name: 'One (number)', input: 1, success: true, output: Implicit.KEY_2 },
193
- { name: 'One (number)', input: '1', success: true, output: Implicit.KEY_2 },
194
- { name: 'KEY_1', input: 'KEY_1', success: true, output: Implicit.KEY_1 },
195
- { name: 'KEY_2', input: 'KEY_2', success: true, output: Implicit.KEY_2 },
336
+ {
337
+ name: 'Zero (number)',
338
+ input: 0,
339
+ success: true,
340
+ output: Implicit.KEY_1
341
+ },
342
+ {
343
+ name: 'Zero (string)',
344
+ input: '0',
345
+ success: true,
346
+ output: Implicit.KEY_1
347
+ },
348
+ {
349
+ name: 'One (number)',
350
+ input: 1,
351
+ success: true,
352
+ output: Implicit.KEY_2
353
+ },
354
+ {
355
+ name: 'One (number)',
356
+ input: '1',
357
+ success: true,
358
+ output: Implicit.KEY_2
359
+ },
360
+ {
361
+ name: 'KEY_1',
362
+ input: 'KEY_1',
363
+ success: true,
364
+ output: Implicit.KEY_1
365
+ },
366
+ {
367
+ name: 'KEY_2',
368
+ input: 'KEY_2',
369
+ success: true,
370
+ output: Implicit.KEY_2
371
+ },
196
372
 
197
373
  // Negative
198
- { name: 'null', input: null, success: false, output: null },
199
- { name: 'undefined', input: undefined, success: false, output: null },
374
+ {
375
+ name: 'null',
376
+ input: null,
377
+ success: false,
378
+ output: null
379
+ },
380
+ {
381
+ name: 'undefined',
382
+ input: undefined,
383
+ success: false,
384
+ output: null
385
+ },
200
386
  ...common,
201
387
  ],
202
388
  },
@@ -205,16 +391,56 @@ describe('Convert', () => {
205
391
  e: Numeric,
206
392
  subcases: [
207
393
  // Positive
208
- { name: 'Zero (number)', input: 0, success: true, output: Numeric.KEY_1 },
209
- { name: 'Zero (string)', input: '0', success: true, output: Numeric.KEY_1 },
210
- { name: 'One (number)', input: 1, success: true, output: Numeric.KEY_2 },
211
- { name: 'One (number)', input: '1', success: true, output: Numeric.KEY_2 },
212
- { name: 'KEY_1', input: 'KEY_1', success: true, output: Numeric.KEY_1 },
213
- { name: 'KEY_2', input: 'KEY_2', success: true, output: Numeric.KEY_2 },
394
+ {
395
+ name: 'Zero (number)',
396
+ input: 0,
397
+ success: true,
398
+ output: Numeric.KEY_1
399
+ },
400
+ {
401
+ name: 'Zero (string)',
402
+ input: '0',
403
+ success: true,
404
+ output: Numeric.KEY_1
405
+ },
406
+ {
407
+ name: 'One (number)',
408
+ input: 1,
409
+ success: true,
410
+ output: Numeric.KEY_2
411
+ },
412
+ {
413
+ name: 'One (number)',
414
+ input: '1',
415
+ success: true,
416
+ output: Numeric.KEY_2
417
+ },
418
+ {
419
+ name: 'KEY_1',
420
+ input: 'KEY_1',
421
+ success: true,
422
+ output: Numeric.KEY_1
423
+ },
424
+ {
425
+ name: 'KEY_2',
426
+ input: 'KEY_2',
427
+ success: true,
428
+ output: Numeric.KEY_2
429
+ },
214
430
 
215
431
  // Negative
216
- { name: 'null', input: null, success: false, output: null },
217
- { name: 'undefined', input: undefined, success: false, output: null },
432
+ {
433
+ name: 'null',
434
+ input: null,
435
+ success: false,
436
+ output: null
437
+ },
438
+ {
439
+ name: 'undefined',
440
+ input: undefined,
441
+ success: false,
442
+ output: null
443
+ },
218
444
  ...common,
219
445
  ]
220
446
  },
@@ -223,16 +449,56 @@ describe('Convert', () => {
223
449
  e: Strings,
224
450
  subcases: [
225
451
  // Positive
226
- { name: 'Zero (string)', input: '0', success: true, output: Strings.KEY_1 },
227
- { name: 'One (number)', input: '1', success: true, output: Strings.KEY_2 },
228
- { name: 'KEY_1', input: 'KEY_1', success: true, output: Strings.KEY_1 },
229
- { name: 'KEY_2', input: 'KEY_2', success: true, output: Strings.KEY_2 },
452
+ {
453
+ name: 'Zero (string)',
454
+ input: '0',
455
+ success: true,
456
+ output: Strings.KEY_1
457
+ },
458
+ {
459
+ name: 'One (number)',
460
+ input: '1',
461
+ success: true,
462
+ output: Strings.KEY_2
463
+ },
464
+ {
465
+ name: 'KEY_1',
466
+ input: 'KEY_1',
467
+ success: true,
468
+ output: Strings.KEY_1
469
+ },
470
+ {
471
+ name: 'KEY_2',
472
+ input: 'KEY_2',
473
+ success: true,
474
+ output: Strings.KEY_2
475
+ },
230
476
 
231
477
  // Negative
232
- { name: 'null', input: null, success: false, output: null },
233
- { name: 'undefined', input: undefined, success: false, output: null },
234
- { name: 'Zero (number)', input: 0, success: false, output: null },
235
- { name: 'One (number)', input: 1, success: false, output: null },
478
+ {
479
+ name: 'null',
480
+ input: null,
481
+ success: false,
482
+ output: null
483
+ },
484
+ {
485
+ name: 'undefined',
486
+ input: undefined,
487
+ success: false,
488
+ output: null
489
+ },
490
+ {
491
+ name: 'Zero (number)',
492
+ input: 0,
493
+ success: false,
494
+ output: null
495
+ },
496
+ {
497
+ name: 'One (number)',
498
+ input: 1,
499
+ success: false,
500
+ output: null
501
+ },
236
502
  ...common,
237
503
  ],
238
504
  },
@@ -241,16 +507,56 @@ describe('Convert', () => {
241
507
  e: Mixed,
242
508
  subcases: [
243
509
  // Positive
244
- { name: 'Zero (string)', input: '0', success: true, output: Mixed.KEY_1 },
245
- { name: 'One (number)', input: 1, success: true, output: Mixed.KEY_2 },
246
- { name: 'One (number)', input: '1', success: true, output: Mixed.KEY_2 },
247
- { name: 'KEY_1', input: 'KEY_1', success: true, output: Mixed.KEY_1 },
248
- { name: 'KEY_2', input: 'KEY_2', success: true, output: Mixed.KEY_2 },
510
+ {
511
+ name: 'Zero (string)',
512
+ input: '0',
513
+ success: true,
514
+ output: Mixed.KEY_1
515
+ },
516
+ {
517
+ name: 'One (number)',
518
+ input: 1,
519
+ success: true,
520
+ output: Mixed.KEY_2
521
+ },
522
+ {
523
+ name: 'One (number)',
524
+ input: '1',
525
+ success: true,
526
+ output: Mixed.KEY_2
527
+ },
528
+ {
529
+ name: 'KEY_1',
530
+ input: 'KEY_1',
531
+ success: true,
532
+ output: Mixed.KEY_1
533
+ },
534
+ {
535
+ name: 'KEY_2',
536
+ input: 'KEY_2',
537
+ success: true,
538
+ output: Mixed.KEY_2
539
+ },
249
540
 
250
541
  // Negative
251
- { name: 'null', input: null, success: false, output: null },
252
- { name: 'undefined', input: undefined, success: false, output: null },
253
- { name: 'Zero (number)', input: 0, success: false, output: null },
542
+ {
543
+ name: 'null',
544
+ input: null,
545
+ success: false,
546
+ output: null
547
+ },
548
+ {
549
+ name: 'undefined',
550
+ input: undefined,
551
+ success: false,
552
+ output: null
553
+ },
554
+ {
555
+ name: 'Zero (number)',
556
+ input: 0,
557
+ success: false,
558
+ output: null
559
+ },
254
560
  ...common,
255
561
  ],
256
562
  },
@@ -16,40 +16,55 @@ describe('misc', () => {
16
16
 
17
17
  const tt: Case[] = [
18
18
  // Positive
19
- { name: 'Correct object (literal)', input: {}, success: true, output: true },
20
- { name: 'Correct object (Object())', input: new Object(), success: true, output: true },
21
- { name: 'Correct object (new Object())', input: new Object(), success: true, output: true },
22
- { name: 'Correct object (Object.create())', input: Object.create({}), success: true, output: true },
23
- { name: 'Correct object (Object.assign())', input: Object.assign({}, {}), success: true, output: true },
19
+ { name: 'Correct object (literal)', input: {}, success: true, output: true },
20
+ { name: 'Correct object (Object())', input: {}, success: true, output: true },
21
+ { name: 'Correct object (new Object())', input: {}, success: true, output: true },
22
+ { name: 'Correct object (Object.create())', input: Object.create({}), success: true, output: true },
23
+ { name: 'Correct object (Object.assign())', input: Object.assign({}, {}), success: true, output: true },
24
24
 
25
- { name: 'Function (declarative)', input: function t(): void {}, success: true, output: false },
26
- { name: 'new Function() instance', input: new Function(), success: true, output: false },
27
- { name: 'Function constructor', input: new (function t() {})(), success: true, output: false },
28
- { name: 'Class', input: class T {}, success: true, output: false },
29
- { name: 'Class constructor', input: new (class T{})(), success: true, output: false },
30
- { name: 'Array (literal)', input: [], success: true, output: false },
31
- { name: 'Array() instance', input: Array(), success: true, output: false },
32
- { name: 'new Array() instance', input: new Array(), success: true, output: false },
33
- { name: 'The Map (new Map())', input: new Map(), success: true, output: false },
34
- { name: 'The Set (new Set())', input: new Set(), success: true, output: false },
35
- { name: 'Date object', input: new Date(), success: true, output: false },
36
- { name: 'String oject', input: new String('str'), success: true, output: false },
37
- { name: 'Number object', input: new Number(1), success: true, output: false },
38
- { name: 'Boolean object', input: new Boolean(true), success: true, output: false },
39
- { name: 'BigInt', input: BigInt(999999999999), success: true, output: false },
40
- { name: 'Symbol', input: Symbol(), success: true, output: false },
41
- { name: 'null', input: null, success: true, output: false },
42
- { name: 'undefined', input: undefined, success: true, output: false },
43
- { name: 'true', input: true, success: true, output: false },
44
- { name: 'number', input: 12, success: true, output: false },
45
- { name: 'string', input: 'str', success: true, output: false },
25
+ {
26
+ name: 'Function (declarative)', input: function t(): void {}, success: true, output: false
27
+ },
28
+ { name: 'new Function() instance', input: new Function(), success: true, output: false },
29
+ {
30
+ name: 'Function constructor', input: new (function t() {})(), success: true, output: false
31
+ },
32
+ {
33
+ name: 'Class', input: class T {}, success: true, output: false
34
+ },
35
+ {
36
+ name: 'Class constructor', input: new (class T {})(), success: true, output: false
37
+ },
38
+ { name: 'Array (literal)', input: [], success: true, output: false },
39
+ { name: 'Array() instance', input: Array(), success: true, output: false },
40
+ { name: 'new Array() instance', input: [], success: true, output: false },
41
+ { name: 'The Map (new Map())', input: new Map(), success: true, output: false },
42
+ { name: 'The Set (new Set())', input: new Set(), success: true, output: false },
43
+ { name: 'Date object', input: new Date(), success: true, output: false },
44
+ { name: 'String oject', input: String('str'), success: true, output: false },
45
+ { name: 'Number object', input: Number(1), success: true, output: false },
46
+ { name: 'Boolean object', input: Boolean(true), success: true, output: false },
47
+ { name: 'BigInt', input: BigInt(999999999999), success: true, output: false },
48
+ { name: 'Symbol', input: Symbol(), success: true, output: false },
49
+ { name: 'null', input: null, success: true, output: false },
50
+ { name: 'undefined', input: undefined, success: true, output: false },
51
+ { name: 'true', input: true, success: true, output: false },
52
+ { name: 'number', input: 12, success: true, output: false },
53
+ { name: 'string', input: 'str', success: true, output: false },
46
54
  ];
47
55
 
48
- for (const { name, input, success, output } of tt) {
56
+ for (const {
57
+ name,
58
+ input,
59
+ success,
60
+ output
61
+ } of tt) {
49
62
  if (success) {
50
- it(name, () => expect(isRecord(input)).toBe(output));
63
+ it(name, () => expect(isRecord(input))
64
+ .toBe(output));
51
65
  } else {
52
- it(name, () => expect(() => isRecord(input)).toThrow());
66
+ it(name, () => expect(() => isRecord(input))
67
+ .toThrow());
53
68
  }
54
69
  }
55
70
  });
@@ -35,7 +35,17 @@ describe('should handle circular', () => {
35
35
  ${a} | ${{ a: '[circular]' }}
36
36
  ${b} | ${{ a: { a: '[circular]' }, b: '[circular]' }}
37
37
  ${c} | ${{ a: { b: { c: '[circular]' } } }}
38
- ${d} | ${{ d: [{ a: '[circular]' }, { a: '[circular]', b: '[circular]' }, { a: { b: { c: '[circular]' } } }, '[circular]'] }}
38
+ ${d} | ${{
39
+ d: [
40
+ { a: '[circular]' },
41
+ {
42
+ a: '[circular]',
43
+ b: '[circular]',
44
+ },
45
+ { a: { b: { c: '[circular]' } } },
46
+ '[circular]',
47
+ ],
48
+ }}
39
49
  `('$input to be $output', ({ input, output }) => {
40
50
  expect(normalizer()(input)).toEqual(output);
41
51
  });
package/src/index.ts CHANGED
@@ -5,3 +5,4 @@ export * from './time';
5
5
  export * from './functions';
6
6
  export * from './size';
7
7
  export * from './strings';
8
+ export * from './observable';
@@ -0,0 +1 @@
1
+ export * from './observable-to-async-iterable';