@ts-fns/stdlib 0.1.0 → 0.2.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/dist/array/index.cjs +230 -33
- package/dist/array/index.cjs.map +1 -1
- package/dist/array/index.d.cts +434 -32
- package/dist/array/index.d.cts.map +1 -1
- package/dist/array/index.d.mts +434 -32
- package/dist/array/index.d.mts.map +1 -1
- package/dist/array/index.mjs +216 -18
- package/dist/array/index.mjs.map +1 -1
- package/dist/function/index.cjs +4 -2
- package/dist/function/index.d.cts +128 -13
- package/dist/function/index.d.cts.map +1 -1
- package/dist/function/index.d.mts +128 -13
- package/dist/function/index.d.mts.map +1 -1
- package/dist/function/index.mjs +3 -3
- package/dist/{function-DnI2v0p3.mjs → function-CYHPhQCQ.mjs} +84 -6
- package/dist/function-CYHPhQCQ.mjs.map +1 -0
- package/dist/{function-CB82a2GS.cjs → function-DYPifnmg.cjs} +95 -5
- package/dist/function-DYPifnmg.cjs.map +1 -0
- package/dist/{get-yrs1Kqho.cjs → get-1kqkxPFX.cjs} +20 -8
- package/dist/get-1kqkxPFX.cjs.map +1 -0
- package/dist/{get-CWL_cu6G.mjs → get-Dv6ejLZg.mjs} +21 -3
- package/dist/get-Dv6ejLZg.mjs.map +1 -0
- package/dist/guard/index.cjs +5 -12
- package/dist/guard/index.cjs.map +1 -1
- package/dist/guard/index.d.cts +18 -17
- package/dist/guard/index.d.cts.map +1 -1
- package/dist/guard/index.d.mts +18 -17
- package/dist/guard/index.d.mts.map +1 -1
- package/dist/guard/index.mjs +4 -12
- package/dist/guard/index.mjs.map +1 -1
- package/dist/index-MbdqaUt1.d.cts +54 -0
- package/dist/index-MbdqaUt1.d.cts.map +1 -0
- package/dist/index-k-paNOu4.d.mts +54 -0
- package/dist/index-k-paNOu4.d.mts.map +1 -0
- package/dist/iterator/index.cjs +72 -26
- package/dist/iterator/index.cjs.map +1 -1
- package/dist/iterator/index.d.cts +157 -5
- package/dist/iterator/index.d.cts.map +1 -1
- package/dist/iterator/index.d.mts +157 -5
- package/dist/iterator/index.d.mts.map +1 -1
- package/dist/iterator/index.mjs +66 -24
- package/dist/iterator/index.mjs.map +1 -1
- package/dist/lens/index.cjs +3 -3
- package/dist/lens/index.cjs.map +1 -1
- package/dist/lens/index.mjs +3 -3
- package/dist/lens/index.mjs.map +1 -1
- package/dist/map/index.cjs +88 -1
- package/dist/map/index.cjs.map +1 -1
- package/dist/map/index.d.cts +130 -2
- package/dist/map/index.d.cts.map +1 -1
- package/dist/map/index.d.mts +130 -2
- package/dist/map/index.d.mts.map +1 -1
- package/dist/map/index.mjs +86 -2
- package/dist/map/index.mjs.map +1 -1
- package/dist/number/index.cjs +91 -18
- package/dist/number/index.cjs.map +1 -1
- package/dist/number/index.d.cts +134 -19
- package/dist/number/index.d.cts.map +1 -1
- package/dist/number/index.d.mts +134 -19
- package/dist/number/index.d.mts.map +1 -1
- package/dist/number/index.mjs +91 -18
- package/dist/number/index.mjs.map +1 -1
- package/dist/object/index.cjs +111 -7
- package/dist/object/index.cjs.map +1 -1
- package/dist/object/index.d.cts +186 -26
- package/dist/object/index.d.cts.map +1 -1
- package/dist/object/index.d.mts +186 -26
- package/dist/object/index.d.mts.map +1 -1
- package/dist/object/index.mjs +111 -7
- package/dist/object/index.mjs.map +1 -1
- package/dist/orNull-CJNrTjhQ.cjs +45 -0
- package/dist/orNull-CJNrTjhQ.cjs.map +1 -0
- package/dist/orNull-EeXiCxD4.mjs +34 -0
- package/dist/orNull-EeXiCxD4.mjs.map +1 -0
- package/dist/order/index.cjs +22 -1
- package/dist/order/index.cjs.map +1 -1
- package/dist/order/index.d.cts +2 -2
- package/dist/order/index.d.mts +2 -2
- package/dist/order/index.mjs +22 -1
- package/dist/order/index.mjs.map +1 -1
- package/dist/{order.constants-BWSCg3C7.d.cts → order.constants-DpGY-EDp.d.cts} +4 -1
- package/dist/order.constants-DpGY-EDp.d.cts.map +1 -0
- package/dist/{order.constants-BWSCg3C7.d.mts → order.constants-DpGY-EDp.d.mts} +4 -1
- package/dist/order.constants-DpGY-EDp.d.mts.map +1 -0
- package/dist/purry-DXnhXie9.mjs +22 -0
- package/dist/purry-DXnhXie9.mjs.map +1 -0
- package/dist/purry-Dqp_F64t.cjs +27 -0
- package/dist/purry-Dqp_F64t.cjs.map +1 -0
- package/dist/set/index.cjs +59 -1
- package/dist/set/index.cjs.map +1 -1
- package/dist/set/index.d.cts +151 -2
- package/dist/set/index.d.cts.map +1 -1
- package/dist/set/index.d.mts +151 -2
- package/dist/set/index.d.mts.map +1 -1
- package/dist/set/index.mjs +59 -2
- package/dist/set/index.mjs.map +1 -1
- package/dist/string/index.cjs +289 -15
- package/dist/string/index.cjs.map +1 -1
- package/dist/string/index.d.cts +406 -1
- package/dist/string/index.d.cts.map +1 -1
- package/dist/string/index.d.mts +406 -1
- package/dist/string/index.d.mts.map +1 -1
- package/dist/string/index.mjs +271 -4
- package/dist/string/index.mjs.map +1 -1
- package/dist/tuple/index.cjs +20 -21
- package/dist/tuple/index.cjs.map +1 -1
- package/dist/tuple/index.d.cts +27 -58
- package/dist/tuple/index.d.cts.map +1 -1
- package/dist/tuple/index.d.mts +27 -58
- package/dist/tuple/index.d.mts.map +1 -1
- package/dist/tuple/index.mjs +20 -22
- package/dist/tuple/index.mjs.map +1 -1
- package/package.json +5 -6
- package/dist/function-CB82a2GS.cjs.map +0 -1
- package/dist/function-DnI2v0p3.mjs.map +0 -1
- package/dist/get-CWL_cu6G.mjs.map +0 -1
- package/dist/get-yrs1Kqho.cjs.map +0 -1
- package/dist/index-BJlKyBJH.d.cts +0 -18
- package/dist/index-BJlKyBJH.d.cts.map +0 -1
- package/dist/index-DGrnGMDt.d.mts +0 -18
- package/dist/index-DGrnGMDt.d.mts.map +0 -1
- package/dist/isNotNil-DrF-ohem.cjs +0 -28
- package/dist/isNotNil-DrF-ohem.cjs.map +0 -1
- package/dist/isNotNil-R5f1hC53.mjs +0 -23
- package/dist/isNotNil-R5f1hC53.mjs.map +0 -1
- package/dist/orThrow-V91Jw2lF.mjs +0 -15
- package/dist/orThrow-V91Jw2lF.mjs.map +0 -1
- package/dist/orThrow-ejzcQYAI.cjs +0 -20
- package/dist/orThrow-ejzcQYAI.cjs.map +0 -1
- package/dist/order.constants-BWSCg3C7.d.cts.map +0 -1
- package/dist/order.constants-BWSCg3C7.d.mts.map +0 -1
- package/dist/purry-B2_0DGLV.cjs +0 -28
- package/dist/purry-B2_0DGLV.cjs.map +0 -1
- package/dist/purry-BOWmqwDB.mjs +0 -23
- package/dist/purry-BOWmqwDB.mjs.map +0 -1
package/dist/array/index.cjs
CHANGED
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
3
|
-
const require_purry = require("../purry-
|
|
2
|
+
const require_function = require("../function-DYPifnmg.cjs");
|
|
3
|
+
const require_purry = require("../purry-Dqp_F64t.cjs");
|
|
4
4
|
const require_errors = require("../errors-O-d_Vemi.cjs");
|
|
5
|
-
require("../function-CB82a2GS.cjs");
|
|
6
5
|
//#region src/array/_globalAliases.ts
|
|
7
|
-
const { from, fromAsync, isArray, of } = Array;
|
|
8
|
-
const arrayConstructor = Array;
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/array/at.ts
|
|
11
6
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @
|
|
7
|
+
* Creates an array from an iterable or array-like object.
|
|
8
|
+
* @function
|
|
14
9
|
*/
|
|
10
|
+
const from = Array.from;
|
|
11
|
+
/**
|
|
12
|
+
* Creates an array from an async iterable.
|
|
13
|
+
* @function
|
|
14
|
+
*/
|
|
15
|
+
const fromAsync = Array.fromAsync;
|
|
16
|
+
/**
|
|
17
|
+
* Checks whether a value is an array.
|
|
18
|
+
* @function
|
|
19
|
+
*/
|
|
20
|
+
const isArray = Array.isArray;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an array containing the given values.
|
|
23
|
+
* @function
|
|
24
|
+
*/
|
|
25
|
+
const of = Array.of;
|
|
26
|
+
/**
|
|
27
|
+
* Alias of the built-in array constructor. `new Array() === new Arr.Ctor()
|
|
28
|
+
* @function
|
|
29
|
+
*/
|
|
30
|
+
const Ctor = Array;
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/array/at.ts
|
|
15
33
|
function atImplementation(arr, index) {
|
|
16
34
|
if (arr.length === 0 || index >= arr.length || index < -arr.length) return /* @__PURE__ */ new RangeError(`Arr.at() :: Invalid index : ${index}`);
|
|
17
35
|
return arr.at(index);
|
|
@@ -20,8 +38,18 @@ function at(...args) {
|
|
|
20
38
|
return require_purry.purry(atImplementation, args);
|
|
21
39
|
}
|
|
22
40
|
function atAssert(...args) {
|
|
23
|
-
return require_purry.purry(
|
|
41
|
+
return require_purry.purry(require_function.orThrow(atImplementation), args);
|
|
24
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Like `at`, but throws when the index is out of bounds.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* at.assert([1, 2, 3], 1); // 2
|
|
49
|
+
* at.assert(-1)([1, 2, 3]); // 3
|
|
50
|
+
* at.assert([1, 2, 3], 3); // throws RangeError
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
25
53
|
at.assert = atAssert;
|
|
26
54
|
//#endregion
|
|
27
55
|
//#region src/array/chunk.ts
|
|
@@ -40,8 +68,17 @@ function chunk(...args) {
|
|
|
40
68
|
return require_purry.purry(chunkImplementation, args);
|
|
41
69
|
}
|
|
42
70
|
function chunkAssert(...args) {
|
|
43
|
-
return require_purry.purry(
|
|
71
|
+
return require_purry.purry(require_function.orThrow(chunkImplementation), args);
|
|
44
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Like `chunk`, but throws when the size is not a positive integer.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* chunk.assert([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]
|
|
79
|
+
* chunk.assert(0)([1, 2, 3]); // throws RangeError
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
45
82
|
chunk.assert = chunkAssert;
|
|
46
83
|
//#endregion
|
|
47
84
|
//#region src/array/concat.ts
|
|
@@ -78,8 +115,17 @@ function find(...args) {
|
|
|
78
115
|
return require_purry.purry(findImplementation, args);
|
|
79
116
|
}
|
|
80
117
|
function findAssert(...args) {
|
|
81
|
-
return require_purry.purry(
|
|
118
|
+
return require_purry.purry(require_function.orThrow(findImplementation), args);
|
|
82
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Like `find`, but throws when no element matches the predicate.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* find.assert([1, 2, 3], n => n > 1); // 2
|
|
126
|
+
* find.assert(n => n > 10)([1, 2, 3]); // throws NotFoundError
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
83
129
|
find.assert = findAssert;
|
|
84
130
|
//#endregion
|
|
85
131
|
//#region src/array/findIndex.ts
|
|
@@ -92,8 +138,17 @@ function findIndex(...args) {
|
|
|
92
138
|
return require_purry.purry(findIndexImplementation, args);
|
|
93
139
|
}
|
|
94
140
|
function findIndexAssert(...args) {
|
|
95
|
-
return require_purry.purry(
|
|
141
|
+
return require_purry.purry(require_function.orThrow(findIndexImplementation), args);
|
|
96
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Like `findIndex`, but throws when no element matches the predicate.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* findIndex.assert([1, 2, 3], n => n > 1); // 1
|
|
149
|
+
* findIndex.assert(n => n > 10)([1, 2, 3]); // throws NotFoundError
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
97
152
|
findIndex.assert = findIndexAssert;
|
|
98
153
|
//#endregion
|
|
99
154
|
//#region src/array/findLast.ts
|
|
@@ -106,8 +161,17 @@ function findLast(...args) {
|
|
|
106
161
|
return require_purry.purry(findLastImplementation, args);
|
|
107
162
|
}
|
|
108
163
|
function findLastAssert(...args) {
|
|
109
|
-
return require_purry.purry(
|
|
164
|
+
return require_purry.purry(require_function.orThrow(findLastImplementation), args);
|
|
110
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Like `findLast`, but throws when no element matches the predicate.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* findLast.assert([1, 2, 3, 2], n => n === 2); // 2
|
|
172
|
+
* findLast.assert(n => n > 10)([1, 2, 3]); // throws NotFoundError
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
111
175
|
findLast.assert = findLastAssert;
|
|
112
176
|
//#endregion
|
|
113
177
|
//#region src/array/findLastIndex.ts
|
|
@@ -120,8 +184,17 @@ function findLastIndex(...args) {
|
|
|
120
184
|
return require_purry.purry(findLastIndexImplementation, args);
|
|
121
185
|
}
|
|
122
186
|
function findLastIndexAssert(...args) {
|
|
123
|
-
return require_purry.purry(
|
|
187
|
+
return require_purry.purry(require_function.orThrow(findLastIndexImplementation), args);
|
|
124
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Like `findLastIndex`, but throws when no element matches the predicate.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* findLastIndex.assert([1, 2, 3, 2], n => n === 2); // 3
|
|
195
|
+
* findLastIndex.assert(n => n > 10)([1, 2, 3]); // throws NotFoundError
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
125
198
|
findLastIndex.assert = findLastIndexAssert;
|
|
126
199
|
//#endregion
|
|
127
200
|
//#region src/array/first.ts
|
|
@@ -130,8 +203,17 @@ function first(arr) {
|
|
|
130
203
|
return arr[0];
|
|
131
204
|
}
|
|
132
205
|
function firstAssert(arr) {
|
|
133
|
-
return
|
|
206
|
+
return require_function.orThrow(first)(arr);
|
|
134
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Like `first`, but throws when the array is empty.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* first.assert([1, 2, 3]); // 1
|
|
214
|
+
* first.assert([]); // throws EmptyArrayError
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
135
217
|
first.assert = firstAssert;
|
|
136
218
|
//#endregion
|
|
137
219
|
//#region src/array/flatMap.ts
|
|
@@ -153,14 +235,29 @@ function forEach(...args) {
|
|
|
153
235
|
//#endregion
|
|
154
236
|
//#region src/array/init.ts
|
|
155
237
|
/**
|
|
238
|
+
* Returns all elements except the last.
|
|
156
239
|
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* init([1, 2, 3]); // [1, 2]
|
|
243
|
+
* init([1]); // []
|
|
244
|
+
* ```
|
|
157
245
|
*/
|
|
158
246
|
function init(arr) {
|
|
159
247
|
return arr.slice(0, arr.length - 1);
|
|
160
248
|
}
|
|
161
249
|
function initAssert(arr) {
|
|
162
|
-
return
|
|
250
|
+
return require_function.orThrow(init)(arr);
|
|
163
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Like `init`, but throws when the array is empty.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* init.assert([1, 2, 3]); // [1, 2]
|
|
258
|
+
* init.assert([]); // throws EmptyArrayError
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
164
261
|
init.assert = initAssert;
|
|
165
262
|
//#endregion
|
|
166
263
|
//#region src/array/insert.ts
|
|
@@ -175,8 +272,17 @@ function insert(...args) {
|
|
|
175
272
|
return require_purry.purry(insertImplementation, args);
|
|
176
273
|
}
|
|
177
274
|
function insertAssert(...args) {
|
|
178
|
-
return require_purry.purry(
|
|
275
|
+
return require_purry.purry(require_function.orThrow(insertImplementation), args);
|
|
179
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Like `insert`, but throws when the index is invalid.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* insert.assert([1, 2, 3], 1, 9); // [1, 9, 3]
|
|
283
|
+
* insert.assert(10, 9)([1, 2, 3]); // throws RangeError
|
|
284
|
+
* ```
|
|
285
|
+
*/
|
|
180
286
|
insert.assert = insertAssert;
|
|
181
287
|
//#endregion
|
|
182
288
|
//#region src/array/isEmpty.ts
|
|
@@ -201,15 +307,28 @@ function last(arr) {
|
|
|
201
307
|
return arr[arr.length - 1];
|
|
202
308
|
}
|
|
203
309
|
function lastAssert(arr) {
|
|
204
|
-
return
|
|
310
|
+
return require_function.orThrow(last)(arr);
|
|
205
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* Like `last`, but throws when the array is empty.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* last.assert([1, 2, 3]); // 3
|
|
318
|
+
* last.assert([]); // throws EmptyArrayError
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
206
321
|
last.assert = lastAssert;
|
|
207
322
|
//#endregion
|
|
208
323
|
//#region src/array/length.ts
|
|
209
324
|
/**
|
|
210
|
-
* Returns
|
|
211
|
-
*
|
|
212
|
-
* @
|
|
325
|
+
* Returns the number of elements in an array.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```ts
|
|
329
|
+
* length([1, 2, 3]); // 3
|
|
330
|
+
* length([]); // 0
|
|
331
|
+
* ```
|
|
213
332
|
*/
|
|
214
333
|
function length(arr) {
|
|
215
334
|
return arr.length;
|
|
@@ -225,9 +344,13 @@ function map(...args) {
|
|
|
225
344
|
//#endregion
|
|
226
345
|
//#region src/array/ofLength.ts
|
|
227
346
|
/**
|
|
228
|
-
*
|
|
347
|
+
* Creates a sparse array with the given length.
|
|
229
348
|
*
|
|
230
|
-
* @
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* ofLength(3); // [empty × 3]
|
|
352
|
+
* ofLength<string>(2); // [empty × 2]
|
|
353
|
+
* ```
|
|
231
354
|
*/
|
|
232
355
|
function ofLength(arrayLength) {
|
|
233
356
|
return Array(arrayLength);
|
|
@@ -256,8 +379,17 @@ function pop(arr) {
|
|
|
256
379
|
return [arr[lastIndex], arr.slice(0, lastIndex)];
|
|
257
380
|
}
|
|
258
381
|
function popAssert(arr) {
|
|
259
|
-
return
|
|
382
|
+
return require_function.orThrow(pop)(arr);
|
|
260
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Like `pop`, but throws when the array is empty.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* pop.assert([1, 2, 3]); // [3, [1, 2]]
|
|
390
|
+
* pop.assert([]); // throws EmptyArrayError
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
261
393
|
pop.assert = popAssert;
|
|
262
394
|
//#endregion
|
|
263
395
|
//#region src/array/prepend.ts
|
|
@@ -310,9 +442,13 @@ function reduceRight1(...args) {
|
|
|
310
442
|
//#endregion
|
|
311
443
|
//#region src/array/rest.ts
|
|
312
444
|
/**
|
|
313
|
-
* Returns
|
|
314
|
-
*
|
|
315
|
-
* @
|
|
445
|
+
* Returns all elements except the first.
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```ts
|
|
449
|
+
* rest([1, 2, 3]); // [2, 3]
|
|
450
|
+
* rest([1]); // []
|
|
451
|
+
* ```
|
|
316
452
|
*/
|
|
317
453
|
function rest(arr) {
|
|
318
454
|
const [, ...tail] = arr;
|
|
@@ -350,11 +486,28 @@ function shift(arr) {
|
|
|
350
486
|
return [head, tail];
|
|
351
487
|
}
|
|
352
488
|
function shiftAssert(arr) {
|
|
353
|
-
return
|
|
489
|
+
return require_function.orThrow(shift)(arr);
|
|
354
490
|
}
|
|
491
|
+
/**
|
|
492
|
+
* Like `shift`, but throws when the array is empty.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* shift.assert([1, 2, 3]); // [1, [2, 3]]
|
|
497
|
+
* shift.assert([]); // throws EmptyArrayError
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
355
500
|
shift.assert = shiftAssert;
|
|
356
501
|
//#endregion
|
|
357
502
|
//#region src/array/shuffle.ts
|
|
503
|
+
/**
|
|
504
|
+
* Returns a shuffled copy of an array using the Fisher-Yates algorithm.
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```ts
|
|
508
|
+
* shuffle([1, 2, 3, 4]); // e.g. [3, 1, 4, 2]
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
358
511
|
function shuffle(arr) {
|
|
359
512
|
const result = [...arr];
|
|
360
513
|
const len = result.length;
|
|
@@ -407,12 +560,29 @@ function take(...args) {
|
|
|
407
560
|
}
|
|
408
561
|
//#endregion
|
|
409
562
|
//#region src/array/transpose.ts
|
|
563
|
+
/**
|
|
564
|
+
* Transposes a matrix so rows become columns and columns become rows.
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
567
|
+
* ```ts
|
|
568
|
+
* transpose([[1, 2], [3, 4], [5, 6]]); // [[1, 3, 5], [2, 4, 6]]
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
410
571
|
function transpose(arr) {
|
|
411
572
|
const maxLen = arr.reduce((acc, inner) => Math.max(acc, inner.length), 0);
|
|
412
573
|
return Array(maxLen).fill(void 0).map((_, index) => arr.map((inner) => inner[index]));
|
|
413
574
|
}
|
|
414
575
|
//#endregion
|
|
415
576
|
//#region src/array/unique.ts
|
|
577
|
+
/**
|
|
578
|
+
* Returns a copy of an array with duplicate values removed.
|
|
579
|
+
*
|
|
580
|
+
* @example
|
|
581
|
+
* ```ts
|
|
582
|
+
* unique([1, 2, 2, 3]); // [1, 2, 3]
|
|
583
|
+
* unique([]); // []
|
|
584
|
+
* ```
|
|
585
|
+
*/
|
|
416
586
|
function unique(arr) {
|
|
417
587
|
if (arr.length === 0) return [];
|
|
418
588
|
return Array.from(new Set(arr));
|
|
@@ -434,6 +604,16 @@ function uniqueBy(...args) {
|
|
|
434
604
|
}
|
|
435
605
|
//#endregion
|
|
436
606
|
//#region src/array/uniqueWith.ts
|
|
607
|
+
/**
|
|
608
|
+
* Returns a copy of an array with duplicates removed using a custom equality function.
|
|
609
|
+
* Keeps the first occurrence of each equivalent value.
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```ts
|
|
613
|
+
* uniqueWith([1, 1.0, 2], (a, b) => a === b); // [1, 2]
|
|
614
|
+
* uniqueWith([], (a, b) => a === b); // []
|
|
615
|
+
* ```
|
|
616
|
+
*/
|
|
437
617
|
function uniqueWith(arr, isEqual) {
|
|
438
618
|
if (arr.length === 0) return [];
|
|
439
619
|
return arr.filter((value, index) => {
|
|
@@ -459,8 +639,17 @@ function update(...args) {
|
|
|
459
639
|
return require_purry.purry(updateImplementation, args);
|
|
460
640
|
}
|
|
461
641
|
function updateAssert(...args) {
|
|
462
|
-
return require_purry.purry(
|
|
642
|
+
return require_purry.purry(require_function.orThrow(updateImplementation), args);
|
|
463
643
|
}
|
|
644
|
+
/**
|
|
645
|
+
* Like `update`, but throws when the index is out of bounds.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
* ```ts
|
|
649
|
+
* update.assert([1, 2, 3], 1, n => n * 10); // [1, 20, 3]
|
|
650
|
+
* update.assert(10, n => n)([1, 2, 3]); // throws RangeError
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
464
653
|
update.assert = updateAssert;
|
|
465
654
|
//#endregion
|
|
466
655
|
//#region src/array/window.ts
|
|
@@ -474,8 +663,17 @@ function window(...args) {
|
|
|
474
663
|
return require_purry.purry(windowImplementation, args);
|
|
475
664
|
}
|
|
476
665
|
function windowAssert(...args) {
|
|
477
|
-
return require_purry.purry(
|
|
666
|
+
return require_purry.purry(require_function.orThrow(windowImplementation), args);
|
|
478
667
|
}
|
|
668
|
+
/**
|
|
669
|
+
* Like `window`, but throws when the size is not a positive integer.
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* window.assert([1, 2, 3, 4], 2); // [[1, 2], [2, 3], [3, 4]]
|
|
674
|
+
* window.assert(0)([1, 2, 3]); // throws RangeError
|
|
675
|
+
* ```
|
|
676
|
+
*/
|
|
479
677
|
window.assert = windowAssert;
|
|
480
678
|
//#endregion
|
|
481
679
|
//#region src/array/zip.ts
|
|
@@ -494,9 +692,8 @@ function zipWith(...args) {
|
|
|
494
692
|
return require_purry.purry(zipWithImplementation, args);
|
|
495
693
|
}
|
|
496
694
|
//#endregion
|
|
497
|
-
exports.
|
|
695
|
+
exports.Ctor = Ctor;
|
|
498
696
|
exports.at = at;
|
|
499
|
-
exports.atAssert = atAssert;
|
|
500
697
|
exports.chunk = chunk;
|
|
501
698
|
exports.concat = concat;
|
|
502
699
|
exports.drop = drop;
|