@pawells/typescript-common 1.3.1 → 2.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 +69 -15
- package/build/array/array-chunk.d.ts +1 -1
- package/build/array/array-chunk.d.ts.map +1 -1
- package/build/array/array-chunk.js.map +1 -1
- package/build/array/array-contains.d.ts +4 -1
- package/build/array/array-contains.d.ts.map +1 -1
- package/build/array/array-contains.js +4 -0
- package/build/array/array-contains.js.map +1 -1
- package/build/array/array-count-by.d.ts +3 -1
- package/build/array/array-count-by.d.ts.map +1 -1
- package/build/array/array-count-by.js +4 -1
- package/build/array/array-count-by.js.map +1 -1
- package/build/array/array-difference.d.ts +20 -9
- package/build/array/array-difference.d.ts.map +1 -1
- package/build/array/array-difference.js +25 -8
- package/build/array/array-difference.js.map +1 -1
- package/build/array/array-filter.d.ts +3 -1
- package/build/array/array-filter.d.ts.map +1 -1
- package/build/array/array-filter.js +4 -1
- package/build/array/array-filter.js.map +1 -1
- package/build/array/array-flatten.d.ts +1 -1
- package/build/array/array-flatten.d.ts.map +1 -1
- package/build/array/array-flatten.js.map +1 -1
- package/build/array/array-group-by.d.ts +3 -1
- package/build/array/array-group-by.d.ts.map +1 -1
- package/build/array/array-group-by.js +4 -1
- package/build/array/array-group-by.js.map +1 -1
- package/build/array/array-intersection.d.ts +20 -9
- package/build/array/array-intersection.d.ts.map +1 -1
- package/build/array/array-intersection.js +30 -12
- package/build/array/array-intersection.js.map +1 -1
- package/build/array/array-partition.d.ts +3 -1
- package/build/array/array-partition.d.ts.map +1 -1
- package/build/array/array-partition.js +4 -1
- package/build/array/array-partition.js.map +1 -1
- package/build/array/array-sample.d.ts +6 -2
- package/build/array/array-sample.d.ts.map +1 -1
- package/build/array/array-sample.js +8 -6
- package/build/array/array-sample.js.map +1 -1
- package/build/array/array-shuffle.d.ts +4 -2
- package/build/array/array-shuffle.d.ts.map +1 -1
- package/build/array/array-shuffle.js +6 -3
- package/build/array/array-shuffle.js.map +1 -1
- package/build/array/array-sort-by.d.ts +1 -1
- package/build/array/array-sort-by.d.ts.map +1 -1
- package/build/array/array-sort-by.js.map +1 -1
- package/build/array/assert.d.ts +22 -18
- package/build/array/assert.d.ts.map +1 -1
- package/build/array/assert.js +27 -23
- package/build/array/assert.js.map +1 -1
- package/build/array/types.d.ts +11 -0
- package/build/array/types.d.ts.map +1 -1
- package/build/array/unique.d.ts +3 -1
- package/build/array/unique.d.ts.map +1 -1
- package/build/array/unique.js +4 -1
- package/build/array/unique.js.map +1 -1
- package/build/asserts/generic.d.ts +9 -0
- package/build/asserts/generic.d.ts.map +1 -1
- package/build/asserts/generic.js +30 -8
- package/build/asserts/generic.js.map +1 -1
- package/build/asserts/utils.d.ts +32 -0
- package/build/asserts/utils.d.ts.map +1 -1
- package/build/asserts/utils.js +79 -0
- package/build/asserts/utils.js.map +1 -1
- package/build/boolean/assert.d.ts.map +1 -1
- package/build/boolean/assert.js +2 -5
- package/build/boolean/assert.js.map +1 -1
- package/build/function/compose.d.ts +3 -2
- package/build/function/compose.d.ts.map +1 -1
- package/build/function/compose.js.map +1 -1
- package/build/function/debounce.d.ts +2 -1
- package/build/function/debounce.d.ts.map +1 -1
- package/build/function/debounce.js.map +1 -1
- package/build/function/once.d.ts +1 -0
- package/build/function/once.d.ts.map +1 -1
- package/build/function/once.js +1 -0
- package/build/function/once.js.map +1 -1
- package/build/function/throttle.d.ts +2 -1
- package/build/function/throttle.d.ts.map +1 -1
- package/build/function/throttle.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/number/assert.d.ts.map +1 -1
- package/build/number/assert.js +38 -42
- package/build/number/assert.js.map +1 -1
- package/build/object/clone.d.ts.map +1 -1
- package/build/object/clone.js +3 -0
- package/build/object/clone.js.map +1 -1
- package/build/object/equals.d.ts +1 -1
- package/build/object/equals.d.ts.map +1 -1
- package/build/object/equals.js +14 -7
- package/build/object/equals.js.map +1 -1
- package/build/object/filter-cached.js.map +1 -1
- package/build/object/filter.d.ts +7 -1
- package/build/object/filter.d.ts.map +1 -1
- package/build/object/filter.js +36 -61
- package/build/object/filter.js.map +1 -1
- package/build/object/hash.d.ts +1 -1
- package/build/object/hash.d.ts.map +1 -1
- package/build/object/hash.js +1 -0
- package/build/object/hash.js.map +1 -1
- package/build/object/key-value-pairs.d.ts +1 -1
- package/build/object/key-value-pairs.d.ts.map +1 -1
- package/build/object/key-value-pairs.js.map +1 -1
- package/build/object/omit.d.ts +1 -1
- package/build/object/omit.d.ts.map +1 -1
- package/build/object/omit.js.map +1 -1
- package/build/object/pick.d.ts +1 -1
- package/build/object/pick.d.ts.map +1 -1
- package/build/object/pick.js.map +1 -1
- package/build/object/property-paths.d.ts +2 -2
- package/build/object/property-paths.d.ts.map +1 -1
- package/build/object/property-paths.js +7 -2
- package/build/object/property-paths.js.map +1 -1
- package/build/object/security-utils.d.ts +2 -2
- package/build/object/security-utils.d.ts.map +1 -1
- package/build/object/security-utils.js.map +1 -1
- package/build/object/types.d.ts +1 -1
- package/build/object/types.d.ts.map +1 -1
- package/build/string/assert.d.ts.map +1 -1
- package/build/string/assert.js +3 -9
- package/build/string/assert.js.map +1 -1
- package/build/string/case-conversion.d.ts +53 -24
- package/build/string/case-conversion.d.ts.map +1 -1
- package/build/string/case-conversion.js +59 -29
- package/build/string/case-conversion.js.map +1 -1
- package/build/string/comparison.d.ts +20 -0
- package/build/string/comparison.d.ts.map +1 -0
- package/build/string/comparison.js +25 -0
- package/build/string/comparison.js.map +1 -0
- package/build/string/formatting.d.ts +35 -22
- package/build/string/formatting.d.ts.map +1 -1
- package/build/string/formatting.js +35 -22
- package/build/string/formatting.js.map +1 -1
- package/build/string/index.d.ts +1 -0
- package/build/string/index.d.ts.map +1 -1
- package/build/string/index.js +1 -0
- package/build/string/index.js.map +1 -1
- package/build/string/transformation.d.ts +19 -9
- package/build/string/transformation.d.ts.map +1 -1
- package/build/string/transformation.js +21 -10
- package/build/string/transformation.js.map +1 -1
- package/build/string/validation.d.ts +21 -9
- package/build/string/validation.d.ts.map +1 -1
- package/build/string/validation.js +23 -10
- package/build/string/validation.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,6 +2,8 @@ import type { TPredicate } from './types.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Splits an array into two groups: elements that satisfy the predicate and those that do not.
|
|
4
4
|
*
|
|
5
|
+
* Returns `[[], []]` if array is null, undefined, or empty.
|
|
6
|
+
*
|
|
5
7
|
* @template T - The type of array elements
|
|
6
8
|
* @param array - The array to partition
|
|
7
9
|
* @param predicate - The condition to test each element against
|
|
@@ -15,5 +17,5 @@ import type { TPredicate } from './types.js';
|
|
|
15
17
|
* const [admins, users] = ArrayPartition(users, (u) => u.role === 'admin');
|
|
16
18
|
* ```
|
|
17
19
|
*/
|
|
18
|
-
export declare function ArrayPartition<T>(array: T[], predicate: TPredicate<T>): [T[], T[]];
|
|
20
|
+
export declare function ArrayPartition<T>(array: readonly T[], predicate: TPredicate<T>): [T[], T[]];
|
|
19
21
|
//# sourceMappingURL=array-partition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-partition.d.ts","sourceRoot":"","sources":["../../src/array/array-partition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C
|
|
1
|
+
{"version":3,"file":"array-partition.d.ts","sourceRoot":"","sources":["../../src/array/array-partition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAgB3F"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Splits an array into two groups: elements that satisfy the predicate and those that do not.
|
|
3
3
|
*
|
|
4
|
+
* Returns `[[], []]` if array is null, undefined, or empty.
|
|
5
|
+
*
|
|
4
6
|
* @template T - The type of array elements
|
|
5
7
|
* @param array - The array to partition
|
|
6
8
|
* @param predicate - The condition to test each element against
|
|
@@ -15,7 +17,8 @@
|
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
17
19
|
export function ArrayPartition(array, predicate) {
|
|
18
|
-
|
|
20
|
+
// Consistent null-check: early return for null/undefined arrays
|
|
21
|
+
if (!array)
|
|
19
22
|
return [[], []];
|
|
20
23
|
const matches = [];
|
|
21
24
|
const rest = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-partition.js","sourceRoot":"","sources":["../../src/array/array-partition.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"array-partition.js","sourceRoot":"","sources":["../../src/array/array-partition.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,cAAc,CAAI,KAAmB,EAAE,SAAwB;IAC9E,gEAAgE;IAChE,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAE5B,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,MAAM,IAAI,GAAQ,EAAE,CAAC;IAErB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,CAAC;IACF,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of array elements
|
|
5
5
|
* @param array - The array to sample from
|
|
6
|
+
* @param random - Optional custom RNG function (returns number between 0 and 1). Defaults to `Math.random`.
|
|
6
7
|
* @returns A random element, or `undefined` if the array is empty
|
|
7
8
|
*
|
|
8
9
|
* @example
|
|
9
10
|
* ```typescript
|
|
10
11
|
* ArraySample([1, 2, 3, 4, 5]); // e.g. 3
|
|
12
|
+
* ArraySample([1, 2, 3], undefined, () => 0.5); // deterministic with custom RNG
|
|
11
13
|
* ```
|
|
12
14
|
*/
|
|
13
|
-
export declare function ArraySample<T>(array: T[]): T | undefined;
|
|
15
|
+
export declare function ArraySample<T>(array: readonly T[]): T | undefined;
|
|
14
16
|
/**
|
|
15
17
|
* Returns `n` unique random elements from an array (without replacement).
|
|
16
18
|
* If `n` exceeds the array length, all elements are returned in random order.
|
|
@@ -18,12 +20,14 @@ export declare function ArraySample<T>(array: T[]): T | undefined;
|
|
|
18
20
|
* @template T - The type of array elements
|
|
19
21
|
* @param array - The array to sample from
|
|
20
22
|
* @param n - How many elements to sample
|
|
23
|
+
* @param random - Optional custom RNG function (returns number between 0 and 1). Defaults to `Math.random`.
|
|
21
24
|
* @returns An array of `n` randomly selected elements
|
|
22
25
|
*
|
|
23
26
|
* @example
|
|
24
27
|
* ```typescript
|
|
25
28
|
* ArraySample([1, 2, 3, 4, 5], 3); // e.g. [4, 1, 3]
|
|
29
|
+
* ArraySample([1, 2, 3], 2, () => 0.5); // deterministic with custom RNG
|
|
26
30
|
* ```
|
|
27
31
|
*/
|
|
28
|
-
export declare function ArraySample<T>(array: T[], n: number): T[];
|
|
32
|
+
export declare function ArraySample<T>(array: readonly T[], n: number, random?: () => number): T[];
|
|
29
33
|
//# sourceMappingURL=array-sample.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-sample.d.ts","sourceRoot":"","sources":["../../src/array/array-sample.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array-sample.d.ts","sourceRoot":"","sources":["../../src/array/array-sample.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,GAAG,CAAC,EAAE,CAAC"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
export function ArraySample(array, n) {
|
|
1
|
+
export function ArraySample(array, n, random) {
|
|
2
|
+
const sampleCount = n;
|
|
3
|
+
const rng = random ?? Math.random;
|
|
2
4
|
if (!array || array.length === 0) {
|
|
3
|
-
return
|
|
5
|
+
return sampleCount !== undefined ? [] : undefined;
|
|
4
6
|
}
|
|
5
|
-
if (
|
|
6
|
-
return array[Math.floor(
|
|
7
|
+
if (sampleCount === undefined) {
|
|
8
|
+
return array[Math.floor(rng() * array.length)];
|
|
7
9
|
}
|
|
8
10
|
// Fisher-Yates partial shuffle for O(n) sampling
|
|
9
11
|
const copy = [...array];
|
|
10
|
-
const count = Math.min(
|
|
12
|
+
const count = Math.min(sampleCount, copy.length);
|
|
11
13
|
for (let i = 0; i < count; i++) {
|
|
12
|
-
const j = i + Math.floor(
|
|
14
|
+
const j = i + Math.floor(rng() * (copy.length - i));
|
|
13
15
|
const tmp = copy[j];
|
|
14
16
|
copy[j] = copy[i];
|
|
15
17
|
copy[i] = tmp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-sample.js","sourceRoot":"","sources":["../../src/array/array-sample.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"array-sample.js","sourceRoot":"","sources":["../../src/array/array-sample.ts"],"names":[],"mappings":"AAkCA,MAAM,UAAU,WAAW,CAAI,KAAmB,EAAE,CAAU,EAAE,MAAqB;IACpF,MAAM,WAAW,GAAG,CAAC,CAAC;IACtB,MAAM,GAAG,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;IAElC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACnD,CAAC;IAED,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,iDAAiD;IACjD,MAAM,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAChC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;QACpD,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAM,CAAC;QACzB,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAM,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of array elements
|
|
5
5
|
* @param array - The array to shuffle
|
|
6
|
+
* @param random - Optional custom RNG function (returns number between 0 and 1). Defaults to `Math.random`.
|
|
6
7
|
* @returns A new shuffled array (original is not mutated)
|
|
7
8
|
*
|
|
8
|
-
* @remarks Uses `Math.random()` — not cryptographically secure. Do not use for
|
|
9
|
+
* @remarks Uses `Math.random()` by default — not cryptographically secure. Do not use for
|
|
9
10
|
* security-sensitive operations.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* ```typescript
|
|
13
14
|
* ArrayShuffle([1, 2, 3, 4, 5]); // e.g. [3, 1, 5, 2, 4]
|
|
15
|
+
* ArrayShuffle([1, 2, 3], () => 0.5); // deterministic with custom RNG
|
|
14
16
|
* ```
|
|
15
17
|
*/
|
|
16
|
-
export declare function ArrayShuffle<T>(array: T[]): T[];
|
|
18
|
+
export declare function ArrayShuffle<T>(array: readonly T[], random?: () => number): T[];
|
|
17
19
|
//# sourceMappingURL=array-shuffle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-shuffle.d.ts","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array-shuffle.d.ts","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,GAAG,CAAC,EAAE,CAc/E"}
|
|
@@ -3,22 +3,25 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @template T - The type of array elements
|
|
5
5
|
* @param array - The array to shuffle
|
|
6
|
+
* @param random - Optional custom RNG function (returns number between 0 and 1). Defaults to `Math.random`.
|
|
6
7
|
* @returns A new shuffled array (original is not mutated)
|
|
7
8
|
*
|
|
8
|
-
* @remarks Uses `Math.random()` — not cryptographically secure. Do not use for
|
|
9
|
+
* @remarks Uses `Math.random()` by default — not cryptographically secure. Do not use for
|
|
9
10
|
* security-sensitive operations.
|
|
10
11
|
*
|
|
11
12
|
* @example
|
|
12
13
|
* ```typescript
|
|
13
14
|
* ArrayShuffle([1, 2, 3, 4, 5]); // e.g. [3, 1, 5, 2, 4]
|
|
15
|
+
* ArrayShuffle([1, 2, 3], () => 0.5); // deterministic with custom RNG
|
|
14
16
|
* ```
|
|
15
17
|
*/
|
|
16
|
-
export function ArrayShuffle(array) {
|
|
18
|
+
export function ArrayShuffle(array, random) {
|
|
17
19
|
if (array === null || array === undefined)
|
|
18
20
|
return [];
|
|
21
|
+
const rng = random ?? Math.random;
|
|
19
22
|
const result = [...array];
|
|
20
23
|
for (let i = result.length - 1; i > 0; i--) {
|
|
21
|
-
const j = Math.floor(
|
|
24
|
+
const j = Math.floor(rng() * (i + 1));
|
|
22
25
|
const temp = result[i];
|
|
23
26
|
result[i] = result[j];
|
|
24
27
|
result[j] = temp;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-shuffle.js","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"array-shuffle.js","sourceRoot":"","sources":["../../src/array/array-shuffle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAAI,KAAmB,EAAE,MAAqB;IACzE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAErD,MAAM,GAAG,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;IAClC,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAE1B,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACvB,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAM,CAAC;QAC3B,MAAM,CAAC,CAAC,CAAC,GAAG,IAAS,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -16,5 +16,5 @@ import type { TTransform } from './types.js';
|
|
|
16
16
|
* ArraySortBy([3, 1, 2], (n) => n, 'desc'); // [3, 2, 1]
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
export declare function ArraySortBy<T>(array: T[], keyFn: TTransform<T, string | number>, direction?: 'asc' | 'desc'): T[];
|
|
19
|
+
export declare function ArraySortBy<T>(array: readonly T[], keyFn: TTransform<T, string | number>, direction?: 'asc' | 'desc'): T[];
|
|
20
20
|
//# sourceMappingURL=array-sort-by.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-sort-by.d.ts","sourceRoot":"","sources":["../../src/array/array-sort-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,KAAK,EAAE,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"array-sort-by.d.ts","sourceRoot":"","sources":["../../src/array/array-sort-by.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC5B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,EACrC,SAAS,GAAE,KAAK,GAAG,MAAc,GAC/B,CAAC,EAAE,CAWL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-sort-by.js","sourceRoot":"","sources":["../../src/array/array-sort-by.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAC1B,
|
|
1
|
+
{"version":3,"file":"array-sort-by.js","sourceRoot":"","sources":["../../src/array/array-sort-by.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,WAAW,CAC1B,KAAmB,EACnB,KAAqC,EACrC,YAA4B,KAAK;IAEjC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IAErD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC/B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAEtB,IAAI,IAAI,GAAG,IAAI;YAAE,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,IAAI,IAAI,GAAG,IAAI;YAAE,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrD,OAAO,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/build/array/assert.d.ts
CHANGED
|
@@ -15,10 +15,6 @@ export interface IAssertArrayArgs {
|
|
|
15
15
|
/** Maximum number of elements the array must contain (inclusive) */
|
|
16
16
|
maxSize?: number;
|
|
17
17
|
}
|
|
18
|
-
/**
|
|
19
|
-
* Alias for {@link IAssertArrayArgs}. Kept for backwards compatibility.
|
|
20
|
-
*/
|
|
21
|
-
export type TSizeConstraint = IAssertArrayArgs;
|
|
22
18
|
/**
|
|
23
19
|
* Type alias for 2D dimension constraint properties.
|
|
24
20
|
* Represents constraints that can be applied to matrix dimensions.
|
|
@@ -64,44 +60,52 @@ export interface IAssertArray2DArgs {
|
|
|
64
60
|
/**
|
|
65
61
|
* Asserts that a value is an array, optionally validating its size.
|
|
66
62
|
* @template T The type of array elements.
|
|
67
|
-
* @param value The value to validate.
|
|
68
|
-
* @param args Optional size constraints.
|
|
69
|
-
* @param exception Optional custom exception to throw.
|
|
63
|
+
* @param value - The value to validate.
|
|
64
|
+
* @param args - Optional size constraints.
|
|
65
|
+
* @param exception - Optional custom exception to throw.
|
|
70
66
|
* @throws {ArrayError} If the value is not an array or fails size validation.
|
|
71
67
|
*/
|
|
72
68
|
export declare function AssertArray<T = unknown>(value: unknown, args?: IAssertArrayArgs, exception?: IAssertException): asserts value is T[];
|
|
73
69
|
/**
|
|
74
70
|
* Asserts that a value is a 2D array, optionally validating its dimensions.
|
|
75
71
|
* @template T The type of array elements.
|
|
76
|
-
* @param value The value to validate.
|
|
77
|
-
* @param args Optional dimension constraints.
|
|
78
|
-
* @param exception Optional custom exception to throw.
|
|
72
|
+
* @param value - The value to validate.
|
|
73
|
+
* @param args - Optional dimension constraints.
|
|
74
|
+
* @param exception - Optional custom exception to throw.
|
|
79
75
|
* @throws {ArrayError} If the value is not a 2D array or fails dimension validation.
|
|
80
76
|
*/
|
|
81
77
|
export declare function AssertArray2D<T = unknown>(value: unknown, args?: IAssertArray2DArgs, exception?: IAssertException): asserts value is T[][];
|
|
82
78
|
/**
|
|
83
79
|
* Asserts that an array is not empty.
|
|
84
80
|
* @template T The type of array elements.
|
|
85
|
-
* @param value The array to validate.
|
|
86
|
-
* @param exception Optional custom exception to throw.
|
|
81
|
+
* @param value - The array to validate.
|
|
82
|
+
* @param exception - Optional custom exception to throw.
|
|
87
83
|
* @throws {ArrayError} If the array is empty.
|
|
88
84
|
*/
|
|
89
85
|
export declare function AssertArrayNotEmpty<T>(value: T[] | unknown, exception?: IAssertException): asserts value is T[];
|
|
90
86
|
/**
|
|
91
87
|
* Asserts that all elements in an array satisfy a predicate.
|
|
88
|
+
*
|
|
89
|
+
* Uses `array.every()` to check if all elements satisfy the predicate condition.
|
|
90
|
+
* Throws an error if any element fails the test.
|
|
91
|
+
*
|
|
92
92
|
* @template T The type of array elements.
|
|
93
|
-
* @param array The array to validate.
|
|
94
|
-
* @param predicate A function to test each element.
|
|
95
|
-
* @param exception Optional custom exception to throw.
|
|
93
|
+
* @param array - The array to validate.
|
|
94
|
+
* @param predicate - A function to test each element.
|
|
95
|
+
* @param exception - Optional custom exception to throw.
|
|
96
96
|
* @throws {ArrayError} If any element fails the predicate test.
|
|
97
97
|
*/
|
|
98
98
|
export declare function AssertArrayAll<T>(array: T[], predicate: (el: T, idx: number, arr: T[]) => boolean, exception?: IAssertException): void;
|
|
99
99
|
/**
|
|
100
100
|
* Asserts that at least one element in an array satisfies a predicate.
|
|
101
|
+
*
|
|
102
|
+
* Uses `array.some()` to check if any element satisfies the predicate condition.
|
|
103
|
+
* Throws an error if no elements pass the test.
|
|
104
|
+
*
|
|
101
105
|
* @template T The type of array elements.
|
|
102
|
-
* @param array The array to validate.
|
|
103
|
-
* @param predicate A function to test each element.
|
|
104
|
-
* @param exception Optional custom exception to throw.
|
|
106
|
+
* @param array - The array to validate.
|
|
107
|
+
* @param predicate - A function to test each element.
|
|
108
|
+
* @param exception - Optional custom exception to throw.
|
|
105
109
|
* @throws {ArrayError} If no elements pass the predicate test.
|
|
106
110
|
*/
|
|
107
111
|
export declare function AssertArrayAny<T>(array: T[], predicate: (el: T, idx: number, arr: T[]) => boolean, exception?: IAssertException): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/array/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,sDAAsD;IACtD,IAAI,CAA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,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,gBAAgB,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,EAAE,CA2BxI;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,GAAE,kBAAuB,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,EAAE,EAAE,CAoElJ;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,EAAE,CAYnH;AAWD;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAO1I;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,SAAS,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAO1I"}
|
package/build/array/assert.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SetExceptionClass, SetExceptionMessage, ThrowException } from '../asserts/utils.js';
|
|
1
|
+
import { SetExceptionClass, SetExceptionMessage, ThrowException, AssertValueType } from '../asserts/utils.js';
|
|
2
2
|
import { SimpleError } from '../asserts/errors.js';
|
|
3
3
|
/**
|
|
4
4
|
* Error thrown when a value is not a valid array or fails an array assertion.
|
|
@@ -14,19 +14,16 @@ export class ArrayError extends SimpleError {
|
|
|
14
14
|
/**
|
|
15
15
|
* Asserts that a value is an array, optionally validating its size.
|
|
16
16
|
* @template T The type of array elements.
|
|
17
|
-
* @param value The value to validate.
|
|
18
|
-
* @param args Optional size constraints.
|
|
19
|
-
* @param exception Optional custom exception to throw.
|
|
17
|
+
* @param value - The value to validate.
|
|
18
|
+
* @param args - Optional size constraints.
|
|
19
|
+
* @param exception - Optional custom exception to throw.
|
|
20
20
|
* @throws {ArrayError} If the value is not an array or fails size validation.
|
|
21
21
|
*/
|
|
22
22
|
export function AssertArray(value, args, exception = {}) {
|
|
23
23
|
// Initialize exception configuration with defaults
|
|
24
24
|
SetExceptionClass(exception, ArrayError);
|
|
25
25
|
// Validate that the value is an array
|
|
26
|
-
|
|
27
|
-
SetExceptionMessage(exception, `Expected array but received ${typeof value}: ${String(value)}`);
|
|
28
|
-
ThrowException(exception);
|
|
29
|
-
}
|
|
26
|
+
AssertValueType(value, 'array', exception);
|
|
30
27
|
// Type cast is safe after array validation
|
|
31
28
|
const array = value;
|
|
32
29
|
// Validate exact size constraint if specified
|
|
@@ -48,19 +45,16 @@ export function AssertArray(value, args, exception = {}) {
|
|
|
48
45
|
/**
|
|
49
46
|
* Asserts that a value is a 2D array, optionally validating its dimensions.
|
|
50
47
|
* @template T The type of array elements.
|
|
51
|
-
* @param value The value to validate.
|
|
52
|
-
* @param args Optional dimension constraints.
|
|
53
|
-
* @param exception Optional custom exception to throw.
|
|
48
|
+
* @param value - The value to validate.
|
|
49
|
+
* @param args - Optional dimension constraints.
|
|
50
|
+
* @param exception - Optional custom exception to throw.
|
|
54
51
|
* @throws {ArrayError} If the value is not a 2D array or fails dimension validation.
|
|
55
52
|
*/
|
|
56
53
|
export function AssertArray2D(value, args = {}, exception = {}) {
|
|
57
54
|
// Initialize exception configuration with defaults
|
|
58
55
|
SetExceptionClass(exception, ArrayError);
|
|
59
56
|
// Validate that the value is an array
|
|
60
|
-
|
|
61
|
-
SetExceptionMessage(exception, `Expected array but received ${typeof value}: ${String(value)}`);
|
|
62
|
-
ThrowException(exception);
|
|
63
|
-
}
|
|
57
|
+
AssertValueType(value, 'array', exception);
|
|
64
58
|
// Type cast is safe after array validation
|
|
65
59
|
const array = value;
|
|
66
60
|
// Validate that all elements are arrays (making it 2D)
|
|
@@ -118,8 +112,8 @@ export function AssertArray2D(value, args = {}, exception = {}) {
|
|
|
118
112
|
/**
|
|
119
113
|
* Asserts that an array is not empty.
|
|
120
114
|
* @template T The type of array elements.
|
|
121
|
-
* @param value The array to validate.
|
|
122
|
-
* @param exception Optional custom exception to throw.
|
|
115
|
+
* @param value - The array to validate.
|
|
116
|
+
* @param exception - Optional custom exception to throw.
|
|
123
117
|
* @throws {ArrayError} If the array is empty.
|
|
124
118
|
*/
|
|
125
119
|
export function AssertArrayNotEmpty(value, exception = {}) {
|
|
@@ -143,13 +137,18 @@ function assertIsArray(array, exception) {
|
|
|
143
137
|
}
|
|
144
138
|
/**
|
|
145
139
|
* Asserts that all elements in an array satisfy a predicate.
|
|
140
|
+
*
|
|
141
|
+
* Uses `array.every()` to check if all elements satisfy the predicate condition.
|
|
142
|
+
* Throws an error if any element fails the test.
|
|
143
|
+
*
|
|
146
144
|
* @template T The type of array elements.
|
|
147
|
-
* @param array The array to validate.
|
|
148
|
-
* @param predicate A function to test each element.
|
|
149
|
-
* @param exception Optional custom exception to throw.
|
|
145
|
+
* @param array - The array to validate.
|
|
146
|
+
* @param predicate - A function to test each element.
|
|
147
|
+
* @param exception - Optional custom exception to throw.
|
|
150
148
|
* @throws {ArrayError} If any element fails the predicate test.
|
|
151
149
|
*/
|
|
152
150
|
export function AssertArrayAll(array, predicate, exception = {}) {
|
|
151
|
+
// Predicate functions use array.some() / array.every() for consistency
|
|
153
152
|
assertIsArray(array, exception);
|
|
154
153
|
if (!array.every(predicate)) {
|
|
155
154
|
SetExceptionMessage(exception, 'Not all elements satisfy the predicate condition');
|
|
@@ -158,13 +157,18 @@ export function AssertArrayAll(array, predicate, exception = {}) {
|
|
|
158
157
|
}
|
|
159
158
|
/**
|
|
160
159
|
* Asserts that at least one element in an array satisfies a predicate.
|
|
160
|
+
*
|
|
161
|
+
* Uses `array.some()` to check if any element satisfies the predicate condition.
|
|
162
|
+
* Throws an error if no elements pass the test.
|
|
163
|
+
*
|
|
161
164
|
* @template T The type of array elements.
|
|
162
|
-
* @param array The array to validate.
|
|
163
|
-
* @param predicate A function to test each element.
|
|
164
|
-
* @param exception Optional custom exception to throw.
|
|
165
|
+
* @param array - The array to validate.
|
|
166
|
+
* @param predicate - A function to test each element.
|
|
167
|
+
* @param exception - Optional custom exception to throw.
|
|
165
168
|
* @throws {ArrayError} If no elements pass the predicate test.
|
|
166
169
|
*/
|
|
167
170
|
export function AssertArrayAny(array, predicate, exception = {}) {
|
|
171
|
+
// Predicate functions use array.some() / array.every() for consistency
|
|
168
172
|
assertIsArray(array, exception);
|
|
169
173
|
if (!array.some(predicate)) {
|
|
170
174
|
SetExceptionMessage(exception, 'No elements satisfy the predicate condition');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/array/assert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/array/assert.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AA+BnD;;;;;GAKG;AACH,MAAM,OAAO,UAAW,SAAQ,WAAW;IAC1C,YAAY,OAAgB;QAC3B,KAAK,CAAC,OAAO,IAAI,wBAAwB,CAAC,CAAC;IAC5C,CAAC;CACD;AAwBD;;;;;;;GAOG;AACH,MAAM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,CAAC;AACF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,cAAc,CAAI,KAAU,EAAE,SAAoD,EAAE,YAA8B,EAAE;IACnI,uEAAuE;IACvE,aAAa,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,mBAAmB,CAAC,SAAS,EAAE,6CAA6C,CAAC,CAAC;QAC9E,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;AACF,CAAC"}
|
package/build/array/types.d.ts
CHANGED
|
@@ -29,4 +29,15 @@ export type TComparator<T> = (a: T, b: T) => number;
|
|
|
29
29
|
* @returns true if values are equal, false otherwise
|
|
30
30
|
*/
|
|
31
31
|
export type TEqualityComparator<T> = (a: T, b: T) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Options for comparing array elements.
|
|
34
|
+
* Supports both custom comparator functions and deep equality checking.
|
|
35
|
+
*
|
|
36
|
+
* @template T - The type of array elements
|
|
37
|
+
*/
|
|
38
|
+
export type TArrayComparisonOptions<T> = {
|
|
39
|
+
comparator?: TEqualityComparator<T>;
|
|
40
|
+
} | {
|
|
41
|
+
useDeepEqual?: boolean;
|
|
42
|
+
};
|
|
32
43
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,EAAE,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/array/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,EAAE,OAAO,IAAI,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAClC;IAAE,UAAU,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAA;CAAE,GACvC;IAAE,YAAY,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC"}
|
package/build/array/unique.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a new array with duplicate values removed.
|
|
3
3
|
*
|
|
4
|
+
* Returns empty array if input is null, undefined, or empty.
|
|
5
|
+
*
|
|
4
6
|
* @template T - The type of array elements
|
|
5
7
|
* @param array - The input array
|
|
6
8
|
* @returns A new array containing only unique values (preserves first occurrence order)
|
|
@@ -14,5 +16,5 @@
|
|
|
14
16
|
* Unique(['a', 'b', 'a']); // ['a', 'b']
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
17
|
-
export declare function Unique<T>(array: T[]): T[];
|
|
19
|
+
export declare function Unique<T>(array: readonly T[]): T[];
|
|
18
20
|
//# sourceMappingURL=unique.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unique.d.ts","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"unique.d.ts","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE,CAOlD"}
|
package/build/array/unique.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a new array with duplicate values removed.
|
|
3
3
|
*
|
|
4
|
+
* Returns empty array if input is null, undefined, or empty.
|
|
5
|
+
*
|
|
4
6
|
* @template T - The type of array elements
|
|
5
7
|
* @param array - The input array
|
|
6
8
|
* @returns A new array containing only unique values (preserves first occurrence order)
|
|
@@ -15,7 +17,8 @@
|
|
|
15
17
|
* ```
|
|
16
18
|
*/
|
|
17
19
|
export function Unique(array) {
|
|
18
|
-
|
|
20
|
+
// Consistent null-check: early return for null/undefined/empty arrays
|
|
21
|
+
if (!array || array.length === 0) {
|
|
19
22
|
return [];
|
|
20
23
|
}
|
|
21
24
|
return [...new Set(array)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unique.js","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"unique.js","sourceRoot":"","sources":["../../src/array/unique.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,MAAM,CAAI,KAAmB;IAC5C,sEAAsE;IACtE,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,EAAE,CAAC;IACX,CAAC;IAED,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { IAssertException, TGuard, TValidationPredicate } from './types.js';
|
|
2
2
|
import { SimpleError } from './errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Gets the display type of a value including null and undefined.
|
|
5
|
+
* Used for error messages in null/undefined assertions and type checking.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The value to get the type of
|
|
8
|
+
* @returns A string representation of the value's type ('null', 'undefined', 'array', 'object', or typeof)
|
|
9
|
+
* @internal Used internally by assertion functions for consistent type messages
|
|
10
|
+
*/
|
|
11
|
+
export declare function GetValueType(value: unknown): string;
|
|
3
12
|
/**
|
|
4
13
|
* Type alias for constructor functions.
|
|
5
14
|
* Represents any class constructor that can be instantiated.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/asserts/generic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEjF,OAAO,EAAkB,WAAW,EAAE,MAAM,aAAa,CAAC;AAc1D;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,GAAG,GAAG,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEtE;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,WAAW;gBAC7B,OAAO,CAAC,EAAE,MAAM;CAG5B;AAED;;;;;;;GAOG;AACH,qBAAa,YAAa,SAAQ,WAAW;gBAChC,OAAO,CAAC,EAAE,MAAM;CAG5B;AAED;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,WAAW;gBAClC,OAAO,CAAC,EAAE,MAAM;CAG5B;AAED;;;;;GAKG;AAC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,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAOzH;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,GAAE,gBAAqB,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAOtG;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,SAAS,GAAE,gBAAqB,GAAG,IAAI,CAqB/J"}
|
package/build/asserts/generic.js
CHANGED
|
@@ -12,6 +12,24 @@ function safeDisplay(value) {
|
|
|
12
12
|
return String(value).slice(0, MAX_VALUE_DISPLAY_LENGTH);
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the display type of a value including null and undefined.
|
|
17
|
+
* Used for error messages in null/undefined assertions and type checking.
|
|
18
|
+
*
|
|
19
|
+
* @param value - The value to get the type of
|
|
20
|
+
* @returns A string representation of the value's type ('null', 'undefined', 'array', 'object', or typeof)
|
|
21
|
+
* @internal Used internally by assertion functions for consistent type messages
|
|
22
|
+
*/
|
|
23
|
+
export function GetValueType(value) {
|
|
24
|
+
if (value === null)
|
|
25
|
+
return 'null';
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
return 'undefined';
|
|
28
|
+
if (typeof value === 'object') {
|
|
29
|
+
return Array.isArray(value) ? 'array' : 'object';
|
|
30
|
+
}
|
|
31
|
+
return typeof value;
|
|
32
|
+
}
|
|
15
33
|
/**
|
|
16
34
|
* Error thrown when a nullish assertion fails — the value is not null or undefined
|
|
17
35
|
* but was expected to be. Used by {@link AssertNull} when the provided value is a
|
|
@@ -270,7 +288,8 @@ export function AssertNotEquals(value, expected, exception = {}) {
|
|
|
270
288
|
export function AssertNull(value, exception = {}) {
|
|
271
289
|
SetExceptionClass(exception, NullError);
|
|
272
290
|
if (value !== null && value !== undefined) {
|
|
273
|
-
|
|
291
|
+
const actualType = GetValueType(value);
|
|
292
|
+
SetExceptionMessage(exception, `Expected null or undefined but received ${actualType}: ${safeDisplay(value)}`);
|
|
274
293
|
ThrowException(exception);
|
|
275
294
|
}
|
|
276
295
|
}
|
|
@@ -309,8 +328,8 @@ export function AssertNull(value, exception = {}) {
|
|
|
309
328
|
export function AssertNotNull(value, exception = {}) {
|
|
310
329
|
SetExceptionClass(exception, NotNullError);
|
|
311
330
|
if (value === null || value === undefined) {
|
|
312
|
-
const
|
|
313
|
-
SetExceptionMessage(exception, `Expected non-null/non-undefined value but received ${
|
|
331
|
+
const actualType = GetValueType(value);
|
|
332
|
+
SetExceptionMessage(exception, `Expected non-null/non-undefined value but received ${actualType}`);
|
|
314
333
|
ThrowException(exception);
|
|
315
334
|
}
|
|
316
335
|
}
|
|
@@ -398,8 +417,8 @@ export function AssertPredicate(value, predicate, exception = {}) {
|
|
|
398
417
|
export function AssertIsType(value, typeGuard, exception = {}) {
|
|
399
418
|
SetExceptionClass(exception, TypeGuardError);
|
|
400
419
|
if (!typeGuard(value)) {
|
|
401
|
-
const actualType = value
|
|
402
|
-
SetExceptionMessage(exception, `Expected value to conform to required type but received ${actualType}: ${
|
|
420
|
+
const actualType = GetValueType(value);
|
|
421
|
+
SetExceptionMessage(exception, `Expected value to conform to required type but received ${actualType}: ${safeDisplay(value)}`);
|
|
403
422
|
ThrowException(exception);
|
|
404
423
|
}
|
|
405
424
|
}
|
|
@@ -440,7 +459,10 @@ export function AssertIsType(value, typeGuard, exception = {}) {
|
|
|
440
459
|
export function AssertInstanceOf(value, constructor, exception = {}) {
|
|
441
460
|
SetExceptionClass(exception, InstanceOfError);
|
|
442
461
|
if (!(value instanceof constructor)) {
|
|
443
|
-
|
|
462
|
+
let actualType = GetValueType(value);
|
|
463
|
+
if (actualType === 'object' && value !== null && typeof value === 'object') {
|
|
464
|
+
actualType = value.constructor?.name ?? 'object';
|
|
465
|
+
}
|
|
444
466
|
SetExceptionMessage(exception, `Expected instance of ${constructor.name} but received ${actualType}`);
|
|
445
467
|
ThrowException(exception);
|
|
446
468
|
}
|
|
@@ -465,7 +487,7 @@ export function AssertInstanceOf(value, constructor, exception = {}) {
|
|
|
465
487
|
export function AssertFunction(value, exception = {}) {
|
|
466
488
|
SetExceptionClass(exception, FunctionError);
|
|
467
489
|
if (typeof value !== 'function') {
|
|
468
|
-
const actualType = value
|
|
490
|
+
const actualType = GetValueType(value);
|
|
469
491
|
SetExceptionMessage(exception, `Expected function but received ${actualType}`);
|
|
470
492
|
ThrowException(exception);
|
|
471
493
|
}
|
|
@@ -490,7 +512,7 @@ export function AssertFunction(value, exception = {}) {
|
|
|
490
512
|
export function AssertSymbol(value, exception = {}) {
|
|
491
513
|
SetExceptionClass(exception, SymbolError);
|
|
492
514
|
if (typeof value !== 'symbol') {
|
|
493
|
-
const actualType = value
|
|
515
|
+
const actualType = GetValueType(value);
|
|
494
516
|
SetExceptionMessage(exception, `Expected symbol but received ${actualType}`);
|
|
495
517
|
ThrowException(exception);
|
|
496
518
|
}
|