@vpmedia/simplify 1.70.0 → 1.72.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.
@@ -1,47 +0,0 @@
1
- import { serverDataToState } from './state.js';
2
-
3
- describe('state', () => {
4
- test('serverDataToState() recursive', () => {
5
- const state = serverDataToState(
6
- {
7
- my_array: [{ key_a: 'value1' }],
8
- my_data: { key_a: 'value1' },
9
- my_list: [1, 2, 3],
10
- my_null: null,
11
- my_number: 1000,
12
- my_string: 'a',
13
- my_var: 'test',
14
- },
15
- true
16
- );
17
- expect(state.myArray[0].keyA).toBe('value1');
18
- expect(state.myData.keyA).toBe('value1');
19
- expect(state.myList[0]).toBe(1);
20
- expect(state.myNull).toBe(null);
21
- expect(state.myNumber).toBe(1000);
22
- expect(state.myString).toBe('a');
23
- expect(state.myVar).toBe('test');
24
- });
25
-
26
- test('serverDataToState() non-recursive', () => {
27
- const state = serverDataToState(
28
- {
29
- my_array: [{ key_a: 'value1' }],
30
- my_data: { key_a: 'value1' },
31
- my_list: [1, 2, 3],
32
- my_null: null,
33
- my_number: 1000,
34
- my_string: 'a',
35
- my_var: 'test',
36
- },
37
- false
38
- );
39
- expect(state.myArray[0].key_a).toBe('value1');
40
- expect(state.myData.key_a).toBe('value1');
41
- expect(state.myList[0]).toBe(1);
42
- expect(state.myNull).toBe(null);
43
- expect(state.myNumber).toBe(1000);
44
- expect(state.myString).toBe('a');
45
- expect(state.myVar).toBe('test');
46
- });
47
- });
@@ -1,66 +0,0 @@
1
- /* eslint-disable unicorn/no-useless-undefined */
2
-
3
- import {
4
- underscoreToCamelCase,
5
- capitalize,
6
- addLeadingZero,
7
- getTypeFromValue,
8
- getDisplayValue,
9
- saveAsFile,
10
- } from './string.js';
11
-
12
- describe('string', () => {
13
- test('addLeadingZero', () => {
14
- expect(addLeadingZero(1)).toBe('01');
15
- expect(addLeadingZero('1')).toBe('01');
16
- expect(addLeadingZero(1, 3)).toBe('001');
17
- expect(addLeadingZero('21')).toBe('21');
18
- expect(addLeadingZero(21)).toBe('21');
19
- expect(addLeadingZero(null)).toBe(null);
20
- expect(addLeadingZero(undefined)).toBe(null);
21
- });
22
-
23
- test('capitalize', () => {
24
- expect(capitalize('test')).toBe('Test');
25
- expect(capitalize('TEST')).toBe('Test');
26
- expect(capitalize('tEST')).toBe('Test');
27
- expect(capitalize(null)).toBe(null);
28
- expect(capitalize('')).toBe('');
29
- expect(capitalize(' ')).toBe(' ');
30
- expect(capitalize('a')).toBe('A');
31
- expect(capitalize('A')).toBe('A');
32
- expect(capitalize('test123')).toBe('Test123');
33
- });
34
-
35
- test('underscoreToCamelCase', () => {
36
- expect(underscoreToCamelCase('test')).toBe('test');
37
- expect(underscoreToCamelCase('test_variable')).toBe('testVariable');
38
- expect(underscoreToCamelCase('test_variable_name')).toBe('testVariableName');
39
- });
40
-
41
- test('getTypeFromValue', () => {
42
- expect(getTypeFromValue('test')).toBe('string');
43
- expect(getTypeFromValue(() => null)).toBe('function');
44
- expect(getTypeFromValue([])).toBe('array');
45
- expect(getTypeFromValue({})).toBe('object');
46
- expect(getTypeFromValue(new Date())).toBe('date');
47
- expect(getTypeFromValue(null)).toBe('null');
48
- expect(getTypeFromValue(true)).toBe('boolean');
49
- expect(getTypeFromValue(undefined)).toBe('undefined');
50
- });
51
-
52
- test('getDisplayValue', () => {
53
- expect(getDisplayValue('test')).toBe('"test"');
54
- expect(getDisplayValue(() => null)).toBe('() => null');
55
- expect(getDisplayValue([])).toBe('[]');
56
- expect(getDisplayValue({})).toBe('{}');
57
- expect(getDisplayValue(new Date())).not.toBe(null);
58
- expect(getDisplayValue(null)).toBe('null');
59
- expect(getDisplayValue(true)).toBe('true');
60
- expect(getDisplayValue(undefined)).toBe('undefined');
61
- });
62
-
63
- test('saveAsFile', () => {
64
- expect(() => saveAsFile('test.txt', 'test content')).not.toThrowError(Error);
65
- });
66
- });
@@ -1,39 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
- import { randomUUIDFallback, uuidv4 } from './uuid.js';
3
-
4
- const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
5
-
6
- describe('UUID functions', () => {
7
- let originalRandomUUID = null;
8
-
9
- beforeEach(() => {
10
- originalRandomUUID = crypto.randomUUID;
11
- });
12
-
13
- afterEach(() => {
14
- crypto.randomUUID = originalRandomUUID;
15
- });
16
-
17
- it('randomUUIDFallback generates a valid UUID v4', () => {
18
- const uuid = randomUUIDFallback();
19
- expect(uuid).toMatch(uuidV4Regex);
20
- });
21
-
22
- it('uuidv4 returns a valid UUID v4', () => {
23
- const uuid = uuidv4();
24
- expect(uuid).toMatch(uuidV4Regex);
25
- });
26
-
27
- it('uuidv4 uses crypto.randomUUID if available', () => {
28
- // @ts-expect-error
29
- crypto.randomUUID = vi.fn(() => 'mock-uuid');
30
- const uuid = uuidv4();
31
- expect(uuid).toBe('mock-uuid');
32
- expect(crypto.randomUUID).toHaveBeenCalled();
33
- });
34
-
35
- it('randomUUIDFallback fallback works if crypto.randomUUID not available', () => {
36
- const uuid = randomUUIDFallback();
37
- expect(uuid).toMatch(uuidV4Regex);
38
- });
39
- });
@@ -1,311 +0,0 @@
1
- /* eslint-disable unicorn/no-useless-undefined */
2
-
3
- import {
4
- isArray,
5
- isArrayOf,
6
- isBoolean,
7
- isEnum,
8
- isFunction,
9
- isInstance,
10
- isInteger,
11
- isNonNegativeInteger,
12
- isNonNegativeNumber,
13
- isNull,
14
- isNumber,
15
- isPlainObject,
16
- isPlainObjectOf,
17
- isAnyOf,
18
- isPositiveInteger,
19
- isPositiveNumber,
20
- isString,
21
- isUndefined,
22
- refineValidator,
23
- isNumberLess,
24
- isNumberGreater,
25
- isNumberLessOrEqual,
26
- isNumberGreaterOrEqual,
27
- isIntegerLess,
28
- isIntegerGreater,
29
- isIntegerLessOrEqual,
30
- isIntegerGreaterOrEqual,
31
- isNumberInRange,
32
- isIntegerInRange,
33
- isArrayLengthEqual,
34
- isArrayLengthInRange,
35
- isStringLengthEqual,
36
- isStringLengthInRange,
37
- isNullOrUndefined,
38
- } from './validate.js';
39
-
40
- describe('validate', () => {
41
- test('isArray', () => {
42
- expect(isArray('string')).toBe(false);
43
- expect(isArray([])).toBe(true);
44
- expect(isArray([1, 2, 3])).toBe(true);
45
- expect(isArray({ string: '1' })).toBe(false);
46
- expect(isArray(0.1)).toBe(false);
47
- expect(isArray(1)).toBe(false);
48
- expect(isArray(false)).toBe(false);
49
- expect(isArray(null)).toBe(false);
50
- expect(isArray(true)).toBe(false);
51
- expect(isArray(undefined)).toBe(false);
52
- expect(isArray(() => true)).toBe(false);
53
- });
54
-
55
- test('isBoolean', () => {
56
- expect(isBoolean('string')).toBe(false);
57
- expect(isBoolean([])).toBe(false);
58
- expect(isBoolean([1, 2, 3])).toBe(false);
59
- expect(isBoolean({ string: '1' })).toBe(false);
60
- expect(isBoolean(0.1)).toBe(false);
61
- expect(isBoolean(1)).toBe(false);
62
- expect(isBoolean(false)).toBe(true);
63
- expect(isBoolean(null)).toBe(false);
64
- expect(isBoolean(true)).toBe(true);
65
- expect(isBoolean(undefined)).toBe(false);
66
- expect(isBoolean(() => true)).toBe(false);
67
- });
68
-
69
- test('isNumber', () => {
70
- expect(isNumber('string')).toBe(false);
71
- expect(isNumber([])).toBe(false);
72
- expect(isNumber([1, 2, 3])).toBe(false);
73
- expect(isNumber({ string: '1' })).toBe(false);
74
- expect(isNumber(0.1)).toBe(true);
75
- expect(isNumber(1)).toBe(true);
76
- expect(isNumber(false)).toBe(false);
77
- expect(isNumber(null)).toBe(false);
78
- expect(isNumber(Number.NaN)).toBe(false);
79
- expect(isNumber(Number.POSITIVE_INFINITY)).toBe(false);
80
- expect(isNumber(true)).toBe(false);
81
- expect(isNumber(undefined)).toBe(false);
82
- expect(isNumber(() => true)).toBe(false);
83
- });
84
-
85
- test('isPositiveNumber', () => {
86
- expect(isPositiveNumber(0)).toBe(false);
87
- expect(isPositiveNumber(1)).toBe(true);
88
- expect(isPositiveNumber(1.1)).toBe(true);
89
- expect(isPositiveNumber(-1)).toBe(false);
90
- expect(isPositiveNumber(-1.1)).toBe(false);
91
- });
92
-
93
- test('isNonNegativeNumber', () => {
94
- expect(isNonNegativeNumber(0)).toBe(true);
95
- expect(isNonNegativeNumber(1)).toBe(true);
96
- expect(isNonNegativeNumber(1.1)).toBe(true);
97
- expect(isNonNegativeNumber(-1)).toBe(false);
98
- expect(isNonNegativeNumber(-1.1)).toBe(false);
99
- });
100
-
101
- test('isInteger', () => {
102
- expect(isInteger('string')).toBe(false);
103
- expect(isInteger(() => true)).toBe(false);
104
- expect(isInteger([])).toBe(false);
105
- expect(isInteger([1, 2, 3])).toBe(false);
106
- expect(isInteger({ string: '1' })).toBe(false);
107
- expect(isInteger(0.1)).toBe(false);
108
- expect(isInteger(1)).toBe(true);
109
- expect(isInteger(false)).toBe(false);
110
- expect(isInteger(null)).toBe(false);
111
- expect(isInteger(Number.NaN)).toBe(false);
112
- expect(isInteger(Number.POSITIVE_INFINITY)).toBe(false);
113
- expect(isInteger(true)).toBe(false);
114
- expect(isInteger(undefined)).toBe(false);
115
- });
116
-
117
- test('isPositiveInteger', () => {
118
- expect(isPositiveInteger(0)).toBe(false);
119
- expect(isPositiveInteger(1)).toBe(true);
120
- expect(isPositiveInteger(1.1)).toBe(false);
121
- expect(isPositiveInteger(-1)).toBe(false);
122
- expect(isPositiveInteger(-1.1)).toBe(false);
123
- });
124
-
125
- test('isNonNegativeInteger', () => {
126
- expect(isNonNegativeInteger(0)).toBe(true);
127
- expect(isNonNegativeInteger(1)).toBe(true);
128
- expect(isNonNegativeInteger(1.1)).toBe(false);
129
- expect(isNonNegativeInteger(-1)).toBe(false);
130
- expect(isNonNegativeInteger(-1.1)).toBe(false);
131
- });
132
-
133
- test('isString', () => {
134
- expect(isString('string')).toBe(true);
135
- expect(isString([])).toBe(false);
136
- expect(isString([1, 2, 3])).toBe(false);
137
- expect(isString({ string: '1' })).toBe(false);
138
- expect(isString(0.1)).toBe(false);
139
- expect(isString(1)).toBe(false);
140
- expect(isString(false)).toBe(false);
141
- expect(isString(null)).toBe(false);
142
- expect(isString(true)).toBe(false);
143
- expect(isString(undefined)).toBe(false);
144
- expect(isString(() => true)).toBe(false);
145
- });
146
-
147
- test('isFunction', () => {
148
- expect(isFunction('string')).toBe(false);
149
- expect(isFunction([])).toBe(false);
150
- expect(isFunction([1, 2, 3])).toBe(false);
151
- expect(isFunction({ string: '1' })).toBe(false);
152
- expect(isFunction(0.1)).toBe(false);
153
- expect(isFunction(1)).toBe(false);
154
- expect(isFunction(false)).toBe(false);
155
- expect(isFunction(null)).toBe(false);
156
- expect(isFunction(true)).toBe(false);
157
- expect(isFunction(undefined)).toBe(false);
158
- expect(isFunction(() => true)).toBe(true);
159
- });
160
-
161
- test('isNull', () => {
162
- expect(isNull('string')).toBe(false);
163
- expect(isNull([])).toBe(false);
164
- expect(isNull([1, 2, 3])).toBe(false);
165
- expect(isNull({ string: '1' })).toBe(false);
166
- expect(isNull(0.1)).toBe(false);
167
- expect(isNull(1)).toBe(false);
168
- expect(isNull(false)).toBe(false);
169
- expect(isNull(null)).toBe(true);
170
- expect(isNull(true)).toBe(false);
171
- expect(isNull(undefined)).toBe(false);
172
- expect(isNull(() => true)).toBe(false);
173
- });
174
-
175
- test('isUndefined', () => {
176
- expect(isUndefined('string')).toBe(false);
177
- expect(isUndefined([])).toBe(false);
178
- expect(isUndefined([1, 2, 3])).toBe(false);
179
- expect(isUndefined({ string: '1' })).toBe(false);
180
- expect(isUndefined(0.1)).toBe(false);
181
- expect(isUndefined(1)).toBe(false);
182
- expect(isUndefined(false)).toBe(false);
183
- expect(isUndefined(null)).toBe(false);
184
- expect(isUndefined(true)).toBe(false);
185
- expect(isUndefined(undefined)).toBe(true);
186
- expect(isUndefined(() => true)).toBe(false);
187
- });
188
-
189
- test('isNullOrUndefined', () => {
190
- expect(isNullOrUndefined('string')).toBe(false);
191
- expect(isNullOrUndefined([])).toBe(false);
192
- expect(isNullOrUndefined([1, 2, 3])).toBe(false);
193
- expect(isNullOrUndefined({ string: '1' })).toBe(false);
194
- expect(isNullOrUndefined(0.1)).toBe(false);
195
- expect(isNullOrUndefined(1)).toBe(false);
196
- expect(isNullOrUndefined(false)).toBe(false);
197
- expect(isNullOrUndefined(null)).toBe(true);
198
- expect(isNullOrUndefined(true)).toBe(false);
199
- expect(isNullOrUndefined(undefined)).toBe(true);
200
- expect(isNullOrUndefined(() => true)).toBe(false);
201
- });
202
-
203
- test('isPlainObject', () => {
204
- expect(isPlainObject('string')).toBe(false);
205
- expect(isPlainObject(() => true)).toBe(false);
206
- expect(isPlainObject([])).toBe(false);
207
- expect(isPlainObject([1, 2, 3])).toBe(false);
208
- expect(isPlainObject({ string: '1' })).toBe(true);
209
- expect(isPlainObject(0.1)).toBe(false);
210
- expect(isPlainObject(1)).toBe(false);
211
- expect(isPlainObject(false)).toBe(false);
212
- expect(isPlainObject(new Date())).toBe(false);
213
- expect(isPlainObject(null)).toBe(false);
214
- expect(isPlainObject(true)).toBe(false);
215
- expect(isPlainObject(undefined)).toBe(false);
216
- });
217
-
218
- test('isInstance', () => {
219
- class CustomError extends Error {}
220
- // @ts-expect-error
221
- expect(isInstance({}, {})).toBe(false);
222
- expect(isInstance({}, Number)).toBe(false);
223
- // @ts-expect-error
224
- expect(isInstance(new CustomError(), {})).toBe(false);
225
- expect(isInstance(new CustomError(), Error)).toBe(true);
226
- expect(isInstance(new CustomError(), Number)).toBe(false);
227
- expect(isInstance(new Date(), Date)).toBe(true);
228
- });
229
-
230
- test('isEnum', () => {
231
- expect(isEnum(0, [1, 2])).toBe(false);
232
- expect(isEnum(1, [1, 2])).toBe(true);
233
- expect(isEnum('AB', ['AB', 'CD'])).toBe(true);
234
- expect(isEnum('EF', ['AB', 'CD'])).toBe(false);
235
- expect(isEnum('AB', { AB: 'AB', CD: 'CD' })).toBe(true);
236
- expect(isEnum('EF', { AB: 'AB', CD: 'CD' })).toBe(false);
237
- expect(isEnum('AB', new Set(['AB', 'CD']))).toBe(true);
238
- expect(isEnum('EF', new Set(['AB', 'CD']))).toBe(false);
239
- expect(isEnum('EF', null)).toBe(false);
240
- expect(isEnum('EF', undefined)).toBe(false);
241
- // @ts-expect-error
242
- expect(isEnum('EF', 1)).toBe(false);
243
- // @ts-expect-error
244
- expect(isEnum('EF', 'string')).toBe(false);
245
- // @ts-expect-error
246
- expect(isEnum(false, 'string')).toBe(false);
247
- });
248
-
249
- test('isArrayOf', () => {
250
- // @ts-expect-error
251
- expect(isArrayOf(0.1, isNumber)).toBe(false);
252
- expect(isArrayOf([0.1, 'string'], isNumber)).toBe(false);
253
- expect(isArrayOf([0.1, 0.2], isNumber)).toBe(true);
254
- expect(isArrayOf([0.1, 1, 2], isInteger)).toBe(false);
255
- expect(isArrayOf([1, 2], isInteger)).toBe(true);
256
- expect(isArrayOf([1, 'string', undefined], isAnyOf(isInteger, isNullOrUndefined))).toBe(false);
257
- expect(isArrayOf([1, null, undefined], isAnyOf(isInteger, isNullOrUndefined))).toBe(true);
258
- });
259
-
260
- test('isPlainObjectOf', () => {
261
- // @ts-expect-error
262
- expect(isPlainObjectOf(0.1, isNumber)).toBe(false);
263
- expect(isPlainObjectOf({ a: 0.1, b: 'string' }, isNumber)).toBe(false);
264
- expect(isPlainObjectOf({ a: 0.1, b: 0.2 }, isNumber)).toBe(true);
265
- expect(isPlainObjectOf({ a: 0.1, b: 1, c: 2 }, isInteger)).toBe(false);
266
- expect(isPlainObjectOf({ a: 1, b: 2 }, isInteger)).toBe(true);
267
- });
268
-
269
- test('isAnyOf', () => {
270
- expect(isAnyOf(isNumber, isNull)(1)).toBe(true);
271
- expect(isAnyOf(isNumber, isNull)(null)).toBe(true);
272
- expect(isAnyOf(isNumber, isNull)('string')).toBe(false);
273
- });
274
-
275
- test('refineValidator', () => {
276
- expect(refineValidator(isNumber, (v) => v > 0)(-1)).toBe(false);
277
- expect(refineValidator(isNumber, (v) => v > 0)(1)).toBe(true);
278
- expect(refineValidator(isNumber, (v) => v > 0).name).toBe('isNumberRefined');
279
- });
280
-
281
- test('isRefinedExtensions', () => {
282
- expect(isNumberLess(0)(-1.1)).toBe(true);
283
- expect(isNumberLess(0)(0)).toBe(false);
284
- expect(isNumberLessOrEqual(0)(0)).toBe(true);
285
- expect(isNumberGreater(0)(0)).toBe(false);
286
- expect(isNumberGreater(0)(1.1)).toBe(true);
287
- expect(isNumberGreaterOrEqual(0)(0)).toBe(true);
288
- expect(isNumberInRange(0, 1.1)(0)).toBe(true);
289
- expect(isNumberInRange.name).toBe('isNumberInRange');
290
-
291
- expect(isIntegerLess(0)(-1)).toBe(true);
292
- expect(isIntegerLess(0)(0)).toBe(false);
293
- expect(isIntegerLessOrEqual(0)(0)).toBe(true);
294
- expect(isIntegerGreater(0)(0)).toBe(false);
295
- expect(isIntegerGreater(0)(1)).toBe(true);
296
- expect(isIntegerGreater(0)(1.1)).toBe(false);
297
- expect(isIntegerGreaterOrEqual(0)(0)).toBe(true);
298
- expect(isIntegerInRange(0, 1)(0)).toBe(true);
299
- expect(isIntegerInRange(0, 1)(2)).toBe(false);
300
-
301
- expect(isStringLengthEqual(1)('a')).toBe(true);
302
- expect(isStringLengthEqual(1)('ab')).toBe(false);
303
- expect(isStringLengthInRange(1, 2)('ab')).toBe(true);
304
- expect(isStringLengthInRange(1, 2)('abc')).toBe(false);
305
-
306
- expect(isArrayLengthEqual(1)([1])).toBe(true);
307
- expect(isArrayLengthEqual(1)([1, 2])).toBe(false);
308
- expect(isArrayLengthInRange(1, 2)([1, 2])).toBe(true);
309
- expect(isArrayLengthInRange(1, 2)([1, 2, 3])).toBe(false);
310
- });
311
- });
@@ -1,34 +0,0 @@
1
- import { http, HttpResponse } from 'msw';
2
-
3
- export const fetchHandlers = [
4
- http.get('/test.json', () => {
5
- const response = HttpResponse.json(
6
- {
7
- success: true,
8
- method: 'GET',
9
- },
10
- { status: 200 }
11
- );
12
- return response;
13
- }),
14
- http.post('/test.json', () => {
15
- const response = HttpResponse.json(
16
- {
17
- success: true,
18
- method: 'POST',
19
- },
20
- { status: 200 }
21
- );
22
- return response;
23
- }),
24
- http.post('/test_error.json', () => {
25
- const response = HttpResponse.json(
26
- {
27
- success: false,
28
- method: 'POST',
29
- },
30
- { status: 404 }
31
- );
32
- return response;
33
- }),
34
- ];
@@ -1,3 +0,0 @@
1
- import { fetchHandlers } from './handlers/fetch.js';
2
-
3
- export const handlers = [...fetchHandlers];
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "jsx": "react-jsx",
5
- "module": "NodeNext",
6
- "moduleResolution": "nodenext",
7
- "types": ["node", "vitest/globals"],
8
- "allowJs": true,
9
- "checkJs": true,
10
- "declaration": true,
11
- "declarationMap": true,
12
- "emitDeclarationOnly": true,
13
- "declarationDir": "./types",
14
- "isolatedModules": true,
15
- "esModuleInterop": true,
16
- "forceConsistentCasingInFileNames": true,
17
- "strict": true,
18
- "noImplicitAny": false,
19
- "strictNullChecks": false,
20
- "skipLibCheck": true
21
- },
22
- "include": ["./src/**/*"],
23
- "exclude": ["./src/**/*.test.js"]
24
- }
package/vitest.setup.js DELETED
@@ -1,17 +0,0 @@
1
- import { setupServer } from 'msw/node';
2
- import { beforeAll } from 'vitest';
3
- import { handlers } from './tests/mocks/handlers.js';
4
-
5
- const server = setupServer(...handlers);
6
-
7
- beforeAll(() => {
8
- server.listen();
9
- });
10
-
11
- afterEach(() => {
12
- server.resetHandlers();
13
- });
14
-
15
- afterAll(() => {
16
- server.close();
17
- });