ts-data-forge 14.6.2 → 14.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/dist/array/impl/array-utils-creation.mjs +103 -103
  2. package/dist/array/impl/array-utils-element-access.mjs +46 -46
  3. package/dist/array/impl/array-utils-iterators.mjs +54 -54
  4. package/dist/array/impl/array-utils-length-bounded-array-cast.mjs +49 -49
  5. package/dist/array/impl/array-utils-length-bounded-array-guard.mjs +40 -40
  6. package/dist/array/impl/array-utils-length-bounded-tuple-cast.mjs +42 -42
  7. package/dist/array/impl/array-utils-length-bounded-tuple-guard.mjs +46 -46
  8. package/dist/array/impl/array-utils-modification.mjs +5 -5
  9. package/dist/array/impl/array-utils-reducing-value.mjs +11 -11
  10. package/dist/array/impl/array-utils-search.mjs +6 -6
  11. package/dist/array/impl/array-utils-set-op.mjs +116 -116
  12. package/dist/array/impl/array-utils-size.mjs +6 -6
  13. package/dist/array/impl/array-utils-slice-clamped.mjs +1 -1
  14. package/dist/array/impl/array-utils-slicing.mjs +56 -56
  15. package/dist/array/impl/array-utils-transformation.mjs +158 -158
  16. package/dist/array/impl/array-utils-validation.mjs +36 -36
  17. package/dist/collections/imap-mapped.mjs +195 -195
  18. package/dist/collections/imap.mjs +143 -143
  19. package/dist/collections/iset-mapped.mjs +320 -320
  20. package/dist/collections/iset.mjs +207 -207
  21. package/dist/collections/queue.mjs +130 -130
  22. package/dist/collections/stack.mjs +125 -125
  23. package/dist/expect-type.mjs +68 -68
  24. package/dist/functional/async-result/impl/async-result-flat-map.mjs +3 -3
  25. package/dist/functional/async-result/impl/async-result-map-err.mjs +2 -2
  26. package/dist/functional/async-result/impl/async-result-map.mjs +2 -2
  27. package/dist/functional/async-result/impl/async-result-unwrap-or.mjs +31 -31
  28. package/dist/functional/optional/impl/optional-expect-to-be.mjs +1 -1
  29. package/dist/functional/optional/impl/optional-filter.mjs +1 -1
  30. package/dist/functional/optional/impl/optional-flat-map.mjs +1 -1
  31. package/dist/functional/optional/impl/optional-from-nullable.mjs +24 -24
  32. package/dist/functional/optional/impl/optional-is-none.mjs +19 -19
  33. package/dist/functional/optional/impl/optional-is-optional.mjs +18 -18
  34. package/dist/functional/optional/impl/optional-is-some.mjs +20 -20
  35. package/dist/functional/optional/impl/optional-map.mjs +2 -2
  36. package/dist/functional/optional/impl/optional-match.mjs +2 -2
  37. package/dist/functional/optional/impl/optional-none.mjs +16 -16
  38. package/dist/functional/optional/impl/optional-or-else.mjs +1 -1
  39. package/dist/functional/optional/impl/optional-some.mjs +19 -19
  40. package/dist/functional/optional/impl/optional-to-nullable.mjs +26 -26
  41. package/dist/functional/optional/impl/optional-unwrap-or.mjs +1 -1
  42. package/dist/functional/optional/impl/optional-unwrap-throw.mjs +28 -28
  43. package/dist/functional/optional/impl/optional-unwrap.mjs +1 -1
  44. package/dist/functional/optional/impl/optional-zip.mjs +32 -32
  45. package/dist/functional/optional/impl/tag.mjs +1 -1
  46. package/dist/functional/pipe.mjs +19 -19
  47. package/dist/functional/result/impl/result-err.mjs +25 -25
  48. package/dist/functional/result/impl/result-expect-to-be.mjs +2 -2
  49. package/dist/functional/result/impl/result-flat-map.mjs +4 -4
  50. package/dist/functional/result/impl/result-fold.mjs +4 -4
  51. package/dist/functional/result/impl/result-from-optional.mjs +2 -2
  52. package/dist/functional/result/impl/result-from-promise.mjs +34 -34
  53. package/dist/functional/result/impl/result-from-throwable.mjs +29 -29
  54. package/dist/functional/result/impl/result-is-err.mjs +19 -19
  55. package/dist/functional/result/impl/result-is-ok.mjs +19 -19
  56. package/dist/functional/result/impl/result-is-result.mjs +19 -19
  57. package/dist/functional/result/impl/result-map-err.mjs +4 -4
  58. package/dist/functional/result/impl/result-map.mjs +4 -4
  59. package/dist/functional/result/impl/result-match.mjs +3 -3
  60. package/dist/functional/result/impl/result-ok.mjs +25 -25
  61. package/dist/functional/result/impl/result-or-else.mjs +2 -2
  62. package/dist/functional/result/impl/result-safe-try.mjs +15 -15
  63. package/dist/functional/result/impl/result-safe-unwrap.mjs +33 -33
  64. package/dist/functional/result/impl/result-swap.mjs +20 -20
  65. package/dist/functional/result/impl/result-to-optional.mjs +27 -27
  66. package/dist/functional/result/impl/result-unwrap-err-or.mjs +2 -2
  67. package/dist/functional/result/impl/result-unwrap-err-throw.mjs +31 -31
  68. package/dist/functional/result/impl/result-unwrap-err.mjs +30 -30
  69. package/dist/functional/result/impl/result-unwrap-ok-or.mjs +2 -2
  70. package/dist/functional/result/impl/result-unwrap-ok.mjs +1 -1
  71. package/dist/functional/result/impl/result-unwrap-throw.mjs +31 -31
  72. package/dist/functional/result/impl/result-zip.mjs +29 -29
  73. package/dist/functional/result/impl/tag.mjs +1 -1
  74. package/dist/functional/ternary-result/impl/tag.mjs +2 -2
  75. package/dist/functional/ternary-result/impl/ternary-result-err.mjs +13 -13
  76. package/dist/functional/ternary-result/impl/ternary-result-flat-map.mjs +4 -4
  77. package/dist/functional/ternary-result/impl/ternary-result-fold.mjs +4 -4
  78. package/dist/functional/ternary-result/impl/ternary-result-from-promise.mjs +18 -18
  79. package/dist/functional/ternary-result/impl/ternary-result-from-throwable.mjs +17 -17
  80. package/dist/functional/ternary-result/impl/ternary-result-is-err.mjs +17 -17
  81. package/dist/functional/ternary-result/impl/ternary-result-is-ok.mjs +19 -19
  82. package/dist/functional/ternary-result/impl/ternary-result-is-ternary-result.mjs +19 -19
  83. package/dist/functional/ternary-result/impl/ternary-result-is-warn.mjs +18 -18
  84. package/dist/functional/ternary-result/impl/ternary-result-map-err.mjs +2 -2
  85. package/dist/functional/ternary-result/impl/ternary-result-map-warn.mjs +3 -3
  86. package/dist/functional/ternary-result/impl/ternary-result-map.mjs +4 -4
  87. package/dist/functional/ternary-result/impl/ternary-result-ok.mjs +14 -14
  88. package/dist/functional/ternary-result/impl/ternary-result-to-optional.mjs +19 -19
  89. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err-throw.mjs +19 -19
  90. package/dist/functional/ternary-result/impl/ternary-result-unwrap-err.mjs +17 -17
  91. package/dist/functional/ternary-result/impl/ternary-result-unwrap-ok.mjs +1 -1
  92. package/dist/functional/ternary-result/impl/ternary-result-unwrap-throw.mjs +20 -20
  93. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn-throw.mjs +18 -18
  94. package/dist/functional/ternary-result/impl/ternary-result-unwrap-warn.mjs +17 -17
  95. package/dist/functional/ternary-result/impl/ternary-result-warn.mjs +16 -16
  96. package/dist/functional/ternary-result/impl/ternary-result-zip.mjs +31 -31
  97. package/dist/functional/ternary-result/impl/variant-name.mjs +1 -1
  98. package/dist/guard/has-key.mjs +41 -41
  99. package/dist/guard/is-non-empty-string.mjs +37 -37
  100. package/dist/guard/is-non-null-object.mjs +34 -34
  101. package/dist/guard/is-primitive.mjs +31 -31
  102. package/dist/guard/is-record.mjs +86 -86
  103. package/dist/guard/is-type.mjs +387 -387
  104. package/dist/guard/key-is-in.mjs +40 -40
  105. package/dist/iterator/range.mjs +1 -1
  106. package/dist/json/json.mjs +289 -289
  107. package/dist/number/branded-types/finite-number.mjs +116 -116
  108. package/dist/number/branded-types/int.mjs +223 -223
  109. package/dist/number/branded-types/int16.mjs +116 -116
  110. package/dist/number/branded-types/int32.mjs +116 -116
  111. package/dist/number/branded-types/negative-finite-number.mjs +126 -126
  112. package/dist/number/branded-types/negative-int.mjs +104 -104
  113. package/dist/number/branded-types/negative-safe-int.mjs +104 -104
  114. package/dist/number/branded-types/non-negative-finite-number.mjs +132 -132
  115. package/dist/number/branded-types/non-negative-int16.mjs +113 -113
  116. package/dist/number/branded-types/non-negative-int32.mjs +113 -113
  117. package/dist/number/branded-types/non-positive-finite-number.mjs +116 -116
  118. package/dist/number/branded-types/non-positive-int.mjs +97 -97
  119. package/dist/number/branded-types/non-positive-safe-int.mjs +98 -98
  120. package/dist/number/branded-types/non-zero-finite-number.mjs +112 -112
  121. package/dist/number/branded-types/non-zero-int.mjs +82 -82
  122. package/dist/number/branded-types/non-zero-int16.mjs +95 -95
  123. package/dist/number/branded-types/non-zero-int32.mjs +95 -95
  124. package/dist/number/branded-types/non-zero-safe-int.mjs +99 -99
  125. package/dist/number/branded-types/non-zero-uint16.mjs +95 -95
  126. package/dist/number/branded-types/non-zero-uint32.mjs +95 -95
  127. package/dist/number/branded-types/positive-finite-number.mjs +134 -134
  128. package/dist/number/branded-types/positive-int.mjs +237 -237
  129. package/dist/number/branded-types/positive-int16.mjs +110 -110
  130. package/dist/number/branded-types/positive-int32.mjs +110 -110
  131. package/dist/number/branded-types/positive-safe-int.mjs +268 -268
  132. package/dist/number/branded-types/positive-uint16.mjs +110 -110
  133. package/dist/number/branded-types/positive-uint32.mjs +110 -110
  134. package/dist/number/branded-types/safe-int.mjs +259 -259
  135. package/dist/number/branded-types/safe-uint.mjs +111 -111
  136. package/dist/number/branded-types/uint.mjs +225 -225
  137. package/dist/number/branded-types/uint16.mjs +108 -108
  138. package/dist/number/branded-types/uint32.mjs +108 -108
  139. package/dist/number/enum/int8.mjs +118 -118
  140. package/dist/number/enum/uint8.mjs +109 -109
  141. package/dist/number/num-arithmetic-types.mjs +1 -1
  142. package/dist/number/num.mjs +478 -478
  143. package/dist/number/refined-number-utils.mjs +170 -170
  144. package/dist/object/object.mjs +234 -234
  145. package/dist/others/cast-mutable.mjs +33 -33
  146. package/dist/others/cast-readonly.mjs +32 -32
  147. package/dist/others/debounce-function.mjs +13 -13
  148. package/dist/others/fast-deep-equal.mjs +14 -14
  149. package/dist/others/if-then.mjs +29 -29
  150. package/dist/others/tuple.mjs +50 -50
  151. package/dist/others/unknown-to-string.mjs +38 -38
  152. package/dist/promise/promise.mjs +47 -47
  153. package/dist/string/str.mjs +177 -177
  154. package/dist/types.mjs +1 -1
  155. package/package.json +6 -6
  156. package/src/guard/is-type.test.mts +2 -2
  157. package/src/number/branded-types/finite-number.test.mts +1 -1
  158. package/src/number/branded-types/int.test.mts +1 -1
  159. package/src/number/branded-types/int16.test.mts +1 -1
  160. package/src/number/branded-types/int32.test.mts +1 -1
  161. package/src/number/branded-types/non-negative-finite-number.test.mts +1 -1
  162. package/src/number/branded-types/non-negative-int16.test.mts +1 -1
  163. package/src/number/branded-types/non-negative-int32.test.mts +1 -1
  164. package/src/number/branded-types/non-zero-finite-number.test.mts +1 -1
  165. package/src/number/branded-types/non-zero-int.test.mts +1 -1
  166. package/src/number/branded-types/non-zero-int16.test.mts +1 -1
  167. package/src/number/branded-types/non-zero-int32.test.mts +1 -1
  168. package/src/number/branded-types/non-zero-safe-int.test.mts +1 -1
  169. package/src/number/branded-types/non-zero-uint16.test.mts +1 -1
  170. package/src/number/branded-types/non-zero-uint32.test.mts +1 -1
  171. package/src/number/branded-types/positive-finite-number.test.mts +1 -1
  172. package/src/number/branded-types/positive-int.test.mts +1 -1
  173. package/src/number/branded-types/positive-int16.test.mts +1 -1
  174. package/src/number/branded-types/positive-int32.test.mts +1 -1
  175. package/src/number/branded-types/positive-safe-int.test.mts +1 -1
  176. package/src/number/branded-types/positive-uint16.test.mts +1 -1
  177. package/src/number/branded-types/positive-uint32.test.mts +1 -1
  178. package/src/number/branded-types/safe-int.test.mts +1 -1
  179. package/src/number/branded-types/safe-uint.test.mts +1 -1
  180. package/src/number/branded-types/uint.test.mts +1 -1
  181. package/src/number/branded-types/uint16.test.mts +1 -1
  182. package/src/number/branded-types/uint32.test.mts +1 -1
@@ -59,54 +59,54 @@ const asBoundedLengthTupleImpl = (min, max, xs) => {
59
59
  }
60
60
  return xs;
61
61
  };
62
- /**
63
- * Casts an array to the structural empty tuple after checking that it is
64
- * empty.
65
- *
66
- * This is the structural counterpart of `asEmptyArray`, and the length-0
67
- * specialization of {@link asFixedLengthTuple}.
68
- *
69
- * @example
70
- *
71
- * ```ts
72
- * const nothing = Arr.asEmptyTuple([]);
73
- *
74
- * // Arr.asEmptyTuple([1]); // throws TypeError
75
- * ```
76
- *
77
- * @template Xs - The input array type (tuple types are preserved).
78
- * @param xs - The array to cast.
79
- * @returns `xs` typed as `readonly [] & Xs`.
80
- * @throws {TypeError} If `xs` is not empty.
81
- */
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
82
  export const asEmptyTuple = (xs) => {
83
83
  if (!isEmptyTuple(xs)) {
84
84
  throw new TypeError(`Expected an empty array, got an array of length ${xs.length}`);
85
85
  }
86
86
  return xs;
87
87
  };
88
- /**
89
- * Casts an array to `MinLengthTuple<1, E>` after checking that it has at least
90
- * one element.
91
- *
92
- * This is the structural counterpart of `asNonEmptyArray`, and the length-1
93
- * specialization of {@link asMinLengthTuple}.
94
- *
95
- * @example
96
- *
97
- * ```ts
98
- * const values = Arr.asNonEmptyTuple([1, 2, 3]);
99
- *
100
- * const first: number = values[0]; // OK — no `undefined`
101
- *
102
- * // Arr.asNonEmptyTuple([]); // throws TypeError
103
- * ```
104
- *
105
- * @template Xs - The input array type (tuple types are preserved).
106
- * @param xs - The array to cast.
107
- * @returns `xs` typed as `MinLengthTuple<1, Xs[number]> & Xs`.
108
- * @throws {TypeError} If `xs` is empty.
109
- */
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
110
  export const asNonEmptyTuple = (xs) => {
111
111
  if (!isMinLengthTuple(1, xs)) {
112
112
  throw new TypeError('Expected a non-empty array, got an empty array');
@@ -1,50 +1,50 @@
1
- /**
2
- * Type guard that checks if an array is empty, narrowing it to the structural
3
- * empty tuple.
4
- *
5
- * This is the structural counterpart of `isEmpty`: it narrows to `readonly []`
6
- * rather than to the branded `FixedLengthArray<0, E>`. Prefer `isEmpty` unless
7
- * you specifically need the structural type.
8
- *
9
- * @example
10
- *
11
- * ```ts
12
- * const values: readonly number[] = [] as const;
13
- *
14
- * assert.isTrue(Arr.isEmptyTuple(values));
15
- *
16
- * assert.isFalse(Arr.isEmptyTuple([1] as const));
17
- * ```
18
- *
19
- * @template E - The element type.
20
- * @param array - The array to check.
21
- * @returns `true` if `array.length === 0`. When `true`, TypeScript narrows
22
- * `array` to `readonly []`.
23
- */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
24
  export const isEmptyTuple = (array) => array.length === 0;
25
- /**
26
- * Type guard that checks if an array is non-empty, narrowing it to the
27
- * structural non-empty tuple.
28
- *
29
- * This is the structural counterpart of `isNonEmpty`: it narrows to
30
- * `MinLengthTuple<1, E>` rather than to the branded `MinLengthArray<1, E>`.
31
- * Prefer `isNonEmpty` unless you specifically need the structural type.
32
- *
33
- * @example
34
- *
35
- * ```ts
36
- * const values: readonly number[] = [1, 2] as const;
37
- *
38
- * assert.isTrue(Arr.isNonEmptyTuple(values));
39
- *
40
- * assert.isFalse(Arr.isNonEmptyTuple([] as const));
41
- * ```
42
- *
43
- * @template E - The element type.
44
- * @param array - The array to check.
45
- * @returns `true` if `array.length >= 1`. When `true`, TypeScript narrows
46
- * `array` to `MinLengthTuple<1, E>`.
47
- */
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
48
  export const isNonEmptyTuple = (array) => array.length >= 1;
49
49
  export function isFixedLengthTuple(...args) {
50
50
  switch (args.length) {
@@ -1,6 +1,6 @@
1
1
  import { asPositiveUint32 } from '../../number/index.mjs';
2
2
 
3
- import { create } from './array-utils-creation.mjs';
3
+ import { copy, create } from './array-utils-creation.mjs';
4
4
  export function set(...args) {
5
5
  switch (args.length) {
6
6
  case 3:
@@ -19,7 +19,7 @@ export function toUpdated(...args) {
19
19
  }
20
20
  }
21
21
  const toUpdatedImpl = (array, index, updater) =>
22
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
+
23
23
  array.with(index, updater(array[index]));
24
24
  export function toInserted(...args) {
25
25
  switch (args.length) {
@@ -30,7 +30,7 @@ export function toInserted(...args) {
30
30
  }
31
31
  }
32
32
  const toInsertedImpl = (array, index, newValue) =>
33
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
33
+
34
34
  array.toSpliced(index, 0, newValue);
35
35
  export function toRemoved(...args) {
36
36
  switch (args.length) {
@@ -50,7 +50,7 @@ export function toPushed(...args) {
50
50
  }
51
51
  }
52
52
  const toPushedImpl = (array, newValue) =>
53
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
53
+
54
54
  array.toSpliced(array.length, 0, newValue);
55
55
  export function toUnshifted(...args) {
56
56
  switch (args.length) {
@@ -61,7 +61,7 @@ export function toUnshifted(...args) {
61
61
  }
62
62
  }
63
63
  const toUnshiftedImpl = (array, newValue) =>
64
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
64
+
65
65
  array.toSpliced(0, 0, newValue);
66
66
  export function toFilled(...args) {
67
67
  switch (args.length) {
@@ -14,7 +14,7 @@ export function min(array, comparator) {
14
14
  }
15
15
  export function max(array, comparator) {
16
16
  const cmp = comparator ?? ((x, y) => Num.from(x) - Num.from(y));
17
- // Find max by finding min with an inverted comparator
17
+
18
18
  return min(array, (x, y) => -cmp(x, y));
19
19
  }
20
20
  export function minBy(array, comparatorValueMapper, comparator) {
@@ -103,16 +103,16 @@ const joinImpl = (array, separator) => {
103
103
  return Result.err(isError(error) ? error : new Error(unknownToString(error)));
104
104
  }
105
105
  };
106
- /**
107
- * Alias for `foldl`.
108
- *
109
- * @see {@link foldl}
110
- */
106
+
107
+
108
+
109
+
110
+
111
111
  export const reduce = foldl;
112
- /**
113
- * Alias for `foldr`.
114
- *
115
- * @see {@link foldr}
116
- */
112
+
113
+
114
+
115
+
116
+
117
117
  export const reduceRight = foldr;
118
118
  //# sourceMappingURL=array-utils-reducing-value.mjs.map
@@ -11,7 +11,7 @@ export function find(...args) {
11
11
  }
12
12
  const findImpl = (array, predicate) => {
13
13
  const foundIndex = array.findIndex(
14
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
14
+
15
15
  predicate);
16
16
 
17
17
 
@@ -27,7 +27,7 @@ const findImpl = (array, predicate) => {
27
27
 
28
28
  return foundIndex === -1
29
29
  ? Optional.none
30
- : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
30
+ :
31
31
  Optional.some(array[foundIndex]);
32
32
  };
33
33
  export function findLast(...args) {
@@ -40,7 +40,7 @@ export function findLast(...args) {
40
40
  }
41
41
  const findLastImpl = (array, predicate) => {
42
42
  const foundIndex = array.findLastIndex(
43
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
43
+
44
44
  predicate);
45
45
 
46
46
 
@@ -56,7 +56,7 @@ const findLastImpl = (array, predicate) => {
56
56
 
57
57
  return foundIndex === -1
58
58
  ? Optional.none
59
- : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
59
+ :
60
60
  Optional.some(array[foundIndex]);
61
61
  };
62
62
  export function findIndex(...args) {
@@ -68,7 +68,7 @@ export function findIndex(...args) {
68
68
  }
69
69
  }
70
70
  const findIndexImpl = (array, predicate) => pipe(array.findIndex(
71
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
71
+
72
72
  predicate)).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
73
73
  export function findLastIndex(...args) {
74
74
  switch (args.length) {
@@ -79,7 +79,7 @@ export function findLastIndex(...args) {
79
79
  }
80
80
  }
81
81
  const findLastIndexImpl = (array, predicate) => pipe(array.findLastIndex(
82
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
82
+
83
83
  predicate)).map((idx) => (idx >= 0 ? asUint32(idx) : -1)).value;
84
84
  export function indexOf(...args) {
85
85
  switch (args.length) {
@@ -1,129 +1,129 @@
1
- /**
2
- * Checks if two arrays are equal by comparing their elements.
3
- *
4
- * @example
5
- *
6
- * ```ts
7
- * const numbers = [1, 2, 3] as const;
8
- *
9
- * const sameNumbers = [1, 2, 3] as const;
10
- *
11
- * const differentNumbers = [1, 2, 4] as const;
12
- *
13
- * assert.isTrue(Arr.eq(numbers, sameNumbers));
14
- *
15
- * assert.isFalse(Arr.eq(numbers, differentNumbers));
16
- * ```
17
- */
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
18
  export const eq = (array1, array2, equality = Object.is) => array1.length === array2.length &&
19
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
19
+
20
20
  array1.every((v, i) => equality(v, array2[i]));
21
- /**
22
- * Alias for `eq`.
23
- *
24
- * @see {@link eq}
25
- */
21
+
22
+
23
+
24
+
25
+
26
26
  export const equal = eq;
27
- /**
28
- * Checks if the first array is a subset of the second array.
29
- *
30
- * @example
31
- *
32
- * ```ts
33
- * const subset = [1, 2] as const;
34
- *
35
- * const superset = [1, 2, 3] as const;
36
- *
37
- * const notSubset = [2, 4] as const;
38
- *
39
- * assert.isTrue(Arr.isSubset(subset, superset));
40
- *
41
- * assert.isFalse(Arr.isSubset(notSubset, superset));
42
- * ```
43
- */
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
44
  export const isSubset = (array1, array2) => array1.every((a) =>
45
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
45
+
46
46
  array2.includes(a));
47
- /**
48
- * Checks if the first array is a superset of the second array.
49
- *
50
- * @example
51
- *
52
- * ```ts
53
- * const potentialSuperset = ['a', 'b', 'c'] as const;
54
- *
55
- * const subset = ['a', 'c'] as const;
56
- *
57
- * const notSuperset = ['a', 'd'] as const;
58
- *
59
- * assert.isTrue(Arr.isSuperset(potentialSuperset, subset));
60
- *
61
- * assert.isFalse(Arr.isSuperset(subset, potentialSuperset));
62
- *
63
- * assert.isFalse(Arr.isSuperset(potentialSuperset, notSuperset));
64
- * ```
65
- */
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
66
  export const isSuperset = (array1, array2) => isSubset(array2, array1);
67
- /**
68
- * Returns the intersection of two arrays.
69
- *
70
- * @example
71
- *
72
- * ```ts
73
- * const refs = ['Ada', 'Alan', 'Grace'] as const;
74
- *
75
- * const attendees = ['Grace', 'Alan', 'Barbara'] as const;
76
- *
77
- * const both = Arr.setIntersection(refs, attendees);
78
- *
79
- * assert.deepStrictEqual(both, ['Alan', 'Grace']);
80
- * ```
81
- */
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
82
  export const setIntersection = (array1, array2) =>
83
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
83
+
84
84
  array1.filter((e) => array2.includes(e));
85
- /**
86
- * Returns the set difference of two arrays (elements in first but not in second).
87
- *
88
- * @example
89
- *
90
- * ```ts
91
- * const baseline = [1, 2, 3, 4] as const;
92
- *
93
- * const removed = [2, 4] as const;
94
- *
95
- * const remaining = Arr.setDifference(baseline, removed);
96
- *
97
- * assert.deepStrictEqual(remaining, [1, 3]);
98
- * ```
99
- */
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
100
  export const setDifference = (array1, array2) => array1.filter((e) => !array2.includes(e));
101
- /**
102
- * Returns the set difference of two sorted numeric arrays (optimized for sorted arrays).
103
- *
104
- * @example
105
- *
106
- * ```ts
107
- * const upcoming = [1, 3, 5, 7, 9] as const;
108
- *
109
- * const completed = [3, 4, 7] as const;
110
- *
111
- * const remaining = Arr.sortedNumSetDifference(upcoming, completed);
112
- *
113
- * const expected = [1, 5, 9] as const;
114
- *
115
- * assert.deepStrictEqual(remaining, expected);
116
- * ```
117
- */
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+
118
118
  export const sortedNumSetDifference = (sortedList1, sortedList2) => {
119
119
  const mut_result = [];
120
- let mut_it1 = 0; // iterator for sortedList1
121
- let mut_it2 = 0; // iterator for sortedList2
120
+ let mut_it1 = 0;
121
+ let mut_it2 = 0;
122
122
  while (mut_it1 < sortedList1.length && mut_it2 < sortedList2.length) {
123
- // Non-null assertions are safe due to loop condition
124
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
123
+
124
+
125
125
  const val1 = sortedList1[mut_it1];
126
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
+
127
127
  const val2 = sortedList2[mut_it2];
128
128
  if (val1 === val2) {
129
129
  mut_it1 += 1;
@@ -134,13 +134,13 @@ export const sortedNumSetDifference = (sortedList1, sortedList2) => {
134
134
  mut_it1 += 1;
135
135
  }
136
136
  else {
137
- // val1 > val2
137
+
138
138
  mut_it2 += 1;
139
139
  }
140
140
  }
141
- // Add remaining elements from sortedList1
141
+
142
142
  for (; mut_it1 < sortedList1.length; mut_it1 += 1) {
143
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
143
+
144
144
  mut_result.push(sortedList1[mut_it1]);
145
145
  }
146
146
  return mut_result;
@@ -1,10 +1,10 @@
1
1
  export const size = (array) =>
2
- // eslint-disable-next-line total-functions/no-unsafe-type-assertion
2
+
3
3
  array.length;
4
- /**
5
- * Alias for `size`.
6
- *
7
- * @see {@link size}
8
- */
4
+
5
+
6
+
7
+
8
+
9
9
  export const length = size;
10
10
  //# sourceMappingURL=array-utils-size.mjs.map
@@ -9,7 +9,7 @@ export function sliceClamped(...args) {
9
9
  }
10
10
  const sliceClampedImpl = (array, start, end) => {
11
11
  const startClamped = Num.clamp(0, array.length)(start);
12
- // Ensure endClamped is not less than startClamped.
12
+
13
13
  const endClamped = Num.clamp(startClamped, array.length)(end);
14
14
  return array.slice(startClamped, endClamped);
15
15
  };