vest-utils 1.4.0 → 1.5.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.
Files changed (157) hide show
  1. package/README.md +2 -7
  2. package/dist/cjs/minifyObject.development.js +217 -0
  3. package/dist/cjs/minifyObject.development.js.map +1 -0
  4. package/dist/cjs/minifyObject.js +6 -0
  5. package/dist/cjs/minifyObject.production.js +2 -0
  6. package/dist/cjs/minifyObject.production.js.map +1 -0
  7. package/dist/cjs/package.json +1 -0
  8. package/dist/cjs/vest-utils.development.js +378 -0
  9. package/dist/cjs/vest-utils.development.js.map +1 -0
  10. package/dist/cjs/vest-utils.js +6 -0
  11. package/dist/cjs/vest-utils.production.js +2 -0
  12. package/dist/cjs/vest-utils.production.js.map +1 -0
  13. package/dist/es/minifyObject.development.js +214 -0
  14. package/dist/es/minifyObject.development.js.map +1 -0
  15. package/dist/es/minifyObject.production.js +2 -0
  16. package/dist/es/minifyObject.production.js.map +1 -0
  17. package/dist/es/package.json +1 -0
  18. package/dist/es/vest-utils.development.js +330 -0
  19. package/dist/es/vest-utils.development.js.map +1 -0
  20. package/dist/es/vest-utils.production.js +2 -0
  21. package/dist/es/vest-utils.production.js.map +1 -0
  22. package/dist/umd/minifyObject.development.js +223 -0
  23. package/dist/umd/minifyObject.development.js.map +1 -0
  24. package/dist/umd/minifyObject.production.js +2 -0
  25. package/dist/umd/minifyObject.production.js.map +1 -0
  26. package/dist/umd/vest-utils.development.js +384 -0
  27. package/dist/umd/vest-utils.development.js.map +1 -0
  28. package/dist/umd/vest-utils.production.js +2 -0
  29. package/dist/umd/vest-utils.production.js.map +1 -0
  30. package/minifyObject/package.json +8 -12
  31. package/package.json +58 -43
  32. package/types/{exports/minifyObject.d.cts → minifyObject.d.ts} +2 -4
  33. package/types/minifyObject.d.ts.map +1 -0
  34. package/types/vest-utils.d.ts +143 -245
  35. package/types/vest-utils.d.ts.map +1 -0
  36. package/vitest.config.ts +45 -9
  37. package/dist/chunk-CLMFDpHK.mjs +0 -18
  38. package/dist/exports/minifyObject.cjs +0 -114
  39. package/dist/exports/minifyObject.cjs.map +0 -1
  40. package/dist/exports/minifyObject.mjs +0 -113
  41. package/dist/exports/minifyObject.mjs.map +0 -1
  42. package/dist/exports/standardSchemaSpec.cjs +0 -0
  43. package/dist/exports/standardSchemaSpec.mjs +0 -1
  44. package/dist/isEmpty-BBxAFjjm.mjs +0 -103
  45. package/dist/isEmpty-BBxAFjjm.mjs.map +0 -1
  46. package/dist/isEmpty-BuEa-96Q.cjs +0 -235
  47. package/dist/isEmpty-BuEa-96Q.cjs.map +0 -1
  48. package/dist/vest-utils.cjs +0 -510
  49. package/dist/vest-utils.cjs.map +0 -1
  50. package/dist/vest-utils.mjs +0 -421
  51. package/dist/vest-utils.mjs.map +0 -1
  52. package/src/Brand.ts +0 -9
  53. package/src/IO.ts +0 -2
  54. package/src/Predicates.ts +0 -13
  55. package/src/Result.ts +0 -121
  56. package/src/SimpleStateMachine.ts +0 -157
  57. package/src/StringObject.ts +0 -6
  58. package/src/__tests__/Architecture.test.ts +0 -69
  59. package/src/__tests__/Predicates.test.ts +0 -118
  60. package/src/__tests__/Result.test.ts +0 -284
  61. package/src/__tests__/SimpleStateMachine.test.ts +0 -425
  62. package/src/__tests__/StringObject.test.ts +0 -18
  63. package/src/__tests__/asArray.test.ts +0 -14
  64. package/src/__tests__/bindNot.test.ts +0 -39
  65. package/src/__tests__/bus.test.ts +0 -135
  66. package/src/__tests__/cache.test.ts +0 -139
  67. package/src/__tests__/callEach.test.ts +0 -20
  68. package/src/__tests__/defaultTo.test.ts +0 -52
  69. package/src/__tests__/deferThrow.test.ts +0 -26
  70. package/src/__tests__/either.test.ts +0 -17
  71. package/src/__tests__/freezeAssign.test.ts +0 -24
  72. package/src/__tests__/greaterThan.test.ts +0 -68
  73. package/src/__tests__/invariant.test.ts +0 -47
  74. package/src/__tests__/isArray.test.ts +0 -16
  75. package/src/__tests__/isBoolean.test.ts +0 -16
  76. package/src/__tests__/isEmpty.test.ts +0 -55
  77. package/src/__tests__/isEmptySet.test.ts +0 -22
  78. package/src/__tests__/isNull.test.ts +0 -26
  79. package/src/__tests__/isNumeric.test.ts +0 -27
  80. package/src/__tests__/isPositive.test.ts +0 -38
  81. package/src/__tests__/isPromise.test.ts +0 -17
  82. package/src/__tests__/isString.test.ts +0 -13
  83. package/src/__tests__/isUndefined.test.ts +0 -27
  84. package/src/__tests__/isUnsafeKey.test.ts +0 -22
  85. package/src/__tests__/lengthEquals.test.ts +0 -58
  86. package/src/__tests__/longerThan.test.ts +0 -58
  87. package/src/__tests__/mapFirst.test.ts +0 -31
  88. package/src/__tests__/nonnullish.test.ts +0 -25
  89. package/src/__tests__/noop.test.ts +0 -12
  90. package/src/__tests__/numberEquals.test.ts +0 -67
  91. package/src/__tests__/optionalFunctionValue.test.ts +0 -29
  92. package/src/__tests__/seq.test.ts +0 -29
  93. package/src/__tests__/text.test.ts +0 -41
  94. package/src/__tests__/tinyState.test.ts +0 -68
  95. package/src/__tests__/toNumber.test.ts +0 -39
  96. package/src/__tests__/vest-utils.test.ts +0 -13
  97. package/src/__tests__/withCatch.test.ts +0 -17
  98. package/src/__tests__/withResolvers.test.ts +0 -45
  99. package/src/asArray.ts +0 -3
  100. package/src/assign.ts +0 -1
  101. package/src/bindNot.ts +0 -3
  102. package/src/bus.ts +0 -52
  103. package/src/cache.ts +0 -68
  104. package/src/callEach.ts +0 -5
  105. package/src/defaultTo.ts +0 -9
  106. package/src/deferThrow.ts +0 -7
  107. package/src/dynamicValue.ts +0 -9
  108. package/src/either.ts +0 -3
  109. package/src/exports/__tests__/minifyObject.security.test.ts +0 -65
  110. package/src/exports/__tests__/minifyObject.test.ts +0 -281
  111. package/src/exports/minifyObject.ts +0 -198
  112. package/src/exports/standardSchemaSpec.ts +0 -70
  113. package/src/freezeAssign.ts +0 -5
  114. package/src/globals.d.ts +0 -3
  115. package/src/greaterThan.ts +0 -8
  116. package/src/hasOwnProperty.ts +0 -9
  117. package/src/invariant.ts +0 -19
  118. package/src/isArrayValue.ts +0 -11
  119. package/src/isBooleanValue.ts +0 -3
  120. package/src/isEmpty.ts +0 -18
  121. package/src/isEmptySet.ts +0 -15
  122. package/src/isFunction.ts +0 -5
  123. package/src/isNull.ts +0 -7
  124. package/src/isNullish.ts +0 -10
  125. package/src/isNumeric.ts +0 -11
  126. package/src/isPositive.ts +0 -5
  127. package/src/isPromise.ts +0 -5
  128. package/src/isStringValue.ts +0 -3
  129. package/src/isUndefined.ts +0 -7
  130. package/src/isUnsafeKey.ts +0 -3
  131. package/src/lengthEquals.ts +0 -11
  132. package/src/longerThan.ts +0 -8
  133. package/src/mapFirst.ts +0 -25
  134. package/src/nonnullish.ts +0 -9
  135. package/src/noop.ts +0 -1
  136. package/src/numberEquals.ts +0 -11
  137. package/src/seq.ts +0 -16
  138. package/src/text.ts +0 -20
  139. package/src/tinyState.ts +0 -28
  140. package/src/toNumber.ts +0 -11
  141. package/src/utilityTypes.ts +0 -25
  142. package/src/valueIsObject.ts +0 -5
  143. package/src/vest-utils.ts +0 -73
  144. package/src/withCatch.ts +0 -11
  145. package/src/withResolvers.ts +0 -33
  146. package/standardSchemaSpec/package.json +0 -14
  147. package/types/exports/minifyObject.d.cts.map +0 -1
  148. package/types/exports/minifyObject.d.mts +0 -7
  149. package/types/exports/minifyObject.d.mts.map +0 -1
  150. package/types/exports/standardSchemaSpec.d.cts +0 -59
  151. package/types/exports/standardSchemaSpec.d.cts.map +0 -1
  152. package/types/exports/standardSchemaSpec.d.mts +0 -59
  153. package/types/exports/standardSchemaSpec.d.mts.map +0 -1
  154. package/types/vest-utils.d.cts +0 -296
  155. package/types/vest-utils.d.cts.map +0 -1
  156. package/types/vest-utils.d.mts +0 -295
  157. package/types/vest-utils.d.mts.map +0 -1
@@ -1,22 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import isUnsafeKey from '../isUnsafeKey';
3
-
4
- describe('isUnsafeKey', () => {
5
- it('should return true for __proto__', () => {
6
- expect(isUnsafeKey('__proto__')).toBe(true);
7
- });
8
-
9
- it('should return true for constructor', () => {
10
- expect(isUnsafeKey('constructor')).toBe(true);
11
- });
12
-
13
- it('should return true for prototype', () => {
14
- expect(isUnsafeKey('prototype')).toBe(true);
15
- });
16
-
17
- it('should return false for other keys', () => {
18
- expect(isUnsafeKey('someKey')).toBe(false);
19
- expect(isUnsafeKey('toString')).toBe(false);
20
- expect(isUnsafeKey('valueOf')).toBe(false);
21
- });
22
- });
@@ -1,58 +0,0 @@
1
- import { faker } from '@faker-js/faker';
2
- import { lengthEquals } from '../lengthEquals';
3
- import { describe, it, expect } from 'vitest';
4
-
5
- describe('Tests lengthEquals rule', () => {
6
- const length = 10;
7
- const word = faker.lorem.word();
8
- const boolean = faker.datatype.boolean();
9
-
10
- describe('First argument is array or string', () => {
11
- describe('When first argument is equal to a given value', () => {
12
- it('Should return true for an array equal to length', () => {
13
- expect(lengthEquals(new Array(length), length)).toBe(true);
14
- });
15
-
16
- it('Should return true for a string equal to word length', () => {
17
- expect(lengthEquals(word, word.length)).toBe(true);
18
- });
19
- });
20
-
21
- describe('When first argument is shorter', () => {
22
- it('Should return false for an array shorter than length', () => {
23
- expect(lengthEquals(new Array(length), length + 1)).toBe(false);
24
- });
25
-
26
- it('Should return false for a string shorter than word length', () => {
27
- expect(lengthEquals(word, word.length + 1)).toBe(false);
28
- });
29
- });
30
-
31
- describe('When first argument is longer', () => {
32
- it('Should return false for an array longer than length', () => {
33
- expect(lengthEquals(new Array(length), length - 1)).toBe(false);
34
- });
35
-
36
- it('Should return false for a string longer than word length', () => {
37
- expect(lengthEquals(word, word.length - 1)).toBe(false);
38
- });
39
- });
40
- });
41
-
42
- describe("First argument isn't array or string", () => {
43
- it('Should throw error', () => {
44
- // @ts-expect-error - testing wrong input
45
- expect(() => lengthEquals(undefined, 0)).toThrow(TypeError);
46
- });
47
-
48
- it('Should return false for number argument', () => {
49
- // @ts-expect-error - testing wrong input
50
- expect(lengthEquals(100, 0)).toBe(false);
51
- });
52
-
53
- it('Should return false for boolean argument', () => {
54
- // @ts-expect-error - testing wrong input
55
- expect(lengthEquals(boolean, 0)).toBe(false);
56
- });
57
- });
58
- });
@@ -1,58 +0,0 @@
1
- import { faker } from '@faker-js/faker';
2
- import { longerThan } from '../longerThan';
3
- import { describe, it, expect } from 'vitest';
4
-
5
- describe('Tests longerThan rule', () => {
6
- const length = 10;
7
- const word = faker.lorem.word();
8
- const boolean = faker.datatype.boolean();
9
-
10
- describe('First argument is array or string', () => {
11
- describe('When first argument is longer', () => {
12
- it('Should return true for an array longer than length', () => {
13
- expect(longerThan(new Array(length), length - 1)).toBe(true);
14
- });
15
-
16
- it('Should return true for a string longer than word length', () => {
17
- expect(longerThan(word, word.length - 1)).toBe(true);
18
- });
19
- });
20
-
21
- describe('When first argument is shorter', () => {
22
- it('Should return false for an array shorter than length', () => {
23
- expect(longerThan(new Array(length), length + 1)).toBe(false);
24
- });
25
-
26
- it('Should return false for a string shorter than word length', () => {
27
- expect(longerThan(word, word.length + 1)).toBe(false);
28
- });
29
- });
30
-
31
- describe('When first argument is equal to a given value', () => {
32
- it('Should return false for an array equal to length', () => {
33
- expect(longerThan(new Array(length), length)).toBe(false);
34
- });
35
-
36
- it('Should return false for a string equal to word length', () => {
37
- expect(longerThan(word, word.length)).toBe(false);
38
- });
39
- });
40
- });
41
-
42
- describe("First argument isn't array or string", () => {
43
- it('Should throw error', () => {
44
- // @ts-expect-error - testing wrong input
45
- expect(() => longerThan(undefined, 0)).toThrow(TypeError);
46
- });
47
-
48
- it('Should return false for number argument', () => {
49
- // @ts-expect-error - testing wrong input
50
- expect(longerThan(length, 0)).toBe(false);
51
- });
52
-
53
- it('Should return false for boolean argument', () => {
54
- // @ts-expect-error - testing wrong input
55
- expect(longerThan(boolean, 0)).toBe(false);
56
- });
57
- });
58
- });
@@ -1,31 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- import { mapFirst } from '../vest-utils';
4
-
5
- describe('mapFirst', () => {
6
- it('should return the broken out result', () => {
7
- const result = mapFirst([1, 2, 3], (value, breakout) => {
8
- breakout(value === 3, { pass: true });
9
- });
10
-
11
- expect(result).toEqual({ pass: true });
12
- });
13
-
14
- it('Should respect the breakout conditional', () => {
15
- const result = mapFirst([1, 2, 3], (_, breakout) => {
16
- breakout(false, 0);
17
- breakout(false, 0);
18
- breakout(true, 1);
19
- });
20
-
21
- expect(result).toBe(1);
22
- });
23
-
24
- describe('When not broken out', () => {
25
- it('Should return undefined', () => {
26
- const result = mapFirst([1, 2, 3], () => {});
27
-
28
- expect(result).toBeUndefined();
29
- });
30
- });
31
- });
@@ -1,25 +0,0 @@
1
- import { nonnullish } from '../nonnullish';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('nonnullish', () => {
5
- it('should return the value if it is not null or undefined', () => {
6
- const value = 'hello';
7
- expect(nonnullish(value)).toBe(value);
8
- });
9
-
10
- it('should throw an error if the value is null', () => {
11
- const value = null;
12
- expect(() => nonnullish(value)).toThrow();
13
- });
14
-
15
- it('should throw an error if the value is undefined', () => {
16
- const value = undefined;
17
- expect(() => nonnullish(value)).toThrow();
18
- });
19
-
20
- it('should throw a custom error message if provided', () => {
21
- const value = null;
22
- const errorMessage = 'Value must be defined';
23
- expect(() => nonnullish(value, errorMessage)).toThrow(errorMessage);
24
- });
25
- });
@@ -1,12 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { noop } from '../noop';
3
-
4
- describe('noop', () => {
5
- it('should be a function', () => {
6
- expect(typeof noop).toBe('function');
7
- });
8
-
9
- it('should return undefined', () => {
10
- expect(noop()).toBeUndefined();
11
- });
12
- });
@@ -1,67 +0,0 @@
1
- import { faker } from '@faker-js/faker';
2
- import { numberEquals } from '../numberEquals';
3
- import { describe, it, expect, beforeEach } from 'vitest';
4
-
5
- describe('Tests numberEquals rule', () => {
6
- describe('Arguments are numbers', () => {
7
- let arg0: number;
8
- beforeEach(() => {
9
- arg0 = faker.number.int();
10
- });
11
-
12
- describe('When first argument is larger', () => {
13
- it('Should return false', () => {
14
- expect(numberEquals(arg0, arg0 - 1)).toBe(false);
15
- });
16
- });
17
-
18
- describe('When first argument is smaller', () => {
19
- it('Should return false', () => {
20
- expect(numberEquals(arg0, arg0 + 1)).toBe(false);
21
- });
22
- });
23
-
24
- describe('When values are equal', () => {
25
- it('Should return true', () => {
26
- expect(numberEquals(arg0, arg0)).toBe(true);
27
- });
28
- });
29
- });
30
-
31
- describe('Arguments are numeric strings', () => {
32
- let arg0: string;
33
-
34
- beforeEach(() => {
35
- arg0 = faker.number.int().toString();
36
- });
37
-
38
- describe('When first argument is larger', () => {
39
- it('Should return false', () => {
40
- expect(numberEquals(`${arg0}`, `${Number(arg0) - 1}`)).toBe(false);
41
- });
42
- });
43
-
44
- describe('When first argument is smaller', () => {
45
- it('Should return false', () => {
46
- expect(numberEquals(`${arg0}`, `${arg0 + 1}`)).toBe(false);
47
- });
48
- });
49
-
50
- describe('When values are equal', () => {
51
- it('Should return true', () => {
52
- expect(numberEquals('100', '100')).toBe(true);
53
- });
54
- });
55
- });
56
-
57
- describe('Arguments are non numeric', () => {
58
- [faker.lorem.word(), `${faker.number.int()}`.split(''), {}].forEach(
59
- element => {
60
- it('Should return false', () => {
61
- // @ts-expect-error - testing invalid input
62
- expect(numberEquals(element, 0)).toBe(false);
63
- });
64
- },
65
- );
66
- });
67
- });
@@ -1,29 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
-
3
- import { dynamicValue } from '../vest-utils';
4
-
5
- describe('dynamicValue', () => {
6
- describe('When not a function', () => {
7
- it.each([0, undefined, false, true, 1, [], {}, null, NaN])(
8
- 'Should return the same value',
9
- value => {
10
- expect(dynamicValue(value)).toBe(value);
11
- },
12
- );
13
- });
14
-
15
- describe('When value is a function', () => {
16
- it('Should call the function and return its return value', () => {
17
- const value = vi.fn(() => 'return value');
18
-
19
- expect(dynamicValue(value)).toBe('return value');
20
- expect(value).toHaveBeenCalled();
21
- });
22
- it('Should run with arguments array', () => {
23
- const value = vi.fn((...args) => args.join('|'));
24
- const args = [1, 2, 3, 4];
25
- expect(dynamicValue(value, ...args)).toBe('1|2|3|4');
26
- expect(value).toHaveBeenCalledWith(...args);
27
- });
28
- });
29
- });
@@ -1,29 +0,0 @@
1
- import seq, { genSeq } from '../seq';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('lib:seq', () => {
5
- it('Should return a new id on each run', () => {
6
- Array.from({ length: 100 }, () => seq()).reduce((existing, seq) => {
7
- expect(existing).not.toHaveProperty(seq.toString());
8
- Object.assign(existing, { [seq]: true });
9
- expect(existing).toHaveProperty(seq.toString());
10
- return existing;
11
- }, {});
12
- });
13
-
14
- describe('genSeq', () => {
15
- it('Creates a namespaced sequence', () => {
16
- const seq = genSeq('test');
17
- expect(seq()).toBe('test_0');
18
- expect(seq()).toBe('test_1');
19
- expect(seq()).toBe('test_2');
20
-
21
- const seq2 = genSeq('test2');
22
- expect(seq2()).toBe('test2_0');
23
- expect(seq2()).toBe('test2_1');
24
- expect(seq2()).toBe('test2_2');
25
-
26
- expect(seq()).toBe('test_3');
27
- });
28
- });
29
- });
@@ -1,41 +0,0 @@
1
- import { text } from '../text';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('text', () => {
5
- describe('named substitutions (object)', () => {
6
- describe('When all substitutions exist', () => {
7
- it('Should replace delimited placeholders', () => {
8
- expect(text('this {t} an example', { t: 'was' })).toBe(
9
- 'this was an example',
10
- );
11
- expect(text('this {t1} {t2} example', { t1: 'was', t2: 'one' })).toBe(
12
- 'this was one example',
13
- );
14
- });
15
- });
16
-
17
- describe('When a placeholder repeats', () => {
18
- it('Should use the same substitution multiple times', () => {
19
- expect(text('{n} {n} {n}', { n: 1 })).toBe('1 1 1');
20
- });
21
- });
22
-
23
- describe('When a substitution is missing', () => {
24
- it('Should keep the placeholder', () => {
25
- expect(text('{no}', { yes: 'yes' })).toBe('{no}');
26
- });
27
- });
28
- });
29
-
30
- describe('Positional substitutions', () => {
31
- it('should use substitutions one by one', () => {
32
- expect(text('{n} {n} {x} {y}', 1, 2, 3, 4)).toBe('1 2 3 4');
33
- });
34
-
35
- describe('When there are not enough substitutions', () => {
36
- it('Should default to the placeholder', () => {
37
- expect(text('{n} {n} {x} {y}', 1, 2)).toBe('1 2 {x} {y}');
38
- });
39
- });
40
- });
41
- });
@@ -1,68 +0,0 @@
1
- import { createTinyState } from '../tinyState';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('tinyTest', () => {
5
- it('Should be a function', () => {
6
- expect(typeof createTinyState).toBe('function');
7
- });
8
-
9
- it('Should return a function', () => {
10
- expect(typeof createTinyState(1)).toBe('function');
11
- });
12
-
13
- it('Should return a function that returns an array', () => {
14
- expect(Array.isArray(createTinyState(1)())).toBe(true);
15
- });
16
-
17
- it('Should return a function that returns an array with three items', () => {
18
- expect(createTinyState(1)()).toHaveLength(3);
19
- });
20
-
21
- it('Should return a function that returns an array with three items, the first being the initial value', () => {
22
- expect(createTinyState('initial_value')()[0]).toBe('initial_value');
23
-
24
- const initialValue = {};
25
- expect(createTinyState(initialValue)()[0]).toBe(initialValue);
26
- });
27
-
28
- it('Should return a function that returns an array with three items, the second being a function', () => {
29
- expect(typeof createTinyState(1)()[1]).toBe('function');
30
- });
31
-
32
- it('Should return a function that returns an array with three items, the third being a function', () => {
33
- expect(typeof createTinyState(1)()[2]).toBe('function');
34
- });
35
-
36
- it('Updates the value when the second item is called', () => {
37
- const testState = createTinyState('initial_value');
38
-
39
- {
40
- const [, setValue] = testState();
41
- setValue('new_value');
42
- }
43
-
44
- {
45
- const [value] = testState();
46
- expect(value).toBe('new_value');
47
- }
48
- });
49
-
50
- it('resets the value when the third item is called', () => {
51
- const testState = createTinyState('initial_value');
52
-
53
- {
54
- const [, setValue] = testState();
55
- setValue('new_value');
56
- }
57
-
58
- {
59
- const [, , resetValue] = testState();
60
- resetValue();
61
- }
62
-
63
- {
64
- const [value] = testState();
65
- expect(value).toBe('initial_value');
66
- }
67
- });
68
- });
@@ -1,39 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- import { isFailure, isSuccess, unwrap } from '../Result';
4
- import { toNumber } from '../toNumber';
5
-
6
- describe('toNumber', () => {
7
- describe('Successful conversions', () => {
8
- it.each([
9
- [1, 1],
10
- [0, 0],
11
- [-1, -1],
12
- [1.5, 1.5],
13
- ['1', 1],
14
- ['0', 0],
15
- ['-1', -1],
16
- ['1.5', 1.5],
17
- [true, 1],
18
- [false, 0],
19
- [null, 0],
20
- ['', 0],
21
- [' ', 0],
22
- [[], 0],
23
- [[1], 1],
24
- ])('should convert %s to %s', (input, expected) => {
25
- const result = toNumber(input);
26
- expect(isSuccess(result)).toBe(true);
27
- expect(unwrap(result)).toBe(expected);
28
- });
29
- });
30
-
31
- describe('Failed conversions', () => {
32
- it.each([undefined, 'abc', '1a', {}, [1, 2], NaN])(
33
- 'should fail to convert %s',
34
- input => {
35
- expect(isFailure(toNumber(input))).toBe(true);
36
- },
37
- );
38
- });
39
- });
@@ -1,13 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import * as vestUtils from '../vest-utils';
3
-
4
- describe('vest-utils exports', () => {
5
- it('should export expected utilities', () => {
6
- expect(vestUtils.noop).toBeDefined();
7
- expect(vestUtils.isFunction).toBeDefined();
8
- expect(vestUtils.withResolvers).toBeDefined();
9
- // Verify a few others to ensure the file is processed
10
- expect(vestUtils.defaultTo).toBeDefined();
11
- expect(vestUtils.assign).toBeDefined();
12
- });
13
- });
@@ -1,17 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { withCatch } from '../withCatch';
3
-
4
- describe('withCatch', () => {
5
- it('should return the result of the callback if it succeeds', () => {
6
- const fn = withCatch(() => 'success');
7
- expect(fn()).toBe('success');
8
- });
9
-
10
- it('should return the error if the callback throws', () => {
11
- const error = new Error('failure');
12
- const fn = withCatch(() => {
13
- throw error;
14
- });
15
- expect(fn()).toBe(error);
16
- });
17
- });
@@ -1,45 +0,0 @@
1
- import { describe, it, expect, afterEach } from 'vitest';
2
- import { withResolvers } from '../withResolvers';
3
-
4
- describe('withResolvers', () => {
5
- const originalWithResolvers = Promise.withResolvers;
6
-
7
- afterEach(() => {
8
- // Restore the original implementation
9
- if (originalWithResolvers) {
10
- Promise.withResolvers = originalWithResolvers;
11
- } else {
12
- // @ts-ignore
13
- delete Promise.withResolvers;
14
- }
15
- });
16
-
17
- it('should return a promise, resolve, and reject', () => {
18
- const { promise, resolve, reject } = withResolvers();
19
- expect(promise).toBeInstanceOf(Promise);
20
- expect(typeof resolve).toBe('function');
21
- expect(typeof reject).toBe('function');
22
- });
23
-
24
- it('should resolve the promise', async () => {
25
- const { promise, resolve } = withResolvers<string>();
26
- resolve('success');
27
- await expect(promise).resolves.toBe('success');
28
- });
29
-
30
- it('should reject the promise', async () => {
31
- const { promise, reject } = withResolvers<string>();
32
- const error = new Error('fail');
33
- reject(error);
34
- await expect(promise).rejects.toBe(error);
35
- });
36
-
37
- it('should use the polyfill if Promise.withResolvers is not defined', async () => {
38
- // @ts-ignore
39
- Promise.withResolvers = undefined;
40
-
41
- const { promise, resolve } = withResolvers<string>();
42
- resolve('polyfill');
43
- await expect(promise).resolves.toBe('polyfill');
44
- });
45
- });
package/src/asArray.ts DELETED
@@ -1,3 +0,0 @@
1
- export default function asArray<T>(possibleArg: T | T[]): T[] {
2
- return ([] as T[]).concat(possibleArg);
3
- }
package/src/assign.ts DELETED
@@ -1 +0,0 @@
1
- export default Object.assign;
package/src/bindNot.ts DELETED
@@ -1,3 +0,0 @@
1
- export default function bindNot<T extends (...args: any[]) => unknown>(fn: T) {
2
- return (...args: Parameters<T>): boolean => !fn(...args);
3
- }
package/src/bus.ts DELETED
@@ -1,52 +0,0 @@
1
- import type { CB } from './utilityTypes';
2
-
3
- const EVENT_WILDCARD = '*';
4
- type TEventsWildcard = typeof EVENT_WILDCARD;
5
-
6
- export function createBus<
7
- TEvents extends Record<string, any> = Record<string, any>,
8
- >(): BusType<TEvents> {
9
- const listeners = {} as Record<keyof TEvents | TEventsWildcard, CB[]>;
10
-
11
- return {
12
- emit(event: keyof TEvents | TEventsWildcard, payload?: any) {
13
- getListeners(event)
14
- .concat(getListeners(EVENT_WILDCARD))
15
- .forEach(handler => {
16
- handler(payload);
17
- });
18
- },
19
-
20
- on(event: keyof TEvents | TEventsWildcard, handler: CB): OnReturn {
21
- listeners[event] = getListeners(event).concat(handler);
22
-
23
- return {
24
- off() {
25
- listeners[event] = getListeners(event).filter(h => h !== handler);
26
- },
27
- };
28
- },
29
- };
30
-
31
- function getListeners(event: keyof TEvents | TEventsWildcard): CB[] {
32
- return listeners[event] || [];
33
- }
34
- }
35
-
36
- type OnReturn = { off: CB<void> };
37
-
38
- export type BusType<TEvents extends Record<string, any>> = {
39
- on<T extends keyof TEvents>(
40
- event: T,
41
- handler: (payload: TEvents[T]) => void,
42
- ): OnReturn;
43
- on(event: TEventsWildcard, handler: (payload: any) => void): OnReturn;
44
-
45
- emit<T extends keyof TEvents>(
46
- event: T,
47
- ...args: TEvents[T] extends void
48
- ? [payload?: TEvents[T]]
49
- : [payload: TEvents[T]]
50
- ): void;
51
- emit(event: TEventsWildcard, payload?: any): void;
52
- };