ts-data-forge 5.1.0 → 6.0.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.
- package/README.md +46 -44
- package/dist/array/impl/array-utils-modification.d.mts.map +1 -1
- package/dist/array/impl/array-utils-modification.mjs.map +1 -1
- package/dist/array/impl/array-utils-reducing-value.d.mts +8 -8
- package/dist/array/impl/array-utils-search.d.mts +4 -4
- package/dist/array/impl/array-utils-set-op.d.mts +7 -7
- package/dist/array/impl/array-utils-set-op.mjs +7 -7
- package/dist/array/impl/array-utils-size.d.mts +2 -2
- package/dist/array/impl/array-utils-size.mjs +2 -2
- package/dist/array/impl/array-utils-slicing.d.mts +2 -2
- package/dist/array/impl/array-utils-slicing.mjs +2 -2
- package/dist/array/impl/array-utils-validation.d.mts +18 -18
- package/dist/array/impl/array-utils-validation.mjs +14 -14
- package/dist/collections/imap.d.mts +15 -15
- package/dist/collections/imap.mjs +3 -3
- package/dist/collections/iset-mapped.d.mts +19 -19
- package/dist/collections/iset-mapped.mjs +2 -2
- package/dist/collections/iset.d.mts +19 -19
- package/dist/collections/iset.mjs +2 -2
- package/dist/collections/queue.d.mts +25 -25
- package/dist/collections/queue.mjs +5 -5
- package/dist/collections/stack.d.mts +25 -25
- package/dist/collections/stack.mjs +5 -5
- package/dist/functional/match.d.mts +1 -1
- package/dist/functional/optional/impl/optional-expect-to-be.d.mts +2 -2
- package/dist/functional/optional/impl/optional-is-none.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-none.mjs +1 -1
- package/dist/functional/optional/impl/optional-is-optional.d.mts +2 -2
- package/dist/functional/optional/impl/optional-is-optional.mjs +2 -2
- package/dist/functional/optional/impl/optional-is-some.d.mts +1 -1
- package/dist/functional/optional/impl/optional-is-some.mjs +1 -1
- package/dist/functional/optional/impl/optional-none.d.mts +2 -2
- package/dist/functional/optional/impl/optional-none.mjs +2 -2
- package/dist/functional/optional/impl/optional-some.d.mts +2 -2
- package/dist/functional/optional/impl/optional-some.mjs +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.d.mts +2 -2
- package/dist/functional/optional/impl/optional-to-nullable.mjs +2 -2
- package/dist/functional/optional/impl/optional-unwrap-or.d.mts +4 -4
- package/dist/functional/optional/impl/optional-unwrap-throw.d.mts +1 -1
- package/dist/functional/optional/impl/optional-unwrap-throw.mjs +1 -1
- package/dist/functional/optional/impl/optional-unwrap.d.mts +2 -2
- package/dist/functional/optional/impl/optional-zip.d.mts +1 -1
- package/dist/functional/optional/impl/optional-zip.mjs +1 -1
- package/dist/functional/pipe.d.mts +2 -2
- package/dist/functional/result/impl/result-err.d.mts +1 -1
- package/dist/functional/result/impl/result-err.mjs +1 -1
- package/dist/functional/result/impl/result-expect-to-be.d.mts +2 -2
- package/dist/functional/result/impl/result-from-promise.d.mts +1 -1
- package/dist/functional/result/impl/result-from-promise.mjs +1 -1
- package/dist/functional/result/impl/result-from-throwable.d.mts +1 -1
- package/dist/functional/result/impl/result-from-throwable.mjs +1 -1
- package/dist/functional/result/impl/result-is-err.d.mts +2 -2
- package/dist/functional/result/impl/result-is-err.mjs +2 -2
- package/dist/functional/result/impl/result-is-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-is-ok.mjs +2 -2
- package/dist/functional/result/impl/result-is-result.d.mts +3 -3
- package/dist/functional/result/impl/result-is-result.mjs +3 -3
- package/dist/functional/result/impl/result-ok.d.mts +1 -1
- package/dist/functional/result/impl/result-ok.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-err-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-err-throw.mjs +1 -1
- package/dist/functional/result/impl/result-unwrap-err.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-err.mjs +2 -2
- package/dist/functional/result/impl/result-unwrap-ok-or.d.mts +4 -4
- package/dist/functional/result/impl/result-unwrap-ok.d.mts +2 -2
- package/dist/functional/result/impl/result-unwrap-throw.d.mts +1 -1
- package/dist/functional/result/impl/result-unwrap-throw.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-err.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.d.mts +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +1 -1
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.d.mts +3 -3
- package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +3 -3
- package/dist/globals.d.mts +2 -1
- package/dist/guard/has-key.d.mts +6 -3
- package/dist/guard/has-key.d.mts.map +1 -1
- package/dist/guard/has-key.mjs +2 -2
- package/dist/guard/is-record.d.mts.map +1 -1
- package/dist/guard/is-record.mjs +1 -1
- package/dist/guard/is-record.mjs.map +1 -1
- package/dist/guard/key-is-in.d.mts +2 -2
- package/dist/guard/key-is-in.mjs +2 -2
- package/dist/json/json.d.mts +21 -21
- package/dist/json/json.mjs +21 -21
- package/dist/number/branded-types/int.d.mts +19 -19
- package/dist/number/branded-types/int.mjs +19 -19
- package/dist/number/branded-types/positive-int.d.mts +20 -20
- package/dist/number/branded-types/positive-int.mjs +20 -20
- package/dist/number/branded-types/positive-safe-int.d.mts +26 -26
- package/dist/number/branded-types/positive-safe-int.mjs +26 -26
- package/dist/number/branded-types/safe-int.d.mts +27 -27
- package/dist/number/branded-types/safe-int.mjs +27 -27
- package/dist/number/branded-types/uint.d.mts +19 -19
- package/dist/number/branded-types/uint.mjs +19 -19
- package/dist/number/num.d.mts +20 -20
- package/dist/number/num.mjs +16 -16
- package/dist/number/refined-number-utils.d.mts +11 -11
- package/dist/number/refined-number-utils.d.mts.map +1 -1
- package/dist/number/refined-number-utils.mjs +11 -11
- package/dist/object/object.d.mts +3 -3
- package/dist/object/object.d.mts.map +1 -1
- package/dist/object/object.mjs +3 -3
- package/dist/object/object.mjs.map +1 -1
- package/dist/others/tuple.d.mts +3 -3
- package/dist/others/tuple.mjs +3 -3
- package/dist/promise/promise.d.mts +4 -4
- package/dist/promise/promise.mjs +4 -4
- package/package.json +15 -13
- package/src/array/impl/array-utils-creation.test.mts +1 -1
- package/src/array/impl/array-utils-element-access.test.mts +16 -16
- package/src/array/impl/array-utils-modification.mts +38 -19
- package/src/array/impl/array-utils-reducing-value.mts +8 -8
- package/src/array/impl/array-utils-reducing-value.test.mts +23 -31
- package/src/array/impl/array-utils-search.mts +4 -4
- package/src/array/impl/array-utils-search.test.mts +10 -10
- package/src/array/impl/array-utils-set-op.mts +7 -7
- package/src/array/impl/array-utils-set-op.test.mts +13 -13
- package/src/array/impl/array-utils-size.mts +2 -2
- package/src/array/impl/array-utils-slicing.mts +2 -2
- package/src/array/impl/array-utils-transformation.test.mts +2 -2
- package/src/array/impl/array-utils-validation.mts +18 -18
- package/src/array/impl/array-utils-validation.test.mts +80 -78
- package/src/array/impl/array.test.mts +6 -6
- package/src/collections/imap-mapped.test.mts +16 -18
- package/src/collections/imap.mts +15 -15
- package/src/collections/imap.test.mts +31 -31
- package/src/collections/iset-mapped.mts +19 -19
- package/src/collections/iset-mapped.test.mts +52 -52
- package/src/collections/iset.mts +19 -19
- package/src/collections/iset.test.mts +130 -130
- package/src/collections/queue.mts +25 -25
- package/src/collections/queue.test.mts +33 -35
- package/src/collections/stack.mts +25 -25
- package/src/collections/stack.test.mts +15 -15
- package/src/functional/match.mts +1 -1
- package/src/functional/optional/impl/optional-expect-to-be.mts +2 -2
- package/src/functional/optional/impl/optional-is-none.mts +1 -1
- package/src/functional/optional/impl/optional-is-optional.mts +2 -2
- package/src/functional/optional/impl/optional-is-some.mts +1 -1
- package/src/functional/optional/impl/optional-none.mts +2 -2
- package/src/functional/optional/impl/optional-some.mts +2 -2
- package/src/functional/optional/impl/optional-to-nullable.mts +2 -2
- package/src/functional/optional/impl/optional-unwrap-or.mts +4 -4
- package/src/functional/optional/impl/optional-unwrap-throw.mts +1 -1
- package/src/functional/optional/impl/optional-unwrap.mts +2 -2
- package/src/functional/optional/impl/optional-zip.mts +1 -1
- package/src/functional/optional.test.mts +53 -54
- package/src/functional/pipe.mts +2 -2
- package/src/functional/pipe.test.mts +4 -4
- package/src/functional/result/impl/result-err.mts +1 -1
- package/src/functional/result/impl/result-expect-to-be.mts +2 -2
- package/src/functional/result/impl/result-from-promise.mts +1 -1
- package/src/functional/result/impl/result-from-throwable.mts +1 -1
- package/src/functional/result/impl/result-is-err.mts +2 -2
- package/src/functional/result/impl/result-is-ok.mts +2 -2
- package/src/functional/result/impl/result-is-result.mts +3 -3
- package/src/functional/result/impl/result-ok.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-err-throw.mts +1 -1
- package/src/functional/result/impl/result-unwrap-err.mts +2 -2
- package/src/functional/result/impl/result-unwrap-ok-or.mts +4 -4
- package/src/functional/result/impl/result-unwrap-ok.mts +2 -2
- package/src/functional/result/impl/result-unwrap-throw.mts +1 -1
- package/src/functional/result.test.mts +94 -152
- package/src/functional/ternary-result/impl/ternary-result-err.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-promise.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-from-throwable.mts +1 -1
- package/src/functional/ternary-result/impl/ternary-result-is-ternary-result.mts +3 -3
- package/src/functional/ternary-result.test.mts +8 -8
- package/src/globals.d.mts +2 -1
- package/src/guard/has-key.mts +8 -5
- package/src/guard/has-key.test.mts +0 -5
- package/src/guard/is-error.test.mts +143 -0
- package/src/guard/is-non-empty-string.test.mts +24 -24
- package/src/guard/is-non-null-object.test.mts +26 -26
- package/src/guard/is-primitive.test.mts +28 -28
- package/src/guard/is-record.mts +1 -2
- package/src/guard/is-record.test.mts +57 -67
- package/src/guard/is-type.test.mts +151 -155
- package/src/guard/key-is-in.mts +2 -2
- package/src/guard/key-is-in.test.mts +2 -2
- package/src/json/json.mts +21 -21
- package/src/json/json.test.mts +135 -174
- package/src/number/branded-types/finite-number.test.mts +13 -11
- package/src/number/branded-types/int.mts +19 -19
- package/src/number/branded-types/int.test.mts +14 -14
- package/src/number/branded-types/int16.test.mts +16 -16
- package/src/number/branded-types/int32.test.mts +16 -16
- package/src/number/branded-types/non-negative-finite-number.test.mts +12 -12
- package/src/number/branded-types/non-negative-int16.test.mts +16 -16
- package/src/number/branded-types/non-negative-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-finite-number.test.mts +14 -14
- package/src/number/branded-types/non-zero-int.test.mts +19 -19
- package/src/number/branded-types/non-zero-int16.test.mts +16 -16
- package/src/number/branded-types/non-zero-int32.test.mts +16 -16
- package/src/number/branded-types/non-zero-safe-int.test.mts +23 -23
- package/src/number/branded-types/non-zero-uint16.test.mts +16 -16
- package/src/number/branded-types/non-zero-uint32.test.mts +16 -16
- package/src/number/branded-types/positive-finite-number.test.mts +14 -14
- package/src/number/branded-types/positive-int.mts +20 -20
- package/src/number/branded-types/positive-int.test.mts +17 -17
- package/src/number/branded-types/positive-int16.test.mts +15 -15
- package/src/number/branded-types/positive-int32.test.mts +15 -15
- package/src/number/branded-types/positive-safe-int.mts +26 -26
- package/src/number/branded-types/positive-safe-int.test.mts +19 -19
- package/src/number/branded-types/positive-uint16.test.mts +16 -16
- package/src/number/branded-types/positive-uint32.test.mts +16 -16
- package/src/number/branded-types/safe-int.mts +27 -27
- package/src/number/branded-types/safe-int.test.mts +18 -18
- package/src/number/branded-types/safe-uint.test.mts +17 -17
- package/src/number/branded-types/uint.mts +19 -19
- package/src/number/branded-types/uint.test.mts +15 -15
- package/src/number/branded-types/uint16.test.mts +15 -15
- package/src/number/branded-types/uint32.test.mts +15 -15
- package/src/number/enum/int8.test.mts +1 -1
- package/src/number/enum/uint8.test.mts +1 -1
- package/src/number/num.mts +20 -20
- package/src/number/num.test.mts +26 -26
- package/src/number/refined-number-utils.mts +13 -13
- package/src/object/object.mts +4 -3
- package/src/object/object.test.mts +6 -6
- package/src/others/cast-mutable.test.mts +1 -1
- package/src/others/cast-readonly.test.mts +4 -4
- package/src/others/if-then.test.mts +24 -24
- package/src/others/tuple.mts +3 -3
- package/src/promise/promise.mts +4 -4
- package/src/promise/promise.test.mts +7 -13
package/README.md
CHANGED
|
@@ -171,7 +171,7 @@ const maybeValue = Optional.some(42);
|
|
|
171
171
|
|
|
172
172
|
const doubled = Optional.map(maybeValue, (x) => x * 2);
|
|
173
173
|
|
|
174
|
-
assert(Optional.unwrapOr(doubled, 0) === 84);
|
|
174
|
+
assert.isTrue(Optional.unwrapOr(doubled, 0) === 84);
|
|
175
175
|
|
|
176
176
|
// Result for error handling
|
|
177
177
|
const success = Result.ok(42);
|
|
@@ -201,19 +201,19 @@ const handleStatus = (status: Status, data?: string): string =>
|
|
|
201
201
|
error: 'An error occurred',
|
|
202
202
|
});
|
|
203
203
|
|
|
204
|
-
assert(handleStatus('loading') === 'Please wait...');
|
|
204
|
+
assert.isTrue(handleStatus('loading') === 'Please wait...');
|
|
205
205
|
|
|
206
|
-
assert(handleStatus('success', 'Hello') === 'Data: Hello');
|
|
206
|
+
assert.isTrue(handleStatus('success', 'Hello') === 'Data: Hello');
|
|
207
207
|
|
|
208
|
-
assert(handleStatus('error') === 'An error occurred');
|
|
208
|
+
assert.isTrue(handleStatus('error') === 'An error occurred');
|
|
209
209
|
|
|
210
210
|
// Pattern matching with Result
|
|
211
211
|
const processResult = (result: Result<number, string>): string =>
|
|
212
212
|
Result.isOk(result) ? `Success: ${result.value}` : `Error: ${result.value}`;
|
|
213
213
|
|
|
214
|
-
assert(processResult(Result.ok(42)) === 'Success: 42');
|
|
214
|
+
assert.isTrue(processResult(Result.ok(42)) === 'Success: 42');
|
|
215
215
|
|
|
216
|
-
assert(processResult(Result.err('Failed')) === 'Error: Failed');
|
|
216
|
+
assert.isTrue(processResult(Result.err('Failed')) === 'Error: Failed');
|
|
217
217
|
```
|
|
218
218
|
|
|
219
219
|
### 3. Number Utilities with `Num` and Branded Number Types
|
|
@@ -224,34 +224,34 @@ The `Num` object provides safe and convenient functions for numerical operations
|
|
|
224
224
|
import { Num } from 'ts-data-forge';
|
|
225
225
|
|
|
226
226
|
// Basic conversions
|
|
227
|
-
assert(Num.from('123') === 123);
|
|
227
|
+
assert.isTrue(Num.from('123') === 123);
|
|
228
228
|
|
|
229
|
-
assert(Number.isNaN(Num.from('abc')));
|
|
229
|
+
assert.isTrue(Number.isNaN(Num.from('abc')));
|
|
230
230
|
|
|
231
231
|
// Range checking
|
|
232
232
|
const inRange = Num.isInRange(0, 10);
|
|
233
233
|
|
|
234
|
-
assert(inRange(5));
|
|
234
|
+
assert.isTrue(inRange(5));
|
|
235
235
|
|
|
236
|
-
assert(inRange(0)); // (inclusive lower bound)
|
|
236
|
+
assert.isTrue(inRange(0)); // (inclusive lower bound)
|
|
237
237
|
|
|
238
|
-
assert(
|
|
238
|
+
assert.isFalse(inRange(10)); // (exclusive upper bound)
|
|
239
239
|
|
|
240
240
|
// Clamping values
|
|
241
241
|
const clamp = Num.clamp(0, 100);
|
|
242
242
|
|
|
243
|
-
assert(clamp(150) === 100);
|
|
243
|
+
assert.isTrue(clamp(150) === 100);
|
|
244
244
|
|
|
245
|
-
assert(clamp(-10) === 0);
|
|
245
|
+
assert.isTrue(clamp(-10) === 0);
|
|
246
246
|
|
|
247
247
|
// Rounding utilities
|
|
248
248
|
const round2 = Num.round(2);
|
|
249
249
|
|
|
250
|
-
assert(round2(3.141_59) === 3.14);
|
|
250
|
+
assert.isTrue(round2(3.141_59) === 3.14);
|
|
251
251
|
|
|
252
|
-
assert(Num.roundAt(3.141_59, 3) === 3.142);
|
|
252
|
+
assert.isTrue(Num.roundAt(3.141_59, 3) === 3.142);
|
|
253
253
|
|
|
254
|
-
assert(Num.roundToInt(3.7) === 4);
|
|
254
|
+
assert.isTrue(Num.roundToInt(3.7) === 4);
|
|
255
255
|
|
|
256
256
|
// Type guards
|
|
257
257
|
const value = 5; // example value
|
|
@@ -260,7 +260,7 @@ if (Num.isNonZero(value)) {
|
|
|
260
260
|
// value is guaranteed to be non-zero
|
|
261
261
|
const result = Num.div(10, value); // Safe division
|
|
262
262
|
|
|
263
|
-
assert(result === 2);
|
|
263
|
+
assert.isTrue(result === 2);
|
|
264
264
|
}
|
|
265
265
|
```
|
|
266
266
|
|
|
@@ -291,13 +291,13 @@ const finite = asFiniteNumber(3.14); // FiniteNumber - finite floating-point
|
|
|
291
291
|
|
|
292
292
|
const safeInt = asSafeInt(42); // SafeInt - integer in safe range
|
|
293
293
|
|
|
294
|
-
assert(integer === 42);
|
|
294
|
+
assert.isTrue(integer === 42);
|
|
295
295
|
|
|
296
|
-
assert(unsigned === 42);
|
|
296
|
+
assert.isTrue(unsigned === 42);
|
|
297
297
|
|
|
298
|
-
assert(finite === 3.14);
|
|
298
|
+
assert.isTrue(finite === 3.14);
|
|
299
299
|
|
|
300
|
-
assert(safeInt === 42);
|
|
300
|
+
assert.isTrue(safeInt === 42);
|
|
301
301
|
|
|
302
302
|
// This line would cause a runtime error:
|
|
303
303
|
assert.throw(() => {
|
|
@@ -309,39 +309,39 @@ const int16 = asInt16(1000); // Int16: [-32768, 32767]
|
|
|
309
309
|
|
|
310
310
|
const uint32 = asUint32(3_000_000_000); // Uint32: [0, 4294967295]
|
|
311
311
|
|
|
312
|
-
assert(int16 === 1000);
|
|
312
|
+
assert.isTrue(int16 === 1000);
|
|
313
313
|
|
|
314
|
-
assert(uint32 === 3_000_000_000);
|
|
314
|
+
assert.isTrue(uint32 === 3_000_000_000);
|
|
315
315
|
|
|
316
316
|
// Non-zero and positive variants
|
|
317
317
|
const nonZeroInt = asNonZeroInt(5); // NonZeroInt - excludes zero
|
|
318
318
|
|
|
319
319
|
const positiveInt = asPositiveInt(10); // PositiveInt - excludes zero and negatives
|
|
320
320
|
|
|
321
|
-
assert(nonZeroInt === 5);
|
|
321
|
+
assert.isTrue(nonZeroInt === 5);
|
|
322
322
|
|
|
323
|
-
assert(positiveInt === 10);
|
|
323
|
+
assert.isTrue(positiveInt === 10);
|
|
324
324
|
|
|
325
325
|
// Type-safe arithmetic with automatic clamping
|
|
326
326
|
const sum = Int16.add(int16, asInt16(2000)); // Int16 (3000)
|
|
327
327
|
|
|
328
328
|
const clamped = Int16.clamp(100_000); // Int16 (32767 - clamped to MAX_VALUE)
|
|
329
329
|
|
|
330
|
-
assert(sum === 3000);
|
|
330
|
+
assert.isTrue(sum === 3000);
|
|
331
331
|
|
|
332
|
-
assert(clamped === 32_767);
|
|
332
|
+
assert.isTrue(clamped === 32_767);
|
|
333
333
|
|
|
334
334
|
// Safe division with non-zero types
|
|
335
335
|
const ratio = NonZeroInt.div(asNonZeroInt(10), nonZeroInt); // No division by zero risk
|
|
336
336
|
|
|
337
|
-
assert(ratio === 2);
|
|
337
|
+
assert.isTrue(ratio === 2);
|
|
338
338
|
|
|
339
339
|
// Random generation within type constraints
|
|
340
340
|
const randomInt16 = Int16.random(); // Int16 (random value in valid range)
|
|
341
341
|
|
|
342
|
-
assert(-32_768 <= randomInt16);
|
|
342
|
+
assert.isTrue(-32_768 <= randomInt16);
|
|
343
343
|
|
|
344
|
-
assert(randomInt16 <= 32_767);
|
|
344
|
+
assert.isTrue(randomInt16 <= 32_767);
|
|
345
345
|
```
|
|
346
346
|
|
|
347
347
|
### 4. Array Utilities with `Arr`
|
|
@@ -356,14 +356,14 @@ const numbers: readonly number[] = [1, 2, 3, 4, 5, 2, 3];
|
|
|
356
356
|
// Reduction
|
|
357
357
|
const sum = Arr.sum(numbers);
|
|
358
358
|
|
|
359
|
-
assert(sum === 20);
|
|
359
|
+
assert.isTrue(sum === 20);
|
|
360
360
|
|
|
361
361
|
// Type-safe length checking
|
|
362
362
|
if (Arr.isArrayAtLeastLength(numbers, 2)) {
|
|
363
363
|
// numbers is now guaranteed to have at least 2 elements
|
|
364
364
|
expectType<typeof numbers, readonly [number, number, ...number[]]>('=');
|
|
365
365
|
|
|
366
|
-
assert(numbers[1] === 2); // Safe access to index 1
|
|
366
|
+
assert.isTrue(numbers[1] === 2); // Safe access to index 1
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
// Take first n elements
|
|
@@ -400,7 +400,7 @@ assert.deepStrictEqual(
|
|
|
400
400
|
);
|
|
401
401
|
|
|
402
402
|
if (Optional.isSome(oldestPerson)) {
|
|
403
|
-
assert(oldestPerson.value.name === 'Charlie');
|
|
403
|
+
assert.isTrue(oldestPerson.value.name === 'Charlie');
|
|
404
404
|
}
|
|
405
405
|
```
|
|
406
406
|
|
|
@@ -419,11 +419,11 @@ const mapWithOne = originalMap.set('one', 1);
|
|
|
419
419
|
const mapWithTwo = mapWithOne.set('two', 2);
|
|
420
420
|
|
|
421
421
|
// Original map is unchanged
|
|
422
|
-
assert(originalMap.size === 0);
|
|
422
|
+
assert.isTrue(originalMap.size === 0);
|
|
423
423
|
|
|
424
424
|
assert.deepStrictEqual(mapWithTwo.get('one'), Optional.some(1));
|
|
425
425
|
|
|
426
|
-
assert(
|
|
426
|
+
assert.isFalse(mapWithTwo.has('three'));
|
|
427
427
|
|
|
428
428
|
// Using pipe for fluent updates
|
|
429
429
|
const sequence = Arr.seq(10); // [0, 1, 2, ..., 9]
|
|
@@ -436,7 +436,7 @@ const skipped = Arr.skip(pairs, 1); // [[1, "1"], ..., [9, "9"]]
|
|
|
436
436
|
|
|
437
437
|
const idMap = IMap.create<number, string>(skipped);
|
|
438
438
|
|
|
439
|
-
assert(idMap.size === 9);
|
|
439
|
+
assert.isTrue(idMap.size === 9);
|
|
440
440
|
|
|
441
441
|
// Efficient batch updates with withMutations
|
|
442
442
|
const idMapUpdated = idMap.withMutations([
|
|
@@ -445,18 +445,18 @@ const idMapUpdated = idMap.withMutations([
|
|
|
445
445
|
{ type: 'delete', key: 4 },
|
|
446
446
|
]);
|
|
447
447
|
|
|
448
|
-
assert(idMapUpdated.size === 9);
|
|
448
|
+
assert.isTrue(idMapUpdated.size === 9);
|
|
449
449
|
|
|
450
450
|
// ISet usage
|
|
451
451
|
const originalSet = ISet.create<number>([]);
|
|
452
452
|
|
|
453
453
|
const setWithItems = originalSet.add(1).add(2).add(1); // Duplicate ignored
|
|
454
454
|
|
|
455
|
-
assert(originalSet.size === 0); // (unchanged)
|
|
455
|
+
assert.isTrue(originalSet.size === 0); // (unchanged)
|
|
456
456
|
|
|
457
|
-
assert(setWithItems.has(1));
|
|
457
|
+
assert.isTrue(setWithItems.has(1));
|
|
458
458
|
|
|
459
|
-
assert(setWithItems.size === 2);
|
|
459
|
+
assert.isTrue(setWithItems.size === 2);
|
|
460
460
|
```
|
|
461
461
|
|
|
462
462
|
### 6. Type Guards
|
|
@@ -488,11 +488,11 @@ if (isNonNullObject(value)) {
|
|
|
488
488
|
}
|
|
489
489
|
|
|
490
490
|
// Example usage
|
|
491
|
-
assert(processData({ name: 'Alice' }) === 'Hello, Alice!');
|
|
491
|
+
assert.isTrue(processData({ name: 'Alice' }) === 'Hello, Alice!');
|
|
492
492
|
|
|
493
|
-
assert(processData({ age: 30 }) === undefined);
|
|
493
|
+
assert.isTrue(processData({ age: 30 }) === undefined);
|
|
494
494
|
|
|
495
|
-
assert(processData('not an object') === undefined);
|
|
495
|
+
assert.isTrue(processData('not an object') === undefined);
|
|
496
496
|
```
|
|
497
497
|
|
|
498
498
|
### 7. Iteration with `range`
|
|
@@ -591,6 +591,8 @@ assert.deepStrictEqual(initialState.items, ['item1', 'item2']);
|
|
|
591
591
|
assert.deepStrictEqual(updatedState.items, ['newItem1', 'newItem2']);
|
|
592
592
|
```
|
|
593
593
|
|
|
594
|
+
**Note**: While [immer](https://immerjs.github.io/immer/) provides `castDraft` with similar usage, it recursively converts types to mutable, resulting in a more complex (fat) type implementation. When you only need shallow mutability conversion, using `castMutable` can potentially reduce type-checking computation overhead.
|
|
595
|
+
|
|
594
596
|
## Modules Overview
|
|
595
597
|
|
|
596
598
|
- **`expect-type`**: Compile-time type assertion utilities for testing and verification.
|
|
@@ -609,7 +611,7 @@ assert.deepStrictEqual(updatedState.items, ['newItem1', 'newItem2']);
|
|
|
609
611
|
- **Type Safety**: All utilities are designed with TypeScript's type system in mind, providing compile-time guarantees.
|
|
610
612
|
- **Immutability**: Data structures and operations promote immutable patterns for safer, more predictable code.
|
|
611
613
|
- **Functional Programming**: Support for functional programming paradigms with utilities like `Optional`, `Result`, and `pipe`.
|
|
612
|
-
- **Zero Runtime Dependencies**: The library has no external runtime dependencies, keeping your bundle size minimal.
|
|
614
|
+
- **Zero Runtime Dependencies**: The library has no external runtime dependencies except for [@sindresorhus/is](https://github.com/sindresorhus/is), keeping your bundle size minimal.
|
|
613
615
|
- **Comprehensive Testing**: All utilities are thoroughly tested with both runtime and compile-time tests.
|
|
614
616
|
|
|
615
617
|
**Important Notes:**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-utils-modification.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-modification.mts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAC3E,KAAK,EAAE,EAAE,EACT,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,EACxB,QAAQ,EAAE,CAAC,GACV,iBAAiB,CAAC,EAAE,CAAC,SAAS,IAAI,
|
|
1
|
+
{"version":3,"file":"array-utils-modification.d.mts","sourceRoot":"","sources":["../../../src/array/impl/array-utils-modification.mts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,SAAS,OAAO,EAAE,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAC3E,KAAK,EAAE,EAAE,EACT,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,EACxB,QAAQ,EAAE,CAAC,GACV,iBAAiB,CAAC,EAAE,CAAC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
1
|
-
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"array-utils-modification.mjs","sources":["../../../src/array/impl/array-utils-modification.mts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CM,SAAU,GAAG,CACjB,GAAG,IAE+C,EAAA;AAElD,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAI;;YAGrC,OAAQ,KAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC;QACnD;QAEA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAI;AAE9B,YAAA,OAAO,CAAC,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC;QAC/C;;AAEJ;AAkDM,SAAU,SAAS,CACvB,GAAG,IAM2D,EAAA;AAE9D,IAAA,QAAQ,IAAI,CAAC,MAAM;QACjB,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,IAAI;;AAGpC,YAAA,OAAQ,KAAmB,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAE,CAAC,CAAC;QACjE;QAEA,KAAK,CAAC,EAAE;AACN,YAAA,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,IAAI;AAE7B,YAAA,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC;QACpD;;AAEJ;AA4CM,SAAU,UAAU,CACxB,GAAG,IAM2D,EAAA;AAE9D,IAAA,QAAQ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YAAA,OAAO,CAAC,KAAK,KAAK,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC;QAC1D;;AAEJ;;;;"}
|
|
@@ -109,9 +109,9 @@ export declare function maxBy<const Ar extends readonly unknown[], V>(array: Ar,
|
|
|
109
109
|
*
|
|
110
110
|
* const withCurried = Arr.count<string>((word) => word.includes('a'))(words);
|
|
111
111
|
*
|
|
112
|
-
* assert(longWords === 2);
|
|
112
|
+
* assert.isTrue(longWords === 2);
|
|
113
113
|
*
|
|
114
|
-
* assert(withCurried === 2);
|
|
114
|
+
* assert.isTrue(withCurried === 2);
|
|
115
115
|
* ```
|
|
116
116
|
*/
|
|
117
117
|
export declare function count<const Ar extends readonly unknown[]>(array: Ar, predicate: (value: Ar[number], index: ArrayIndex<Ar>) => boolean): SizeType.Arr;
|
|
@@ -150,9 +150,9 @@ export declare function countBy<E, G extends MapSetKeyType>(grouper: (value: E,
|
|
|
150
150
|
* 'items',
|
|
151
151
|
* )(words);
|
|
152
152
|
*
|
|
153
|
-
* assert(totalLength === 11);
|
|
153
|
+
* assert.isTrue(totalLength === 11);
|
|
154
154
|
*
|
|
155
|
-
* assert(concat === 'items-Ada-Lovelace');
|
|
155
|
+
* assert.isTrue(concat === 'items-Ada-Lovelace');
|
|
156
156
|
* ```
|
|
157
157
|
*/
|
|
158
158
|
export declare function foldl<const Ar extends readonly unknown[], P>(array: Ar, callbackfn: (previousValue: P, currentValue: Ar[number], currentIndex: ArrayIndex<Ar>) => P, initialValue: P): P;
|
|
@@ -172,9 +172,9 @@ export declare function foldl<E, P>(callbackfn: (previousValue: P, currentValue:
|
|
|
172
172
|
* '',
|
|
173
173
|
* )(numbers);
|
|
174
174
|
*
|
|
175
|
-
* assert(subtractRight === -6);
|
|
175
|
+
* assert.isTrue(subtractRight === -6);
|
|
176
176
|
*
|
|
177
|
-
* assert(joinFromRight === '321');
|
|
177
|
+
* assert.isTrue(joinFromRight === '321');
|
|
178
178
|
* ```
|
|
179
179
|
*/
|
|
180
180
|
export declare function foldr<const Ar extends readonly unknown[], P>(array: Ar, callbackfn: (previousValue: P, currentValue: Ar[number], currentIndex: ArrayIndex<Ar>) => P, initialValue: P): P;
|
|
@@ -193,9 +193,9 @@ export declare function foldr<E, P>(callbackfn: (previousValue: P, currentValue:
|
|
|
193
193
|
*
|
|
194
194
|
* const totalNegatives = Arr.sum(negatives);
|
|
195
195
|
*
|
|
196
|
-
* assert(total === 10);
|
|
196
|
+
* assert.isTrue(total === 10);
|
|
197
197
|
*
|
|
198
|
-
* assert(totalNegatives === 6);
|
|
198
|
+
* assert.isTrue(totalNegatives === 6);
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
201
|
export declare function sum(array: readonly []): 0;
|
|
@@ -56,9 +56,9 @@ export declare function findLast<E>(predicate: (value: E, index: SizeType.Arr, a
|
|
|
56
56
|
* letters,
|
|
57
57
|
* );
|
|
58
58
|
*
|
|
59
|
-
* assert(indexOfB === 1);
|
|
59
|
+
* assert.isTrue(indexOfB === 1);
|
|
60
60
|
*
|
|
61
|
-
* assert(indexOfMissing === -1);
|
|
61
|
+
* assert.isTrue(indexOfMissing === -1);
|
|
62
62
|
* ```
|
|
63
63
|
*/
|
|
64
64
|
export declare function findIndex<const Ar extends readonly unknown[]>(array: Ar, predicate: (value: Ar[number], index: ArrayIndex<Ar>, arr: Ar) => boolean): ArrayIndex<Ar> | -1;
|
|
@@ -76,9 +76,9 @@ export declare function findIndex<E>(predicate: (value: E, index: SizeType.Arr,
|
|
|
76
76
|
* // eslint-disable-next-line unicorn/prefer-array-index-of
|
|
77
77
|
* const notFound = Arr.findLastIndex<string>((letter) => letter === 'z')(letters);
|
|
78
78
|
*
|
|
79
|
-
* assert(lastIndexOfB === 3);
|
|
79
|
+
* assert.isTrue(lastIndexOfB === 3);
|
|
80
80
|
*
|
|
81
|
-
* assert(notFound === -1);
|
|
81
|
+
* assert.isTrue(notFound === -1);
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
84
|
export declare function findLastIndex<const Ar extends readonly unknown[]>(array: Ar, predicate: (value: Ar[number], index: ArrayIndex<Ar>, arr: Ar) => boolean): ArrayIndex<Ar> | -1;
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*
|
|
11
11
|
* const differentNumbers = [1, 2, 4] as const;
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isTrue(Arr.eq(numbers, sameNumbers));
|
|
14
14
|
*
|
|
15
|
-
* assert.
|
|
15
|
+
* assert.isFalse(Arr.eq(numbers, differentNumbers));
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
export declare const eq: <E>(array1: readonly E[], array2: readonly E[], equality?: (a: E, b: E) => boolean) => boolean;
|
|
@@ -34,9 +34,9 @@ export declare const equal: <E>(array1: readonly E[], array2: readonly E[], equa
|
|
|
34
34
|
*
|
|
35
35
|
* const notSubset = [2, 4] as const;
|
|
36
36
|
*
|
|
37
|
-
* assert.
|
|
37
|
+
* assert.isTrue(Arr.isSubset(subset, superset));
|
|
38
38
|
*
|
|
39
|
-
* assert.
|
|
39
|
+
* assert.isFalse(Arr.isSubset(notSubset, superset));
|
|
40
40
|
* ```
|
|
41
41
|
*/
|
|
42
42
|
export declare const isSubset: <E1 extends Primitive, E2 extends Primitive = E1>(array1: readonly E1[], array2: readonly E2[]) => boolean;
|
|
@@ -52,11 +52,11 @@ export declare const isSubset: <E1 extends Primitive, E2 extends Primitive = E1>
|
|
|
52
52
|
*
|
|
53
53
|
* const notSuperset = ['a', 'd'] as const;
|
|
54
54
|
*
|
|
55
|
-
* assert.
|
|
55
|
+
* assert.isTrue(Arr.isSuperset(potentialSuperset, subset));
|
|
56
56
|
*
|
|
57
|
-
* assert.
|
|
57
|
+
* assert.isFalse(Arr.isSuperset(subset, potentialSuperset));
|
|
58
58
|
*
|
|
59
|
-
* assert.
|
|
59
|
+
* assert.isFalse(Arr.isSuperset(potentialSuperset, notSuperset));
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
62
|
export declare const isSuperset: <E1 extends Primitive, E2 extends Primitive = E1>(array1: readonly E1[], array2: readonly E2[]) => boolean;
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*
|
|
11
11
|
* const differentNumbers = [1, 2, 4] as const;
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isTrue(Arr.eq(numbers, sameNumbers));
|
|
14
14
|
*
|
|
15
|
-
* assert.
|
|
15
|
+
* assert.isFalse(Arr.eq(numbers, differentNumbers));
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
const eq = (array1, array2, equality = Object.is) => array1.length === array2.length &&
|
|
@@ -36,9 +36,9 @@ const equal = eq;
|
|
|
36
36
|
*
|
|
37
37
|
* const notSubset = [2, 4] as const;
|
|
38
38
|
*
|
|
39
|
-
* assert.
|
|
39
|
+
* assert.isTrue(Arr.isSubset(subset, superset));
|
|
40
40
|
*
|
|
41
|
-
* assert.
|
|
41
|
+
* assert.isFalse(Arr.isSubset(notSubset, superset));
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
const isSubset = (array1, array2) => array1.every((a) =>
|
|
@@ -56,11 +56,11 @@ array2.includes(a));
|
|
|
56
56
|
*
|
|
57
57
|
* const notSuperset = ['a', 'd'] as const;
|
|
58
58
|
*
|
|
59
|
-
* assert.
|
|
59
|
+
* assert.isTrue(Arr.isSuperset(potentialSuperset, subset));
|
|
60
60
|
*
|
|
61
|
-
* assert.
|
|
61
|
+
* assert.isFalse(Arr.isSuperset(subset, potentialSuperset));
|
|
62
62
|
*
|
|
63
|
-
* assert.
|
|
63
|
+
* assert.isFalse(Arr.isSuperset(potentialSuperset, notSuperset));
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
66
|
const isSuperset = (array1, array2) => isSubset(array2, array1);
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
*
|
|
13
13
|
* const sizeOfLetters = Arr.size(letters);
|
|
14
14
|
*
|
|
15
|
-
* assert(sizeOfNumbers === 3);
|
|
15
|
+
* assert.isTrue(sizeOfNumbers === 3);
|
|
16
16
|
*
|
|
17
|
-
* assert(sizeOfLetters === 0);
|
|
17
|
+
* assert.isTrue(sizeOfLetters === 0);
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
export declare const size: <const Ar extends readonly unknown[]>(array: Ar) => Ar extends NonEmptyArray<unknown> ? IntersectBrand<PositiveNumber, SizeType.Arr> : SizeType.Arr;
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* assert.deepStrictEqual(remainder, ['Grace', 'Katherine']);
|
|
13
13
|
*
|
|
14
|
-
* assert(remainder.length === 2);
|
|
14
|
+
* assert.isTrue(remainder.length === 2);
|
|
15
15
|
* }
|
|
16
16
|
*
|
|
17
17
|
* {
|
|
@@ -40,7 +40,7 @@ export declare const tail: <const Ar extends readonly unknown[]>(array: Ar) => L
|
|
|
40
40
|
*
|
|
41
41
|
* assert.deepStrictEqual(withoutLast, ['task-1', 'task-2']);
|
|
42
42
|
*
|
|
43
|
-
* assert(withoutLast.length === 2);
|
|
43
|
+
* assert.isTrue(withoutLast.length === 2);
|
|
44
44
|
* ```
|
|
45
45
|
*/
|
|
46
46
|
export declare const butLast: <const Ar extends readonly unknown[]>(array: Ar) => List.ButLast<Ar>;
|
|
@@ -45,7 +45,7 @@ import { isEmpty } from './array-utils-validation.mjs';
|
|
|
45
45
|
*
|
|
46
46
|
* assert.deepStrictEqual(remainder, ['Grace', 'Katherine']);
|
|
47
47
|
*
|
|
48
|
-
* assert(remainder.length === 2);
|
|
48
|
+
* assert.isTrue(remainder.length === 2);
|
|
49
49
|
* }
|
|
50
50
|
*
|
|
51
51
|
* {
|
|
@@ -76,7 +76,7 @@ array.slice(1);
|
|
|
76
76
|
*
|
|
77
77
|
* assert.deepStrictEqual(withoutLast, ['task-1', 'task-2']);
|
|
78
78
|
*
|
|
79
|
-
* assert(withoutLast.length === 2);
|
|
79
|
+
* assert.isTrue(withoutLast.length === 2);
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
82
|
const butLast = (array) =>
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
*
|
|
9
9
|
* const maybeValue: unknown = 'Ada';
|
|
10
10
|
*
|
|
11
|
-
* assert.
|
|
11
|
+
* assert.isTrue(Arr.isArray(maybeArray));
|
|
12
12
|
*
|
|
13
|
-
* assert.
|
|
13
|
+
* assert.isFalse(Arr.isArray(maybeValue));
|
|
14
14
|
*
|
|
15
15
|
* if (Arr.isArray(maybeArray)) {
|
|
16
16
|
* assert.deepStrictEqual(maybeArray, [1, 2, 3]);
|
|
@@ -30,9 +30,9 @@ type Cast<A, B> = A extends B ? A : never;
|
|
|
30
30
|
*
|
|
31
31
|
* const words = ['Ada', 'Lovelace'] as const;
|
|
32
32
|
*
|
|
33
|
-
* assert.
|
|
33
|
+
* assert.isTrue(Arr.isEmpty(emptyNumbers));
|
|
34
34
|
*
|
|
35
|
-
* assert.
|
|
35
|
+
* assert.isFalse(Arr.isEmpty(words));
|
|
36
36
|
*
|
|
37
37
|
* if (Arr.isEmpty(emptyNumbers)) {
|
|
38
38
|
* assert.deepStrictEqual(emptyNumbers, []);
|
|
@@ -50,9 +50,9 @@ export declare const isEmpty: <E>(array: readonly E[]) => array is readonly [];
|
|
|
50
50
|
*
|
|
51
51
|
* const emptyUsers: readonly { id: number }[] = [];
|
|
52
52
|
*
|
|
53
|
-
* assert.
|
|
53
|
+
* assert.isTrue(Arr.isNonEmpty(users));
|
|
54
54
|
*
|
|
55
|
-
* assert.
|
|
55
|
+
* assert.isFalse(Arr.isNonEmpty(emptyUsers));
|
|
56
56
|
*
|
|
57
57
|
* if (Arr.isNonEmpty(users)) {
|
|
58
58
|
* assert.deepStrictEqual(users[0], { id: 1 });
|
|
@@ -70,9 +70,9 @@ export declare const isNonEmpty: <E>(array: readonly E[]) => array is NonEmptyAr
|
|
|
70
70
|
*
|
|
71
71
|
* const triple: readonly number[] = [1, 2, 3];
|
|
72
72
|
*
|
|
73
|
-
* assert.
|
|
73
|
+
* assert.isTrue(Arr.isArrayOfLength(pair, 2));
|
|
74
74
|
*
|
|
75
|
-
* assert.
|
|
75
|
+
* assert.isFalse(Arr.isArrayOfLength(triple, 2));
|
|
76
76
|
*
|
|
77
77
|
* if (Arr.isArrayOfLength(pair, 2)) {
|
|
78
78
|
* assert.deepStrictEqual(pair, [1, 2]);
|
|
@@ -90,12 +90,12 @@ export declare const isArrayOfLength: <E, N extends SizeType.ArgArr>(array: read
|
|
|
90
90
|
*
|
|
91
91
|
* const emptyQueue: readonly string[] = [];
|
|
92
92
|
*
|
|
93
|
-
* assert.
|
|
93
|
+
* assert.isTrue(Arr.isArrayAtLeastLength(queue, 1));
|
|
94
94
|
*
|
|
95
|
-
* assert.
|
|
95
|
+
* assert.isFalse(Arr.isArrayAtLeastLength(emptyQueue, 1));
|
|
96
96
|
*
|
|
97
97
|
* if (Arr.isArrayAtLeastLength(queue, 1)) {
|
|
98
|
-
* assert(queue[0] === 'task-1');
|
|
98
|
+
* assert.isTrue(queue[0] === 'task-1');
|
|
99
99
|
* }
|
|
100
100
|
* ```
|
|
101
101
|
*/
|
|
@@ -114,9 +114,9 @@ export declare const isArrayAtLeastLength: <E, N extends SizeType.ArgArr>(array:
|
|
|
114
114
|
*
|
|
115
115
|
* const allStartWithA = Arr.every(words, (value) => value.startsWith('A'));
|
|
116
116
|
*
|
|
117
|
-
* assert.
|
|
117
|
+
* assert.isTrue(allEven);
|
|
118
118
|
*
|
|
119
|
-
* assert.
|
|
119
|
+
* assert.isFalse(allStartWithA);
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
122
|
export declare function every<E, S extends E>(array: readonly E[], predicate: (a: E, index: SizeType.Arr) => a is S): array is readonly S[];
|
|
@@ -137,9 +137,9 @@ export declare function every<E>(predicate: (a: E, index: SizeType.Arr) => boole
|
|
|
137
137
|
*
|
|
138
138
|
* const hasShortName = Arr.some(words, (value) => value.length <= 3);
|
|
139
139
|
*
|
|
140
|
-
* assert.
|
|
140
|
+
* assert.isFalse(hasEven);
|
|
141
141
|
*
|
|
142
|
-
* assert.
|
|
142
|
+
* assert.isTrue(hasShortName);
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
145
|
export declare function some<const Ar extends readonly unknown[]>(array: Ar, predicate: (a: Ar[number], index: ArrayIndex<Ar>) => boolean): boolean;
|
|
@@ -152,12 +152,12 @@ export declare function some<E>(predicate: (a: E, index: SizeType.Arr) => boolea
|
|
|
152
152
|
* ```ts
|
|
153
153
|
* const items = ['Ada', 'Grace', 'Katherine'] as const;
|
|
154
154
|
*
|
|
155
|
-
* assert.
|
|
155
|
+
* assert.isTrue(Arr.indexIsInRange(items, 1));
|
|
156
156
|
*
|
|
157
|
-
* assert.
|
|
157
|
+
* assert.isFalse(Arr.indexIsInRange(items, 3));
|
|
158
158
|
*
|
|
159
159
|
* if (Arr.indexIsInRange(items, 2)) {
|
|
160
|
-
* assert(items[2] === 'Katherine');
|
|
160
|
+
* assert.isTrue(items[2] === 'Katherine');
|
|
161
161
|
* }
|
|
162
162
|
* ```
|
|
163
163
|
*/
|