ts-data-forge 14.5.0 → 14.6.1
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.
- package/dist/array/impl/array-utils-element-access.mjs +1 -1
- package/dist/array/impl/array-utils-reducing-value.mjs +3 -3
- package/dist/array/impl/array-utils-search.mjs +1 -1
- package/dist/collections/imap-mapped.mjs +5 -4
- package/dist/collections/imap-mapped.mjs.map +1 -1
- package/dist/collections/imap.mjs +1 -1
- package/dist/collections/imap.mjs.map +1 -1
- package/dist/collections/iset-mapped.d.mts.map +1 -1
- package/dist/collections/iset-mapped.mjs +3 -1
- package/dist/collections/iset-mapped.mjs.map +1 -1
- package/dist/collections/iset.mjs.map +1 -1
- package/dist/entry-point.mjs +8 -6
- package/dist/entry-point.mjs.map +1 -1
- package/dist/functional/async-result/async-result.d.mts +16 -0
- package/dist/functional/async-result/async-result.d.mts.map +1 -0
- package/dist/functional/async-result/async-result.mjs +3 -0
- package/dist/functional/async-result/async-result.mjs.map +1 -0
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts +39 -0
- package/dist/functional/async-result/impl/async-result-flat-map.d.mts.map +1 -0
- package/dist/functional/async-result/impl/async-result-flat-map.mjs +25 -0
- package/dist/functional/async-result/impl/async-result-flat-map.mjs.map +1 -0
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts +47 -0
- package/dist/functional/async-result/impl/async-result-from-promise.d.mts.map +1 -0
- package/dist/functional/async-result/impl/async-result-from-promise.mjs +11 -0
- package/dist/functional/async-result/impl/async-result-from-promise.mjs.map +1 -0
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts +53 -0
- package/dist/functional/async-result/impl/async-result-from-throwable.d.mts.map +1 -0
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs +17 -0
- package/dist/functional/async-result/impl/async-result-from-throwable.mjs.map +1 -0
- package/dist/functional/async-result/impl/async-result-map-err.d.mts +35 -0
- package/dist/functional/async-result/impl/async-result-map-err.d.mts.map +1 -0
- package/dist/functional/async-result/impl/async-result-map-err.mjs +23 -0
- package/dist/functional/async-result/impl/async-result-map-err.mjs.map +1 -0
- package/dist/functional/async-result/impl/async-result-map.d.mts +45 -0
- package/dist/functional/async-result/impl/async-result-map.d.mts.map +1 -0
- package/dist/functional/async-result/impl/async-result-map.mjs +23 -0
- package/dist/functional/async-result/impl/async-result-map.mjs.map +1 -0
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts +34 -0
- package/dist/functional/async-result/impl/async-result-unwrap-or.d.mts.map +1 -0
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +10 -0
- package/dist/functional/async-result/impl/async-result-unwrap-or.mjs.map +1 -0
- package/dist/functional/async-result/impl/index.d.mts +8 -0
- package/dist/functional/async-result/impl/index.d.mts.map +1 -0
- package/dist/functional/async-result/impl/index.mjs +7 -0
- package/dist/functional/async-result/impl/index.mjs.map +1 -0
- package/dist/functional/async-result/impl/types.d.mts +45 -0
- package/dist/functional/async-result/impl/types.d.mts.map +1 -0
- package/dist/functional/async-result/impl/types.mjs +2 -0
- package/dist/functional/async-result/impl/types.mjs.map +1 -0
- package/dist/functional/async-result/index.d.mts +2 -0
- package/dist/functional/async-result/index.d.mts.map +1 -0
- package/dist/functional/async-result/index.mjs +3 -0
- package/dist/functional/async-result/index.mjs.map +1 -0
- package/dist/functional/index.d.mts +1 -0
- package/dist/functional/index.d.mts.map +1 -1
- package/dist/functional/index.mjs +8 -6
- package/dist/functional/index.mjs.map +1 -1
- package/dist/functional/result/impl/result-from-promise.d.mts +5 -0
- package/dist/functional/result/impl/result-from-promise.d.mts.map +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs.map +1 -1
- package/dist/json/json.mjs +2 -2
- package/dist/number/enum/int8.mjs +1 -1
- package/dist/number/enum/int8.mjs.map +1 -1
- package/dist/number/refined-number-utils.mjs +1 -1
- package/dist/object/object.mjs +1 -1
- package/package.json +7 -7
- package/src/array/impl/array-utils-length-constraint-preservation.test.mts +2 -2
- package/src/collections/imap-mapped.mts +4 -4
- package/src/collections/imap.mts +1 -1
- package/src/collections/imap.test.mts +1 -1
- package/src/collections/iset-mapped.mts +2 -1
- package/src/collections/iset.mts +1 -1
- package/src/functional/async-result/async-result.mts +17 -0
- package/src/functional/async-result/impl/async-result-flat-map.mts +99 -0
- package/src/functional/async-result/impl/async-result-from-promise.mts +69 -0
- package/src/functional/async-result/impl/async-result-from-throwable.mts +78 -0
- package/src/functional/async-result/impl/async-result-map-err.mts +84 -0
- package/src/functional/async-result/impl/async-result-map.mts +94 -0
- package/src/functional/async-result/impl/async-result-unwrap-or.mts +42 -0
- package/src/functional/async-result/impl/index.mts +7 -0
- package/src/functional/async-result/impl/types.mts +51 -0
- package/src/functional/async-result/index.mts +1 -0
- package/src/functional/async-result.test.mts +291 -0
- package/src/functional/index.mts +1 -0
- package/src/functional/optional.test.mts +2 -1
- package/src/functional/result/impl/result-from-promise.mts +5 -0
- package/src/functional/result.test.mts +0 -2
- package/src/guard/is-non-empty-string.test.mts +2 -2
- package/src/guard/is-non-null-object.test.mts +3 -3
- package/src/guard/is-primitive.test.mts +3 -3
- package/src/guard/is-type.test.mts +3 -3
- package/src/json/json.test.mts +1 -1
- package/src/number/enum/int8.mts +1 -1
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import { isError } from '@sindresorhus/is';
|
|
2
|
+
import { AsyncResult as AsyncResultFromEntryPoint } from '../entry-point.mjs';
|
|
3
|
+
import { expectType } from '../expect-type.mjs';
|
|
4
|
+
import { unknownToString } from '../others/index.mjs';
|
|
5
|
+
import { AsyncResult } from './async-result/index.mjs';
|
|
6
|
+
import { Result } from './result/index.mjs';
|
|
7
|
+
|
|
8
|
+
// Fixtures are created through functions so that the success/error types stay
|
|
9
|
+
// unions instead of being narrowed to literal types by const inference.
|
|
10
|
+
const okFixture = (value: number): AsyncResult<number, string> =>
|
|
11
|
+
Promise.resolve(Result.ok(value));
|
|
12
|
+
|
|
13
|
+
const errFixture = (message: string): AsyncResult<number, string> =>
|
|
14
|
+
Promise.resolve(Result.err(message));
|
|
15
|
+
|
|
16
|
+
describe('AsyncResult test', () => {
|
|
17
|
+
describe('fromPromise', () => {
|
|
18
|
+
test('resolved promise becomes Ok', async () => {
|
|
19
|
+
const result = await AsyncResult.fromPromise(
|
|
20
|
+
Promise.resolve(42),
|
|
21
|
+
(error) => `mapped: ${unknownToString(error)}`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
assert.isTrue(Result.isOk(result));
|
|
25
|
+
|
|
26
|
+
assert.deepStrictEqual(result, Result.ok(42));
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('rejected promise becomes Err with mapError applied', async () => {
|
|
30
|
+
const result = await AsyncResult.fromPromise(
|
|
31
|
+
Promise.reject(new Error('boom')),
|
|
32
|
+
(error) => (isError(error) ? error.message : 'unknown'),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
assert.isTrue(Result.isErr(result));
|
|
36
|
+
|
|
37
|
+
assert.deepStrictEqual(result, Result.err('boom'));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('resolved promise becomes Ok when mapError is omitted', async () => {
|
|
41
|
+
const result = await AsyncResult.fromPromise(Promise.resolve(42));
|
|
42
|
+
|
|
43
|
+
assert.deepStrictEqual(result, Result.ok(42));
|
|
44
|
+
|
|
45
|
+
expectType<typeof result, Result<number, unknown>>('=');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('rejection reason is carried as-is when mapError is omitted', async () => {
|
|
49
|
+
const error = new Error('boom');
|
|
50
|
+
|
|
51
|
+
const result = await AsyncResult.fromPromise(
|
|
52
|
+
Promise.reject(error).then(() => 42),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
assert.isTrue(Result.isErr(result));
|
|
56
|
+
|
|
57
|
+
assert.deepStrictEqual(result, Result.err(error));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('fromThrowable', () => {
|
|
62
|
+
test('resolved async function becomes Ok', async () => {
|
|
63
|
+
const result = await AsyncResult.fromThrowable(
|
|
64
|
+
() => Promise.resolve('data'),
|
|
65
|
+
(error) => `mapped: ${unknownToString(error)}`,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
assert.isTrue(Result.isOk(result));
|
|
69
|
+
|
|
70
|
+
assert.deepStrictEqual(result, Result.ok('data'));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('synchronous throw becomes Err with mapError applied', async () => {
|
|
74
|
+
const result = await AsyncResult.fromThrowable(
|
|
75
|
+
(): Promise<number> => {
|
|
76
|
+
throw new Error('sync failure');
|
|
77
|
+
},
|
|
78
|
+
(error) => (isError(error) ? error.message : 'unknown'),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
assert.isTrue(Result.isErr(result));
|
|
82
|
+
|
|
83
|
+
assert.deepStrictEqual(result, Result.err('sync failure'));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('async rejection becomes Err with mapError applied', async () => {
|
|
87
|
+
const result = await AsyncResult.fromThrowable(
|
|
88
|
+
() => Promise.reject(new Error('async failure')),
|
|
89
|
+
(error) => (isError(error) ? error.message : 'unknown'),
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
assert.isTrue(Result.isErr(result));
|
|
93
|
+
|
|
94
|
+
assert.deepStrictEqual(result, Result.err('async failure'));
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('synchronous throw is carried as-is when mapError is omitted', async () => {
|
|
98
|
+
const error = new Error('sync failure');
|
|
99
|
+
|
|
100
|
+
const result = await AsyncResult.fromThrowable((): Promise<number> => {
|
|
101
|
+
throw error;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
assert.deepStrictEqual(result, Result.err(error));
|
|
105
|
+
|
|
106
|
+
expectType<typeof result, Result<number, unknown>>('=');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('async rejection is carried as-is when mapError is omitted', async () => {
|
|
110
|
+
const error = new Error('async failure');
|
|
111
|
+
|
|
112
|
+
const result = await AsyncResult.fromThrowable(() =>
|
|
113
|
+
Promise.reject(error).then(() => 42),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
assert.deepStrictEqual(result, Result.err(error));
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe('map', () => {
|
|
121
|
+
test('maps Ok value with a synchronous function', async () => {
|
|
122
|
+
const result = await AsyncResult.map(okFixture(5), (value) => value * 2);
|
|
123
|
+
|
|
124
|
+
assert.deepStrictEqual(result, Result.ok(10));
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('maps Ok value with an asynchronous function', async () => {
|
|
128
|
+
const result = await AsyncResult.map(okFixture(5), (value) =>
|
|
129
|
+
Promise.resolve(value * 3),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
assert.deepStrictEqual(result, Result.ok(15));
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('passes Err through unchanged', async () => {
|
|
136
|
+
let mut_called = false;
|
|
137
|
+
|
|
138
|
+
const result = await AsyncResult.map(errFixture('failure'), (value) => {
|
|
139
|
+
mut_called = true;
|
|
140
|
+
|
|
141
|
+
return value * 2;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
assert.deepStrictEqual(result, Result.err('failure'));
|
|
145
|
+
|
|
146
|
+
assert.isFalse(mut_called);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('curried version maps Ok value', async () => {
|
|
150
|
+
const double = AsyncResult.map((value: number) => value * 2);
|
|
151
|
+
|
|
152
|
+
const result = await double(okFixture(21));
|
|
153
|
+
|
|
154
|
+
assert.deepStrictEqual(result, Result.ok(42));
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test('curried version passes Err through unchanged', async () => {
|
|
158
|
+
const double = AsyncResult.map((value: number) => value * 2);
|
|
159
|
+
|
|
160
|
+
const result = await double(errFixture('failure'));
|
|
161
|
+
|
|
162
|
+
assert.deepStrictEqual(result, Result.err('failure'));
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('mapErr', () => {
|
|
167
|
+
test('maps Err value with a synchronous function', async () => {
|
|
168
|
+
const result = await AsyncResult.mapErr(errFixture('failure'), (error) =>
|
|
169
|
+
error.toUpperCase(),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
assert.deepStrictEqual(result, Result.err('FAILURE'));
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
test('maps Err value with an asynchronous function', async () => {
|
|
176
|
+
const result = await AsyncResult.mapErr(
|
|
177
|
+
errFixture('failure'),
|
|
178
|
+
(message) => Promise.resolve(message.length),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
assert.deepStrictEqual(result, Result.err(7));
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('passes Ok through unchanged', async () => {
|
|
185
|
+
let mut_called = false;
|
|
186
|
+
|
|
187
|
+
const result = await AsyncResult.mapErr(okFixture(1), (error) => {
|
|
188
|
+
mut_called = true;
|
|
189
|
+
|
|
190
|
+
return error.toUpperCase();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
assert.deepStrictEqual(result, Result.ok(1));
|
|
194
|
+
|
|
195
|
+
assert.isFalse(mut_called);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('curried version maps Err value', async () => {
|
|
199
|
+
const upper = AsyncResult.mapErr((error: string) => error.toUpperCase());
|
|
200
|
+
|
|
201
|
+
const result = await upper(errFixture('failure'));
|
|
202
|
+
|
|
203
|
+
assert.deepStrictEqual(result, Result.err('FAILURE'));
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('flatMap', () => {
|
|
208
|
+
test('chains with a function returning a Result', async () => {
|
|
209
|
+
const result = await AsyncResult.flatMap(okFixture(4), (value) =>
|
|
210
|
+
value > 0 ? Result.ok(value * 10) : Result.err('non-positive'),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
assert.deepStrictEqual(result, Result.ok(40));
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('chains with a function returning an AsyncResult', async () => {
|
|
217
|
+
const result = await AsyncResult.flatMap(okFixture(4), (value) =>
|
|
218
|
+
AsyncResult.fromPromise(Promise.resolve(value + 1), () => 'failed'),
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
assert.deepStrictEqual(result, Result.ok(5));
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('chains into Err returned by the function', async () => {
|
|
225
|
+
const result = await AsyncResult.flatMap(
|
|
226
|
+
okFixture(-1),
|
|
227
|
+
(value): Result<number, string> =>
|
|
228
|
+
value > 0 ? Result.ok(value * 10) : Result.err('non-positive'),
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
assert.deepStrictEqual(result, Result.err('non-positive'));
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('short-circuits on Err without calling the function', async () => {
|
|
235
|
+
let mut_called = false;
|
|
236
|
+
|
|
237
|
+
const result = await AsyncResult.flatMap(
|
|
238
|
+
errFixture('failure'),
|
|
239
|
+
(value) => {
|
|
240
|
+
mut_called = true;
|
|
241
|
+
|
|
242
|
+
return Result.ok(value * 2);
|
|
243
|
+
},
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
assert.deepStrictEqual(result, Result.err('failure'));
|
|
247
|
+
|
|
248
|
+
assert.isFalse(mut_called);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('curried version chains with a function returning a Result', async () => {
|
|
252
|
+
const validate = AsyncResult.flatMap(
|
|
253
|
+
(value: number): Result<number, string> =>
|
|
254
|
+
value > 0 ? Result.ok(value) : Result.err('non-positive'),
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const passed = await validate(okFixture(7));
|
|
258
|
+
|
|
259
|
+
const failed = await validate(okFixture(-7));
|
|
260
|
+
|
|
261
|
+
assert.deepStrictEqual(passed, Result.ok(7));
|
|
262
|
+
|
|
263
|
+
assert.deepStrictEqual(failed, Result.err('non-positive'));
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
describe('unwrapOr', () => {
|
|
268
|
+
test('returns the success value for Ok', async () => {
|
|
269
|
+
const value = await AsyncResult.unwrapOr(okFixture(10), 0);
|
|
270
|
+
|
|
271
|
+
expect(value).toBe(10);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test('returns the default value for Err', async () => {
|
|
275
|
+
const value = await AsyncResult.unwrapOr(errFixture('failure'), 0);
|
|
276
|
+
|
|
277
|
+
expect(value).toBe(0);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('entry point', () => {
|
|
282
|
+
test('AsyncResult is exported from the package entry point', async () => {
|
|
283
|
+
const result = await AsyncResultFromEntryPoint.fromPromise(
|
|
284
|
+
Promise.resolve(1),
|
|
285
|
+
() => 'failed',
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
assert.deepStrictEqual(result, Result.ok(1));
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|
package/src/functional/index.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { expectType } from '../expect-type.mjs';
|
|
2
2
|
import { Num } from '../number/index.mjs';
|
|
3
|
+
import { unknownToString } from '../others/index.mjs';
|
|
3
4
|
import { type None, type Some } from '../types.mjs';
|
|
4
5
|
import { Optional, type UnknownOptional } from './optional/index.mjs';
|
|
5
6
|
import { pipe } from './pipe.mjs';
|
|
@@ -872,7 +873,7 @@ describe('Optional test', () => {
|
|
|
872
873
|
const makeOptional = (): Optional<undefined> => Optional.some(undefined);
|
|
873
874
|
|
|
874
875
|
const result = Optional.match(makeOptional(), {
|
|
875
|
-
some: (value) => `some: ${
|
|
876
|
+
some: (value) => `some: ${unknownToString(value)}`,
|
|
876
877
|
none: () => 'none',
|
|
877
878
|
});
|
|
878
879
|
|
|
@@ -17,6 +17,11 @@ type UnwrapPromise<P extends Promise<unknown>> =
|
|
|
17
17
|
* input Promise rejects, the `Result` will be `Err` with the rejection
|
|
18
18
|
* reason.
|
|
19
19
|
*
|
|
20
|
+
* The error channel is `unknown`, since the rejection reason is carried
|
|
21
|
+
* through untouched. For a concrete error type, use `AsyncResult.fromPromise`
|
|
22
|
+
* with a `mapError` function; called without one it behaves exactly as this
|
|
23
|
+
* function does.
|
|
24
|
+
*
|
|
20
25
|
* @example
|
|
21
26
|
*
|
|
22
27
|
* ```ts
|
|
@@ -963,14 +963,12 @@ describe('Result test', () => {
|
|
|
963
963
|
|
|
964
964
|
const invalidJson = '{invalid json}';
|
|
965
965
|
|
|
966
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
967
966
|
const validResult = Result.fromThrowable(() => JSON.parse(validJson));
|
|
968
967
|
|
|
969
968
|
assert.isTrue(Result.isOk(validResult));
|
|
970
969
|
|
|
971
970
|
assert.deepStrictEqual(Result.unwrapOk(validResult), { key: 'value' });
|
|
972
971
|
|
|
973
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
974
972
|
const invalidResult = Result.fromThrowable(() => JSON.parse(invalidJson));
|
|
975
973
|
|
|
976
974
|
assert.isTrue(Result.isErr(invalidResult));
|
|
@@ -61,7 +61,7 @@ describe(isNonEmptyString, () => {
|
|
|
61
61
|
// TypeScript knows it's a string
|
|
62
62
|
expect(value.length).toBeGreaterThan(0);
|
|
63
63
|
|
|
64
|
-
expect(value.
|
|
64
|
+
expect(value.at(0)).toBe('t');
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
|
|
@@ -109,7 +109,7 @@ describe(isNonEmptyString, () => {
|
|
|
109
109
|
|
|
110
110
|
test('should not accept String objects', () => {
|
|
111
111
|
// @ts-expect-error Testing non-string types
|
|
112
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
112
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
113
113
|
assert.isFalse(isNonEmptyString(new String('hello') as unknown));
|
|
114
114
|
});
|
|
115
115
|
});
|
|
@@ -43,13 +43,13 @@ describe(isNonNullObject, () => {
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
test('should return true for boxed primitives', () => {
|
|
46
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
46
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
47
47
|
assert.isTrue(isNonNullObject(new String('hello')));
|
|
48
48
|
|
|
49
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
49
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
50
50
|
assert.isTrue(isNonNullObject(new Number(42)));
|
|
51
51
|
|
|
52
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
52
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
53
53
|
assert.isTrue(isNonNullObject(new Boolean(true)));
|
|
54
54
|
});
|
|
55
55
|
|
|
@@ -82,13 +82,13 @@ describe(isPrimitive, () => {
|
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
test('should return false for boxed primitives', () => {
|
|
85
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
85
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
86
86
|
assert.isFalse(isPrimitive(new String('hello')));
|
|
87
87
|
|
|
88
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
88
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
89
89
|
assert.isFalse(isPrimitive(new Number(42)));
|
|
90
90
|
|
|
91
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
91
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
92
92
|
assert.isFalse(isPrimitive(new Boolean(true)));
|
|
93
93
|
});
|
|
94
94
|
|
|
@@ -136,7 +136,7 @@ describe(isString, () => {
|
|
|
136
136
|
|
|
137
137
|
assert.isFalse(isString(undefined));
|
|
138
138
|
|
|
139
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
139
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
140
140
|
assert.isFalse(isString(new String('hello')));
|
|
141
141
|
});
|
|
142
142
|
|
|
@@ -175,7 +175,7 @@ describe(isNumber, () => {
|
|
|
175
175
|
|
|
176
176
|
assert.isFalse(isNumber(123n));
|
|
177
177
|
|
|
178
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
178
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
179
179
|
assert.isFalse(isNumber(new Number(42)));
|
|
180
180
|
});
|
|
181
181
|
|
|
@@ -236,7 +236,7 @@ describe(isBoolean, () => {
|
|
|
236
236
|
|
|
237
237
|
assert.isFalse(isBoolean(null));
|
|
238
238
|
|
|
239
|
-
// eslint-disable-next-line unicorn/new-for-builtins
|
|
239
|
+
// eslint-disable-next-line unicorn/new-for-builtins, @typescript-eslint/no-deprecated
|
|
240
240
|
assert.isFalse(isBoolean(new Boolean(true)));
|
|
241
241
|
});
|
|
242
242
|
|
package/src/json/json.test.mts
CHANGED
|
@@ -123,7 +123,7 @@ describe('parse', () => {
|
|
|
123
123
|
|
|
124
124
|
expect(() => Json.parse('null null')).not.toThrow();
|
|
125
125
|
|
|
126
|
-
expect(() => Json.parse(
|
|
126
|
+
expect(() => Json.parse('undefined')).not.toThrow();
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
test('should use reviver function to transform values', () => {
|
package/src/number/enum/int8.mts
CHANGED
|
@@ -38,7 +38,7 @@ const castType = (x: number): Int8 =>
|
|
|
38
38
|
const fromNumber = (a: number): Int8 => castType(fromNumberImpl(a));
|
|
39
39
|
|
|
40
40
|
const abs = <N extends Int8>(x: N): AbsoluteValue<N> =>
|
|
41
|
-
// eslint-disable-next-line total-functions/no-unsafe-type-assertion
|
|
41
|
+
// eslint-disable-next-line total-functions/no-unsafe-type-assertion, @typescript-eslint/no-unnecessary-type-assertion -- unnecessary only under the strict standard library; the stock one types `Math.abs` as returning `number`
|
|
42
42
|
Math.abs(x) as unknown as AbsoluteValue<N>;
|
|
43
43
|
|
|
44
44
|
const min_ = (...values: readonly Int8[]): Int8 =>
|