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,139 +0,0 @@
1
- import _ from 'lodash';
2
- import { describe, it, expect, beforeEach, vi } from 'vitest';
3
-
4
- import { cache } from '../vest-utils';
5
-
6
- describe('lib: cache', () => {
7
- let c: ReturnType<typeof cache>;
8
-
9
- beforeEach(() => {
10
- c = cache();
11
- });
12
- it('should return a function', () => {
13
- expect(typeof cache()).toBe('function');
14
- });
15
-
16
- it('Should create a new function on each call', () => {
17
- expect(cache()).not.toBe(cache());
18
- });
19
-
20
- describe('when cacheaction is a value rather than a function', () => {
21
- it('should store the value if no hit', () => {
22
- const res = c([1, 2, 3], 123);
23
- expect(res).toBe(123);
24
- });
25
- });
26
-
27
- describe('on cache miss', () => {
28
- it('Should call passed cache action function and return its value', () => {
29
- const cacheAction = vi.fn(() => ({}));
30
- const res = c([{}], cacheAction);
31
- expect(cacheAction).toHaveBeenCalledTimes(1);
32
- expect(res).toBe(cacheAction.mock.results[0].value);
33
- });
34
- });
35
-
36
- describe('On cache hit', () => {
37
- it('Should return cached result', () => {
38
- const cacheAction = vi.fn(() => {
39
- Math.random();
40
- });
41
- const depsArray = [true, false, {}];
42
- const res1 = c(depsArray, cacheAction);
43
- expect(res1).toBe(cacheAction.mock.results[0].value);
44
- const res2 = c(depsArray, cacheAction);
45
- expect(res2).toBe(res1);
46
- });
47
-
48
- it('Should return without calling the cache action', () => {
49
- const cacheAction = vi.fn();
50
- const depsArray = [Math.random()];
51
- c(depsArray, cacheAction);
52
- expect(cacheAction).toHaveBeenCalledTimes(1);
53
- c(depsArray, cacheAction);
54
- expect(cacheAction).toHaveBeenCalledTimes(1);
55
- });
56
-
57
- it('Should limit cache results to `maxSize`', () => {
58
- const cacheSize = _.random(5, 10);
59
- const callCount = _.random(cacheSize, cacheSize + 10);
60
- const diff = callCount - cacheSize;
61
- /**
62
- * Doing a nested check to combat the auto cleanup of the cache.
63
- * Otherwise, each access to the cache would purge the oldest results
64
- * and we wouldn't get an accurate read - so instantiating a new cache
65
- * for each index is a good workaround.
66
- */
67
- Array.from({ length: callCount }, (_, i) => {
68
- const c = cache(/*maxSize*/ cacheSize);
69
- const results = Array.from({ length: callCount }, (_, j) =>
70
- c([j], Math.random),
71
- );
72
-
73
- if (i < diff) {
74
- // Here we generate a fresh `null` result
75
- expect(c([i], () => null)).toBeNull();
76
- } else {
77
- // Here we retrieve an existing result
78
- expect(c([i], () => null)).toBe(results[i]);
79
- }
80
- });
81
- });
82
- });
83
- it('Should take into account the deps array in its entirety', () => {
84
- const deps = Array.from({ length: 100 }, () =>
85
- _.sample([{}, false, Math.random(), true, () => null]),
86
- );
87
- const c = cache();
88
- const res = c([...deps], Math.random);
89
- expect(c([...deps], () => undefined)).toBe(res);
90
- const sliced = deps.slice(0, -1);
91
- expect(c(sliced, () => null)).toBeNull();
92
- });
93
-
94
- describe('cache.get', () => {
95
- describe('On cache miss', () => {
96
- it('Should return null', () => {
97
- expect(c.get([1, 2, 3])).toBeNull();
98
- c([1, 2, 3], Math.random);
99
- expect(c.get([1, 2, '3'])).toBeNull();
100
- });
101
- });
102
-
103
- describe('On cache hit', () => {
104
- it('Should return cached key and item from cache storage', () => {
105
- const res = c([1, 2, 3], Math.random);
106
- expect(c.get([1, 2, 3])?.[0]).toEqual([1, 2, 3]);
107
- expect(c.get([1, 2, 3])?.[1]).toEqual(res);
108
- });
109
- });
110
- });
111
-
112
- describe('cache.set', () => {
113
- it('Should set a value to the cache storage by its dependencies', () => {
114
- const deps = [1, 2, 3];
115
- const res = Math.random();
116
- c.set(deps, res);
117
- expect(c.get(deps)?.[1]).toBe(res);
118
- });
119
-
120
- it('Should update an existing value in the cache storage by its dependencies', () => {
121
- const deps = [1, 2, 3];
122
- const res = Math.random();
123
- c.set(deps, res);
124
- const updatedRes = Math.random();
125
- c.set(deps, updatedRes);
126
- expect(c.get(deps)?.[1]).toBe(updatedRes);
127
- });
128
- });
129
-
130
- describe('cache.invalidate', () => {
131
- it('Should remove cached item from cache storage by its dependencies', () => {
132
- const deps = [1, 2, 3];
133
- c(deps, Math.random);
134
- expect(c.get(deps)).not.toBeNull();
135
- c.invalidate(deps);
136
- expect(c.get(deps)).toBeNull();
137
- });
138
- });
139
- });
@@ -1,20 +0,0 @@
1
- import callEach from '../callEach';
2
- import { describe, it, expect, vi } from 'vitest';
3
-
4
- describe('callEach', () => {
5
- it('should call all functions in the array', () => {
6
- const mockFn1 = vi.fn();
7
- const mockFn2 = vi.fn();
8
- const mockFn3 = vi.fn();
9
-
10
- callEach([mockFn1, mockFn2, mockFn3]);
11
-
12
- expect(mockFn1).toHaveBeenCalled();
13
- expect(mockFn2).toHaveBeenCalled();
14
- expect(mockFn3).toHaveBeenCalled();
15
- });
16
-
17
- it('should not throw an error if the array is empty', () => {
18
- expect(() => callEach([])).not.toThrow();
19
- });
20
- });
@@ -1,52 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
-
3
- import { defaultTo } from '../vest-utils';
4
-
5
- describe('defaultTo', () => {
6
- describe('When value is a function', () => {
7
- it('Should call the function', () => {
8
- const value = vi.fn(() => 'return value');
9
-
10
- expect(defaultTo(value, 'fallback value')).toBe('return value');
11
- expect(value).toHaveBeenCalled();
12
- });
13
- describe('When value is nullish', () => {
14
- it('Should return fallback value', () => {
15
- expect(defaultTo(null, 'fallback value')).toBe('fallback value');
16
- expect(defaultTo(undefined, 'fallback value')).toBe('fallback value');
17
- });
18
- });
19
-
20
- describe('When value is not nullish', () => {
21
- it('Should use value', () => {
22
- expect(defaultTo('value', 'fallback value')).toBe('value');
23
- });
24
- });
25
- });
26
-
27
- describe('When value is not a function', () => {
28
- describe('When the value is nullish', () => {
29
- it('Should return fallback value', () => {
30
- expect(defaultTo(null, 'fallback value')).toBe('fallback value');
31
- expect(defaultTo(undefined, 'fallback value')).toBe('fallback value');
32
- });
33
- });
34
- describe('When the value is not nullish', () => {
35
- it.each([0, false, true, 1, [], {}, NaN])(
36
- 'Should return the same value',
37
- value => {
38
- expect(defaultTo(value, 'fallback value')).toBe(value);
39
- },
40
- );
41
- });
42
- });
43
-
44
- describe('When the fallback value is a function', () => {
45
- it('Should call the function and return its return value', () => {
46
- const fallbackValue = vi.fn(() => 'fallback value');
47
-
48
- expect(defaultTo(null, fallbackValue)).toBe('fallback value');
49
- expect(fallbackValue).toHaveBeenCalled();
50
- });
51
- });
52
- });
@@ -1,26 +0,0 @@
1
- import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
2
-
3
- import { deferThrow } from '../vest-utils';
4
- // @ts-ignore
5
- const _to = global.setTimeout;
6
- describe('deferThrow', () => {
7
- beforeEach(() => {
8
- // @ts-ignore
9
- global.setTimeout = vi.fn();
10
- });
11
-
12
- afterEach(() => {
13
- global.setTimeout = _to;
14
- });
15
- it('Should start a timer', () => {
16
- deferThrow();
17
- expect(global.setTimeout).toHaveBeenCalled();
18
- });
19
-
20
- it('Should throw a timed out error with the provided message', () => {
21
- deferThrow('message');
22
- // @ts-ignore
23
- const timeoutCB = global.setTimeout.mock.calls[0][0];
24
- expect(() => timeoutCB()).toThrow('message');
25
- });
26
- });
@@ -1,17 +0,0 @@
1
- import either from '../either';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('either', () => {
5
- it('returns true if one argument is truthy and the other is falsy', () => {
6
- expect(either(true, false)).toBe(true);
7
- expect(either(1, 0)).toBe(true);
8
- expect(either('hello', '')).toBe(true);
9
- });
10
-
11
- it('returns false if both arguments are truthy or falsy', () => {
12
- expect(either(true, true)).toBe(false);
13
- expect(either(false, false)).toBe(false);
14
- expect(either(1, 2)).toBe(false);
15
- expect(either('', null)).toBe(false);
16
- });
17
- });
@@ -1,24 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { freezeAssign } from '../freezeAssign';
3
-
4
- describe('freezeAssign', () => {
5
- it('Should assign properties and freeze the object', () => {
6
- const target = {};
7
- const source = { a: 1 };
8
- const result = freezeAssign(target, source);
9
-
10
- expect(result).toEqual({ a: 1 });
11
- expect(Object.isFrozen(result)).toBe(true);
12
- expect(result).toBe(target); // assign modifies and returns target
13
- });
14
-
15
- it('Should handle multiple sources', () => {
16
- const result = freezeAssign<{ a: number; b: number }>(
17
- {},
18
- { a: 1 },
19
- { b: 2 },
20
- );
21
- expect(result).toEqual({ a: 1, b: 2 });
22
- expect(Object.isFrozen(result)).toBe(true);
23
- });
24
- });
@@ -1,68 +0,0 @@
1
- import { faker } from '@faker-js/faker';
2
- import { greaterThan } from '../greaterThan';
3
- import { describe, it, expect, beforeEach } from 'vitest';
4
-
5
- describe('Tests greaterThan rule', () => {
6
- describe('Arguments are numbers', () => {
7
- let arg0: number;
8
-
9
- beforeEach(() => {
10
- arg0 = faker.number.int();
11
- });
12
-
13
- describe('When first argument is larger', () => {
14
- it('Should return true', () => {
15
- expect(greaterThan(arg0, arg0 - 1)).toBe(true);
16
- });
17
- });
18
-
19
- describe('When first argument is smaller', () => {
20
- it('Should return true', () => {
21
- expect(greaterThan(arg0, arg0 + 1)).toBe(false);
22
- });
23
- });
24
-
25
- describe('When values are equal', () => {
26
- it('Should return false', () => {
27
- expect(greaterThan(arg0, arg0)).toBe(false);
28
- });
29
- });
30
- });
31
-
32
- describe('Arguments are numeric strings', () => {
33
- let arg0: string;
34
-
35
- beforeEach(() => {
36
- arg0 = faker.number.int().toString();
37
- });
38
-
39
- describe('When first argument is larger', () => {
40
- it('Should return true', () => {
41
- expect(greaterThan('100', '99')).toBe(true);
42
- });
43
- });
44
-
45
- describe('When first argument is smaller', () => {
46
- it('Should return true', () => {
47
- expect(greaterThan(`${arg0}`, `${arg0 + 1}`)).toBe(false);
48
- });
49
- });
50
-
51
- describe('When values are equal', () => {
52
- it('Should return false', () => {
53
- expect(greaterThan(arg0, arg0)).toBe(false);
54
- });
55
- });
56
- });
57
-
58
- describe('Arguments are non numeric', () => {
59
- [faker.lorem.word(), `${faker.number.int()}`.split(''), {}].forEach(
60
- element => {
61
- it('Should return false', () => {
62
- // @ts-expect-error - testing invalid input
63
- expect(greaterThan(element, 0)).toBe(false);
64
- });
65
- },
66
- );
67
- });
68
- });
@@ -1,47 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- import { invariant } from '../vest-utils';
4
-
5
- describe('invariant', () => {
6
- it('should throw an error when condition is false', () => {
7
- expect(() => {
8
- invariant(false, 'message');
9
- }).toThrow(Error);
10
- });
11
-
12
- it("Should throw an error with the message if it's a string", () => {
13
- expect(() => {
14
- invariant(false, 'message');
15
- }).toThrow('message');
16
- });
17
-
18
- it('should contintue when condition is true', () => {
19
- expect(() => {
20
- invariant(true, 'message');
21
- }).not.toThrow();
22
- });
23
-
24
- describe('When passed message is a string object', () => {
25
- it('should throw the value of the string object', () => {
26
- expect(() => {
27
- invariant(false, new String('message'));
28
- }).toThrow('message');
29
- });
30
- });
31
-
32
- describe('Shen passed message is a function', () => {
33
- it('should throw the value of the function', () => {
34
- expect(() => {
35
- invariant(false, () => 'message');
36
- }).toThrow('message');
37
- });
38
- });
39
-
40
- describe('When message is falsy', () => {
41
- it('should throw an error with the message', () => {
42
- expect(() => {
43
- invariant(false, '');
44
- }).toThrow('');
45
- });
46
- });
47
- });
@@ -1,16 +0,0 @@
1
- import { isArray } from '../isArrayValue';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('Tests isArray rule', () => {
5
- it('Should return true for an empty array', () => {
6
- expect(isArray([])).toBe(true);
7
- });
8
-
9
- it('Should return true for an array with elements', () => {
10
- expect(isArray([1, 2, 3])).toBe(true);
11
- });
12
-
13
- it('Should return false a string', () => {
14
- expect(isArray('1')).toBe(false);
15
- });
16
- });
@@ -1,16 +0,0 @@
1
- import isBoolean from '../isBooleanValue';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('isBoolean', () => {
5
- it('Should pass for a boolean value', () => {
6
- expect(isBoolean(true)).toBe(true);
7
- expect(isBoolean(false)).toBe(true);
8
- expect(isBoolean(Boolean(1))).toBe(true);
9
- });
10
-
11
- it('Should fail for a non boolean value', () => {
12
- expect(isBoolean('true')).toBe(false);
13
- expect(isBoolean([false])).toBe(false);
14
- expect(isBoolean(null)).toBe(false);
15
- });
16
- });
@@ -1,55 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
-
3
- import { isEmpty } from '../vest-utils';
4
-
5
- describe('Tests isEmpty rule', () => {
6
- describe('Expect true', () => {
7
- it('Should return false for a non-empty array', () => {
8
- expect(isEmpty([1, 2, 3, 4, 5, 6])).toBe(false);
9
- });
10
-
11
- it('Should return true for an empty array', () => {
12
- expect(isEmpty([])).toBe(true);
13
- });
14
-
15
- it('Should return false for a non-empty objecd', () => {
16
- expect(isEmpty({ a: 1 })).toBe(false);
17
- });
18
-
19
- it('Should return true for an empty object', () => {
20
- expect(isEmpty({})).toBe(true);
21
- });
22
-
23
- it('Should return true for an empty string', () => {
24
- expect(isEmpty('')).toBe(true);
25
- });
26
-
27
- it('Should return false for a non empty string', () => {
28
- expect(isEmpty('hey')).toBe(false);
29
- });
30
-
31
- it('Should return true for zero', () => {
32
- expect(isEmpty(0)).toBe(true);
33
- });
34
-
35
- it('Should return false for one', () => {
36
- expect(isEmpty(1)).toBe(false);
37
- });
38
-
39
- it('Should return true for undefined', () => {
40
- expect(isEmpty(undefined)).toBe(true);
41
- });
42
-
43
- it('Should return true for null', () => {
44
- expect(isEmpty(null)).toBe(true);
45
- });
46
-
47
- it('Should return true for NaN', () => {
48
- expect(isEmpty(NaN)).toBe(true);
49
- });
50
-
51
- it('Should return false for a Symbol', () => {
52
- expect(isEmpty(Symbol('hey'))).toBe(false);
53
- });
54
- });
55
- });
@@ -1,22 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { isEmptySet, isNotEmptySet } from '../isEmptySet';
3
-
4
- describe('isEmptySet', () => {
5
- it('Should return true for an empty Set', () => {
6
- expect(isEmptySet(new Set())).toBe(true);
7
- });
8
-
9
- it('Should return false for a non-empty Set', () => {
10
- expect(isEmptySet(new Set([1]))).toBe(false);
11
- });
12
- });
13
-
14
- describe('isNotEmptySet', () => {
15
- it('Should return false for an empty Set', () => {
16
- expect(isNotEmptySet(new Set())).toBe(false);
17
- });
18
-
19
- it('Should return true for a non-empty Set', () => {
20
- expect(isNotEmptySet(new Set([1]))).toBe(true);
21
- });
22
- });
@@ -1,26 +0,0 @@
1
- import { isNull } from '../isNull';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('Tests isNull rule', () => {
5
- it('Should return true for `null` value', () => {
6
- expect(isNull(null)).toBe(true);
7
- });
8
-
9
- it.each([
10
- undefined,
11
- NaN,
12
- false,
13
- true,
14
- Object,
15
- Array(0),
16
- '',
17
- ' ',
18
- 0,
19
- 1,
20
- '0',
21
- '1',
22
- Function.prototype,
23
- ])('Should return false for %s value', v => {
24
- expect(isNull(v)).toBe(false);
25
- });
26
- });
@@ -1,27 +0,0 @@
1
- import { isNumeric } from '../isNumeric';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- const NUMERICS = ['-10', '0', 0xff, '0xFF', '8e5', '3.1415', +10, '0144'];
5
-
6
- const NON_NUMERICS = [
7
- '-0x42',
8
- '7.2acdgs',
9
- '',
10
- {},
11
- NaN,
12
- null,
13
- true,
14
- Infinity,
15
- undefined,
16
- ];
17
-
18
- describe('Tests isNumeric rule', () => {
19
- it('Should return true for numeric values', () => {
20
- NUMERICS.forEach(value => expect(isNumeric(value)).toBe(true));
21
- });
22
-
23
- it('Should return false for non numeric values', () => {
24
- // @ts-expect-error - testing bad usage
25
- NON_NUMERICS.forEach(value => expect(isNumeric(value)).toBe(false));
26
- });
27
- });
@@ -1,38 +0,0 @@
1
- import { isPositive } from '../isPositive';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('Test isPositive rule', () => {
5
- it('Should return false for zero', () => {
6
- expect(isPositive(0)).toBe(false);
7
- });
8
-
9
- describe('When argument is a positive number', () => {
10
- it('Should return true for positive number', () => {
11
- expect(isPositive(10)).toBe(true);
12
- });
13
- it('should return true for positive desimal number', () => {
14
- expect(isPositive(10.1)).toBe(true);
15
- });
16
- it('should return true for positive string number', () => {
17
- expect(isPositive('10')).toBe(true);
18
- });
19
- it('should return true for positive decimal string number', () => {
20
- expect(isPositive('10.10')).toBe(true);
21
- });
22
- });
23
-
24
- describe('When argument is a negative number', () => {
25
- it('Should return false for negative number', () => {
26
- expect(isPositive(-1)).toBe(false);
27
- });
28
- it('should return false for negative desimal number', () => {
29
- expect(isPositive(-1.1)).toBe(false);
30
- });
31
- it('should return false for negative string number', () => {
32
- expect(isPositive('-1')).toBe(false);
33
- });
34
- it('should return false for negative decimal string number', () => {
35
- expect(isPositive('-1.10')).toBe(false);
36
- });
37
- });
38
- });
@@ -1,17 +0,0 @@
1
- import isPromise from '../isPromise';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('isPromise', () => {
5
- it('should return true for a Promise', () => {
6
- expect(isPromise(new Promise(() => {}))).toBe(true);
7
- });
8
-
9
- it('should return false for a non-Promise value', () => {
10
- expect(isPromise('not a Promise')).toBe(false);
11
- });
12
-
13
- it('should return false for null or undefined', () => {
14
- expect(isPromise(null)).toBe(false);
15
- expect(isPromise(undefined)).toBe(false);
16
- });
17
- });
@@ -1,13 +0,0 @@
1
- import isStringValue from '../isStringValue';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('Tests isString rule', () => {
5
- it('Should return false for non-string values', () => {
6
- expect(isStringValue(42)).toBe(false);
7
- expect(isStringValue([])).toBe(false);
8
- });
9
-
10
- it('Should return true for string values', () => {
11
- expect(isStringValue('I love you')).toBe(true);
12
- });
13
- });
@@ -1,27 +0,0 @@
1
- import { isUndefined } from '../isUndefined';
2
- import { describe, it, expect } from 'vitest';
3
-
4
- describe('Tests isUndefined rule', () => {
5
- it('Should return true for `undefined` value', () => {
6
- expect(isUndefined(undefined)).toBe(true);
7
- expect(isUndefined()).toBe(true);
8
- });
9
-
10
- it.each([
11
- null,
12
- NaN,
13
- false,
14
- true,
15
- Object,
16
- Array(0),
17
- '',
18
- ' ',
19
- 0,
20
- 1,
21
- '0',
22
- '1',
23
- () => undefined,
24
- ])('Should return false for %s value', v => {
25
- expect(isUndefined(v)).toBe(false);
26
- });
27
- });