@zairakai/js-utils 1.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/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/arrays.cjs +210 -0
- package/dist/arrays.d.cts +119 -0
- package/dist/arrays.d.ts +119 -0
- package/dist/arrays.js +32 -0
- package/dist/chunk-27YHP2CK.js +407 -0
- package/dist/chunk-3WNRYKPG.js +37 -0
- package/dist/chunk-42CHLXT7.js +214 -0
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-7SXRFZBB.js +173 -0
- package/dist/chunk-F6RSTW65.js +156 -0
- package/dist/chunk-G7ZJ23DW.js +253 -0
- package/dist/chunk-IPP7PA6H.js +136 -0
- package/dist/chunk-LDSWHSRX.js +96 -0
- package/dist/chunk-TY75OOIQ.js +700 -0
- package/dist/chunk-W6JEMFAF.js +54 -0
- package/dist/chunk-XEJLBAXE.js +164 -0
- package/dist/chunk-Z7G3SIQH.js +270 -0
- package/dist/chunk-ZJPKS2MQ.js +101 -0
- package/dist/collections.cjs +797 -0
- package/dist/collections.d.cts +353 -0
- package/dist/collections.d.ts +353 -0
- package/dist/collections.js +17 -0
- package/dist/datetime.cjs +80 -0
- package/dist/datetime.d.cts +75 -0
- package/dist/datetime.d.ts +75 -0
- package/dist/datetime.js +24 -0
- package/dist/equals.cjs +121 -0
- package/dist/equals.d.cts +24 -0
- package/dist/equals.d.ts +24 -0
- package/dist/equals.js +8 -0
- package/dist/formatters.cjs +201 -0
- package/dist/formatters.d.cts +180 -0
- package/dist/formatters.d.ts +180 -0
- package/dist/formatters.js +48 -0
- package/dist/index.cjs +2906 -0
- package/dist/index.d.cts +120 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +348 -0
- package/dist/number.cjs +279 -0
- package/dist/number.d.cts +177 -0
- package/dist/number.d.ts +177 -0
- package/dist/number.js +10 -0
- package/dist/obj.cjs +427 -0
- package/dist/obj.d.cts +177 -0
- package/dist/obj.d.ts +177 -0
- package/dist/obj.js +12 -0
- package/dist/php-arrays.cjs +954 -0
- package/dist/php-arrays.d.cts +256 -0
- package/dist/php-arrays.d.ts +256 -0
- package/dist/php-arrays.js +70 -0
- package/dist/runtime.cjs +134 -0
- package/dist/runtime.d.cts +90 -0
- package/dist/runtime.d.ts +90 -0
- package/dist/runtime.js +24 -0
- package/dist/schemas.cjs +86 -0
- package/dist/schemas.d.cts +108 -0
- package/dist/schemas.d.ts +108 -0
- package/dist/schemas.js +22 -0
- package/dist/str.cjs +499 -0
- package/dist/str.d.cts +282 -0
- package/dist/str.d.ts +282 -0
- package/dist/str.js +11 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +13 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +1 -0
- package/dist/validator.cjs +251 -0
- package/dist/validator.d.cts +99 -0
- package/dist/validator.d.ts +99 -0
- package/dist/validator.js +11 -0
- package/dist/validators.cjs +217 -0
- package/dist/validators.d.cts +216 -0
- package/dist/validators.d.ts +216 -0
- package/dist/validators.js +64 -0
- package/package.json +180 -0
- package/src/arrays.ts +316 -0
- package/src/collections.ts +866 -0
- package/src/datetime.ts +103 -0
- package/src/equals.ts +134 -0
- package/src/formatters.ts +342 -0
- package/src/index.ts +36 -0
- package/src/number.ts +281 -0
- package/src/obj.ts +303 -0
- package/src/php-arrays.ts +445 -0
- package/src/pipe.ts +29 -0
- package/src/runtime.ts +194 -0
- package/src/schemas.ts +136 -0
- package/src/str.ts +438 -0
- package/src/types.ts +13 -0
- package/src/validator.ts +157 -0
- package/src/validators.ts +359 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { EnhancedArray } from './collections.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PHP-like array functions for JavaScript
|
|
5
|
+
* Provides exact API compatibility between PHP arrays and JavaScript arrays
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Split an array into chunks.
|
|
10
|
+
*
|
|
11
|
+
* @param {T[]} array The array to chunk
|
|
12
|
+
* @param {number} size The size of each chunk
|
|
13
|
+
* @returns {T[][]} An array of chunks
|
|
14
|
+
*/
|
|
15
|
+
declare const array_chunk: <T>(array: T[], size: number) => T[][];
|
|
16
|
+
/**
|
|
17
|
+
* Filter elements of an array using a callback function.
|
|
18
|
+
*
|
|
19
|
+
* @param {T[]} array The array to filter
|
|
20
|
+
* @param {Function} [callback] The callback function to use
|
|
21
|
+
* @returns {T[]} The filtered array
|
|
22
|
+
*/
|
|
23
|
+
declare const array_filter: <T>(array: T[], callback?: (value: T, index: number) => boolean) => T[];
|
|
24
|
+
/**
|
|
25
|
+
* Apply a callback to the elements of the given arrays.
|
|
26
|
+
*
|
|
27
|
+
* @param {Function} callback The callback function to apply
|
|
28
|
+
* @param {T[]} array The array to map over
|
|
29
|
+
* @returns {U[]} The mapped array
|
|
30
|
+
*/
|
|
31
|
+
declare const array_map: <T, U>(callback: (value: T, index: number) => U, array: T[]) => U[];
|
|
32
|
+
/**
|
|
33
|
+
* Iteratively reduce the array to a single value using a callback function.
|
|
34
|
+
*
|
|
35
|
+
* @param {T[]} array The source array
|
|
36
|
+
* @param {Function} callback The callback function
|
|
37
|
+
* @param {U} initial The initial value
|
|
38
|
+
* @returns {U} The reduced value
|
|
39
|
+
*/
|
|
40
|
+
declare const array_reduce: <T, U>(array: T[], callback: (carry: U, item: T, index: number) => U, initial: U) => U;
|
|
41
|
+
/**
|
|
42
|
+
* Merge one or more arrays.
|
|
43
|
+
*
|
|
44
|
+
* @param {...T[][]} arrays The arrays to merge
|
|
45
|
+
* @returns {T[]} The merged array
|
|
46
|
+
*/
|
|
47
|
+
declare const array_merge: <T>(...arrays: T[][]) => T[];
|
|
48
|
+
/**
|
|
49
|
+
* Remove duplicate values from an array.
|
|
50
|
+
*
|
|
51
|
+
* @param {T[]} array The source array
|
|
52
|
+
* @returns {T[]} The array with unique values
|
|
53
|
+
*/
|
|
54
|
+
declare const array_unique: <T>(array: T[]) => T[];
|
|
55
|
+
/**
|
|
56
|
+
* Return an array with elements in reverse order.
|
|
57
|
+
*
|
|
58
|
+
* @param {T[]} array The source array
|
|
59
|
+
* @param {boolean} [_preserveKeys=false] Whether to preserve keys (ignored for JS arrays)
|
|
60
|
+
* @returns {T[]} The reversed array
|
|
61
|
+
*/
|
|
62
|
+
declare const array_reverse: <T>(array: T[], _preserveKeys?: boolean) => T[];
|
|
63
|
+
/**
|
|
64
|
+
* Extract a slice of the array.
|
|
65
|
+
*
|
|
66
|
+
* @param {T[]} array The source array
|
|
67
|
+
* @param {number} offset The starting offset
|
|
68
|
+
* @param {number} [length] The length of the slice
|
|
69
|
+
* @returns {T[]} The sliced portion of the array
|
|
70
|
+
*/
|
|
71
|
+
declare const array_slice: <T>(array: T[], offset: number, length?: number) => T[];
|
|
72
|
+
/**
|
|
73
|
+
* Remove a portion of the array and replace it with something else.
|
|
74
|
+
*
|
|
75
|
+
* @param {T[]} array The source array
|
|
76
|
+
* @param {number} offset The starting offset
|
|
77
|
+
* @param {number} [length] The number of elements to remove
|
|
78
|
+
* @param {...T[]} replacement The elements to replace with
|
|
79
|
+
* @returns {T[]} The modified array (copy)
|
|
80
|
+
*/
|
|
81
|
+
declare const array_splice: <T>(array: T[], offset: number, length?: number, ...replacement: T[]) => T[];
|
|
82
|
+
/**
|
|
83
|
+
* Return all the keys or a subset of the keys of an array.
|
|
84
|
+
*
|
|
85
|
+
* @param {T[]} array The source array
|
|
86
|
+
* @returns {number[]} The array keys (indices)
|
|
87
|
+
*/
|
|
88
|
+
declare const array_keys: <T>(array: T[]) => number[];
|
|
89
|
+
/**
|
|
90
|
+
* Search an array for a given value and return the corresponding key if successful.
|
|
91
|
+
*
|
|
92
|
+
* @param {T} needle The value to search for
|
|
93
|
+
* @param {T[]} haystack The array to search in
|
|
94
|
+
* @returns {number | false} The key if found, false otherwise
|
|
95
|
+
*/
|
|
96
|
+
declare const array_search: <T>(needle: T, haystack: T[]) => number | false;
|
|
97
|
+
/**
|
|
98
|
+
* Check if the given key or index exists in the array.
|
|
99
|
+
*
|
|
100
|
+
* @param {number} key The key to check
|
|
101
|
+
* @param {T[]} array The source array
|
|
102
|
+
* @returns {boolean} True if the key exists
|
|
103
|
+
*/
|
|
104
|
+
declare const array_key_exists: <T>(key: number, array: T[]) => boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Pop the element off the end of array.
|
|
107
|
+
*
|
|
108
|
+
* @param {T[]} array The source array
|
|
109
|
+
* @returns {T | undefined} The popped element
|
|
110
|
+
*/
|
|
111
|
+
declare const array_pop: <T>(array: T[]) => T | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Push one or more elements onto the end of array.
|
|
114
|
+
*
|
|
115
|
+
* @param {T[]} array The source array
|
|
116
|
+
* @param {...T[]} values The values to push
|
|
117
|
+
* @returns {T[]} The modified array (copy)
|
|
118
|
+
*/
|
|
119
|
+
declare const array_push: <T>(array: T[], ...values: T[]) => T[];
|
|
120
|
+
/**
|
|
121
|
+
* Shift an element off the beginning of array.
|
|
122
|
+
*
|
|
123
|
+
* @param {T[]} array The source array
|
|
124
|
+
* @returns {T | undefined} The shifted element
|
|
125
|
+
*/
|
|
126
|
+
declare const array_shift: <T>(array: T[]) => T | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Prepend one or more elements to the beginning of an array.
|
|
129
|
+
*
|
|
130
|
+
* @param {T[]} array The source array
|
|
131
|
+
* @param {...T[]} values The values to prepend
|
|
132
|
+
* @returns {T[]} The modified array (copy)
|
|
133
|
+
*/
|
|
134
|
+
declare const array_unshift: <T>(array: T[], ...values: T[]) => T[];
|
|
135
|
+
/**
|
|
136
|
+
* Calculate the sum of values in an array.
|
|
137
|
+
*
|
|
138
|
+
* @param {number[]} array The source array
|
|
139
|
+
* @returns {number} The sum of values
|
|
140
|
+
*/
|
|
141
|
+
declare const array_sum: (array: number[]) => number;
|
|
142
|
+
/**
|
|
143
|
+
* Calculate the product of values in an array.
|
|
144
|
+
*
|
|
145
|
+
* @param {number[]} array The source array
|
|
146
|
+
* @returns {number} The product of values
|
|
147
|
+
*/
|
|
148
|
+
declare const array_product: (array: number[]) => number;
|
|
149
|
+
/**
|
|
150
|
+
* Pick one or more random entries out of an array.
|
|
151
|
+
*
|
|
152
|
+
* @param {T[]} array The source array
|
|
153
|
+
* @param {number} [num=1] The number of entries to pick
|
|
154
|
+
* @returns {T | T[] | undefined} The random entry or entries
|
|
155
|
+
*/
|
|
156
|
+
declare const array_rand: <T>(array: T[], num?: number) => T | T[] | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Exchange all keys with their associated values in an array.
|
|
159
|
+
*
|
|
160
|
+
* @param {T[]} array The source array
|
|
161
|
+
* @returns {Record<string, number>} The flipped record
|
|
162
|
+
*/
|
|
163
|
+
declare const array_flip: <T extends string | number>(array: T[]) => Record<string, number>;
|
|
164
|
+
/**
|
|
165
|
+
* Count all the values of an array.
|
|
166
|
+
*
|
|
167
|
+
* @param {T[]} array The source array
|
|
168
|
+
* @returns {Record<string, number>} A record of values and their counts
|
|
169
|
+
*/
|
|
170
|
+
declare const array_count_values: <T extends string | number>(array: T[]) => Record<string, number>;
|
|
171
|
+
/**
|
|
172
|
+
* Compute the intersection of arrays.
|
|
173
|
+
*
|
|
174
|
+
* @param {...T[][]} arrays The arrays to intersect
|
|
175
|
+
* @returns {T[]} The intersection of the arrays
|
|
176
|
+
*/
|
|
177
|
+
declare const array_intersect: <T>(...arrays: T[][]) => T[];
|
|
178
|
+
/**
|
|
179
|
+
* Compute the difference of arrays.
|
|
180
|
+
*
|
|
181
|
+
* @param {T[]} array1 The array to compare from
|
|
182
|
+
* @param {...T[][]} arrays The arrays to compare against
|
|
183
|
+
* @returns {T[]} The difference of the arrays
|
|
184
|
+
*/
|
|
185
|
+
declare const array_diff: <T>(array1: T[], ...arrays: T[][]) => T[];
|
|
186
|
+
/**
|
|
187
|
+
* Return the values from a single column in the input array.
|
|
188
|
+
*
|
|
189
|
+
* @param {T[]} array The source array of objects
|
|
190
|
+
* @param {K} column The column to retrieve
|
|
191
|
+
* @returns {T[K][]} The array of column values
|
|
192
|
+
*/
|
|
193
|
+
declare const array_column: <T, K extends keyof T>(array: T[], column: K) => T[K][];
|
|
194
|
+
/**
|
|
195
|
+
* Sort an array.
|
|
196
|
+
*
|
|
197
|
+
* @param {T[]} array The source array
|
|
198
|
+
* @returns {T[]} The sorted array (copy)
|
|
199
|
+
*/
|
|
200
|
+
declare const sort: <T>(array: T[]) => T[];
|
|
201
|
+
/**
|
|
202
|
+
* Sort an array in reverse order.
|
|
203
|
+
*
|
|
204
|
+
* @param {T[]} array The source array
|
|
205
|
+
* @returns {T[]} The sorted array (copy)
|
|
206
|
+
*/
|
|
207
|
+
declare const rsort: <T>(array: T[]) => T[];
|
|
208
|
+
/**
|
|
209
|
+
* Sort an array with a user-defined comparison function.
|
|
210
|
+
*
|
|
211
|
+
* @param {T[]} array The source array
|
|
212
|
+
* @param {Function} compareFunction The comparison function
|
|
213
|
+
* @returns {T[]} The sorted array (copy)
|
|
214
|
+
*/
|
|
215
|
+
declare const usort: <T>(array: T[], compareFunction: (a: T, b: T) => number) => T[];
|
|
216
|
+
/**
|
|
217
|
+
* Sort an array with a user-defined comparison function and maintain index association.
|
|
218
|
+
*
|
|
219
|
+
* @param {T[]} array The source array
|
|
220
|
+
* @param {Function} compareFunction The comparison function
|
|
221
|
+
* @returns {T[]} The sorted array (copy)
|
|
222
|
+
*/
|
|
223
|
+
declare const uasort: <T>(array: T[], compareFunction: (a: T, b: T) => number) => T[];
|
|
224
|
+
/**
|
|
225
|
+
* Sort an array by keys using a user-defined comparison function.
|
|
226
|
+
*
|
|
227
|
+
* @param {T[]} array The source array
|
|
228
|
+
* @param {Function} compareFunction The comparison function
|
|
229
|
+
* @returns {T[]} The sorted array (copy)
|
|
230
|
+
*/
|
|
231
|
+
declare const uksort: <T>(array: T[], compareFunction: (a: number, b: number) => number) => T[];
|
|
232
|
+
/**
|
|
233
|
+
* Shuffle an array.
|
|
234
|
+
*
|
|
235
|
+
* @param {T[]} array The source array
|
|
236
|
+
* @returns {T[]} The shuffled array (copy)
|
|
237
|
+
*/
|
|
238
|
+
declare const shuffle: <T>(array: T[]) => T[];
|
|
239
|
+
/**
|
|
240
|
+
* Create an array containing a range of elements.
|
|
241
|
+
*
|
|
242
|
+
* @param {number} start First value of the sequence
|
|
243
|
+
* @param {number} end The sequence is stopped when end is reached
|
|
244
|
+
* @param {number} [step=1] The increment used in the range
|
|
245
|
+
* @returns {number[]} The array of elements
|
|
246
|
+
*/
|
|
247
|
+
declare const range: (start: number, end: number, step?: number) => number[];
|
|
248
|
+
/**
|
|
249
|
+
* Create an EnhancedArray with PHP-like methods.
|
|
250
|
+
*
|
|
251
|
+
* @param {T[]} items The source items
|
|
252
|
+
* @returns {EnhancedArray<T>} The enhanced array
|
|
253
|
+
*/
|
|
254
|
+
declare const php_array: <T>(items: T[]) => EnhancedArray<T>;
|
|
255
|
+
|
|
256
|
+
export { array_chunk, array_column, array_count_values, array_diff, array_filter, array_flip, array_intersect, array_key_exists, array_keys, array_map, array_merge, array_pop, array_product, array_push, array_rand, array_reduce, array_reverse, array_search, array_shift, array_slice, array_splice, array_sum, array_unique, array_unshift, php_array, range, rsort, shuffle, sort, uasort, uksort, usort };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { EnhancedArray } from './collections.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* PHP-like array functions for JavaScript
|
|
5
|
+
* Provides exact API compatibility between PHP arrays and JavaScript arrays
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Split an array into chunks.
|
|
10
|
+
*
|
|
11
|
+
* @param {T[]} array The array to chunk
|
|
12
|
+
* @param {number} size The size of each chunk
|
|
13
|
+
* @returns {T[][]} An array of chunks
|
|
14
|
+
*/
|
|
15
|
+
declare const array_chunk: <T>(array: T[], size: number) => T[][];
|
|
16
|
+
/**
|
|
17
|
+
* Filter elements of an array using a callback function.
|
|
18
|
+
*
|
|
19
|
+
* @param {T[]} array The array to filter
|
|
20
|
+
* @param {Function} [callback] The callback function to use
|
|
21
|
+
* @returns {T[]} The filtered array
|
|
22
|
+
*/
|
|
23
|
+
declare const array_filter: <T>(array: T[], callback?: (value: T, index: number) => boolean) => T[];
|
|
24
|
+
/**
|
|
25
|
+
* Apply a callback to the elements of the given arrays.
|
|
26
|
+
*
|
|
27
|
+
* @param {Function} callback The callback function to apply
|
|
28
|
+
* @param {T[]} array The array to map over
|
|
29
|
+
* @returns {U[]} The mapped array
|
|
30
|
+
*/
|
|
31
|
+
declare const array_map: <T, U>(callback: (value: T, index: number) => U, array: T[]) => U[];
|
|
32
|
+
/**
|
|
33
|
+
* Iteratively reduce the array to a single value using a callback function.
|
|
34
|
+
*
|
|
35
|
+
* @param {T[]} array The source array
|
|
36
|
+
* @param {Function} callback The callback function
|
|
37
|
+
* @param {U} initial The initial value
|
|
38
|
+
* @returns {U} The reduced value
|
|
39
|
+
*/
|
|
40
|
+
declare const array_reduce: <T, U>(array: T[], callback: (carry: U, item: T, index: number) => U, initial: U) => U;
|
|
41
|
+
/**
|
|
42
|
+
* Merge one or more arrays.
|
|
43
|
+
*
|
|
44
|
+
* @param {...T[][]} arrays The arrays to merge
|
|
45
|
+
* @returns {T[]} The merged array
|
|
46
|
+
*/
|
|
47
|
+
declare const array_merge: <T>(...arrays: T[][]) => T[];
|
|
48
|
+
/**
|
|
49
|
+
* Remove duplicate values from an array.
|
|
50
|
+
*
|
|
51
|
+
* @param {T[]} array The source array
|
|
52
|
+
* @returns {T[]} The array with unique values
|
|
53
|
+
*/
|
|
54
|
+
declare const array_unique: <T>(array: T[]) => T[];
|
|
55
|
+
/**
|
|
56
|
+
* Return an array with elements in reverse order.
|
|
57
|
+
*
|
|
58
|
+
* @param {T[]} array The source array
|
|
59
|
+
* @param {boolean} [_preserveKeys=false] Whether to preserve keys (ignored for JS arrays)
|
|
60
|
+
* @returns {T[]} The reversed array
|
|
61
|
+
*/
|
|
62
|
+
declare const array_reverse: <T>(array: T[], _preserveKeys?: boolean) => T[];
|
|
63
|
+
/**
|
|
64
|
+
* Extract a slice of the array.
|
|
65
|
+
*
|
|
66
|
+
* @param {T[]} array The source array
|
|
67
|
+
* @param {number} offset The starting offset
|
|
68
|
+
* @param {number} [length] The length of the slice
|
|
69
|
+
* @returns {T[]} The sliced portion of the array
|
|
70
|
+
*/
|
|
71
|
+
declare const array_slice: <T>(array: T[], offset: number, length?: number) => T[];
|
|
72
|
+
/**
|
|
73
|
+
* Remove a portion of the array and replace it with something else.
|
|
74
|
+
*
|
|
75
|
+
* @param {T[]} array The source array
|
|
76
|
+
* @param {number} offset The starting offset
|
|
77
|
+
* @param {number} [length] The number of elements to remove
|
|
78
|
+
* @param {...T[]} replacement The elements to replace with
|
|
79
|
+
* @returns {T[]} The modified array (copy)
|
|
80
|
+
*/
|
|
81
|
+
declare const array_splice: <T>(array: T[], offset: number, length?: number, ...replacement: T[]) => T[];
|
|
82
|
+
/**
|
|
83
|
+
* Return all the keys or a subset of the keys of an array.
|
|
84
|
+
*
|
|
85
|
+
* @param {T[]} array The source array
|
|
86
|
+
* @returns {number[]} The array keys (indices)
|
|
87
|
+
*/
|
|
88
|
+
declare const array_keys: <T>(array: T[]) => number[];
|
|
89
|
+
/**
|
|
90
|
+
* Search an array for a given value and return the corresponding key if successful.
|
|
91
|
+
*
|
|
92
|
+
* @param {T} needle The value to search for
|
|
93
|
+
* @param {T[]} haystack The array to search in
|
|
94
|
+
* @returns {number | false} The key if found, false otherwise
|
|
95
|
+
*/
|
|
96
|
+
declare const array_search: <T>(needle: T, haystack: T[]) => number | false;
|
|
97
|
+
/**
|
|
98
|
+
* Check if the given key or index exists in the array.
|
|
99
|
+
*
|
|
100
|
+
* @param {number} key The key to check
|
|
101
|
+
* @param {T[]} array The source array
|
|
102
|
+
* @returns {boolean} True if the key exists
|
|
103
|
+
*/
|
|
104
|
+
declare const array_key_exists: <T>(key: number, array: T[]) => boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Pop the element off the end of array.
|
|
107
|
+
*
|
|
108
|
+
* @param {T[]} array The source array
|
|
109
|
+
* @returns {T | undefined} The popped element
|
|
110
|
+
*/
|
|
111
|
+
declare const array_pop: <T>(array: T[]) => T | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Push one or more elements onto the end of array.
|
|
114
|
+
*
|
|
115
|
+
* @param {T[]} array The source array
|
|
116
|
+
* @param {...T[]} values The values to push
|
|
117
|
+
* @returns {T[]} The modified array (copy)
|
|
118
|
+
*/
|
|
119
|
+
declare const array_push: <T>(array: T[], ...values: T[]) => T[];
|
|
120
|
+
/**
|
|
121
|
+
* Shift an element off the beginning of array.
|
|
122
|
+
*
|
|
123
|
+
* @param {T[]} array The source array
|
|
124
|
+
* @returns {T | undefined} The shifted element
|
|
125
|
+
*/
|
|
126
|
+
declare const array_shift: <T>(array: T[]) => T | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Prepend one or more elements to the beginning of an array.
|
|
129
|
+
*
|
|
130
|
+
* @param {T[]} array The source array
|
|
131
|
+
* @param {...T[]} values The values to prepend
|
|
132
|
+
* @returns {T[]} The modified array (copy)
|
|
133
|
+
*/
|
|
134
|
+
declare const array_unshift: <T>(array: T[], ...values: T[]) => T[];
|
|
135
|
+
/**
|
|
136
|
+
* Calculate the sum of values in an array.
|
|
137
|
+
*
|
|
138
|
+
* @param {number[]} array The source array
|
|
139
|
+
* @returns {number} The sum of values
|
|
140
|
+
*/
|
|
141
|
+
declare const array_sum: (array: number[]) => number;
|
|
142
|
+
/**
|
|
143
|
+
* Calculate the product of values in an array.
|
|
144
|
+
*
|
|
145
|
+
* @param {number[]} array The source array
|
|
146
|
+
* @returns {number} The product of values
|
|
147
|
+
*/
|
|
148
|
+
declare const array_product: (array: number[]) => number;
|
|
149
|
+
/**
|
|
150
|
+
* Pick one or more random entries out of an array.
|
|
151
|
+
*
|
|
152
|
+
* @param {T[]} array The source array
|
|
153
|
+
* @param {number} [num=1] The number of entries to pick
|
|
154
|
+
* @returns {T | T[] | undefined} The random entry or entries
|
|
155
|
+
*/
|
|
156
|
+
declare const array_rand: <T>(array: T[], num?: number) => T | T[] | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Exchange all keys with their associated values in an array.
|
|
159
|
+
*
|
|
160
|
+
* @param {T[]} array The source array
|
|
161
|
+
* @returns {Record<string, number>} The flipped record
|
|
162
|
+
*/
|
|
163
|
+
declare const array_flip: <T extends string | number>(array: T[]) => Record<string, number>;
|
|
164
|
+
/**
|
|
165
|
+
* Count all the values of an array.
|
|
166
|
+
*
|
|
167
|
+
* @param {T[]} array The source array
|
|
168
|
+
* @returns {Record<string, number>} A record of values and their counts
|
|
169
|
+
*/
|
|
170
|
+
declare const array_count_values: <T extends string | number>(array: T[]) => Record<string, number>;
|
|
171
|
+
/**
|
|
172
|
+
* Compute the intersection of arrays.
|
|
173
|
+
*
|
|
174
|
+
* @param {...T[][]} arrays The arrays to intersect
|
|
175
|
+
* @returns {T[]} The intersection of the arrays
|
|
176
|
+
*/
|
|
177
|
+
declare const array_intersect: <T>(...arrays: T[][]) => T[];
|
|
178
|
+
/**
|
|
179
|
+
* Compute the difference of arrays.
|
|
180
|
+
*
|
|
181
|
+
* @param {T[]} array1 The array to compare from
|
|
182
|
+
* @param {...T[][]} arrays The arrays to compare against
|
|
183
|
+
* @returns {T[]} The difference of the arrays
|
|
184
|
+
*/
|
|
185
|
+
declare const array_diff: <T>(array1: T[], ...arrays: T[][]) => T[];
|
|
186
|
+
/**
|
|
187
|
+
* Return the values from a single column in the input array.
|
|
188
|
+
*
|
|
189
|
+
* @param {T[]} array The source array of objects
|
|
190
|
+
* @param {K} column The column to retrieve
|
|
191
|
+
* @returns {T[K][]} The array of column values
|
|
192
|
+
*/
|
|
193
|
+
declare const array_column: <T, K extends keyof T>(array: T[], column: K) => T[K][];
|
|
194
|
+
/**
|
|
195
|
+
* Sort an array.
|
|
196
|
+
*
|
|
197
|
+
* @param {T[]} array The source array
|
|
198
|
+
* @returns {T[]} The sorted array (copy)
|
|
199
|
+
*/
|
|
200
|
+
declare const sort: <T>(array: T[]) => T[];
|
|
201
|
+
/**
|
|
202
|
+
* Sort an array in reverse order.
|
|
203
|
+
*
|
|
204
|
+
* @param {T[]} array The source array
|
|
205
|
+
* @returns {T[]} The sorted array (copy)
|
|
206
|
+
*/
|
|
207
|
+
declare const rsort: <T>(array: T[]) => T[];
|
|
208
|
+
/**
|
|
209
|
+
* Sort an array with a user-defined comparison function.
|
|
210
|
+
*
|
|
211
|
+
* @param {T[]} array The source array
|
|
212
|
+
* @param {Function} compareFunction The comparison function
|
|
213
|
+
* @returns {T[]} The sorted array (copy)
|
|
214
|
+
*/
|
|
215
|
+
declare const usort: <T>(array: T[], compareFunction: (a: T, b: T) => number) => T[];
|
|
216
|
+
/**
|
|
217
|
+
* Sort an array with a user-defined comparison function and maintain index association.
|
|
218
|
+
*
|
|
219
|
+
* @param {T[]} array The source array
|
|
220
|
+
* @param {Function} compareFunction The comparison function
|
|
221
|
+
* @returns {T[]} The sorted array (copy)
|
|
222
|
+
*/
|
|
223
|
+
declare const uasort: <T>(array: T[], compareFunction: (a: T, b: T) => number) => T[];
|
|
224
|
+
/**
|
|
225
|
+
* Sort an array by keys using a user-defined comparison function.
|
|
226
|
+
*
|
|
227
|
+
* @param {T[]} array The source array
|
|
228
|
+
* @param {Function} compareFunction The comparison function
|
|
229
|
+
* @returns {T[]} The sorted array (copy)
|
|
230
|
+
*/
|
|
231
|
+
declare const uksort: <T>(array: T[], compareFunction: (a: number, b: number) => number) => T[];
|
|
232
|
+
/**
|
|
233
|
+
* Shuffle an array.
|
|
234
|
+
*
|
|
235
|
+
* @param {T[]} array The source array
|
|
236
|
+
* @returns {T[]} The shuffled array (copy)
|
|
237
|
+
*/
|
|
238
|
+
declare const shuffle: <T>(array: T[]) => T[];
|
|
239
|
+
/**
|
|
240
|
+
* Create an array containing a range of elements.
|
|
241
|
+
*
|
|
242
|
+
* @param {number} start First value of the sequence
|
|
243
|
+
* @param {number} end The sequence is stopped when end is reached
|
|
244
|
+
* @param {number} [step=1] The increment used in the range
|
|
245
|
+
* @returns {number[]} The array of elements
|
|
246
|
+
*/
|
|
247
|
+
declare const range: (start: number, end: number, step?: number) => number[];
|
|
248
|
+
/**
|
|
249
|
+
* Create an EnhancedArray with PHP-like methods.
|
|
250
|
+
*
|
|
251
|
+
* @param {T[]} items The source items
|
|
252
|
+
* @returns {EnhancedArray<T>} The enhanced array
|
|
253
|
+
*/
|
|
254
|
+
declare const php_array: <T>(items: T[]) => EnhancedArray<T>;
|
|
255
|
+
|
|
256
|
+
export { array_chunk, array_column, array_count_values, array_diff, array_filter, array_flip, array_intersect, array_key_exists, array_keys, array_map, array_merge, array_pop, array_product, array_push, array_rand, array_reduce, array_reverse, array_search, array_shift, array_slice, array_splice, array_sum, array_unique, array_unshift, php_array, range, rsort, shuffle, sort, uasort, uksort, usort };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
array_chunk,
|
|
3
|
+
array_column,
|
|
4
|
+
array_count_values,
|
|
5
|
+
array_diff,
|
|
6
|
+
array_filter,
|
|
7
|
+
array_flip,
|
|
8
|
+
array_intersect,
|
|
9
|
+
array_key_exists,
|
|
10
|
+
array_keys,
|
|
11
|
+
array_map,
|
|
12
|
+
array_merge,
|
|
13
|
+
array_pop,
|
|
14
|
+
array_product,
|
|
15
|
+
array_push,
|
|
16
|
+
array_rand,
|
|
17
|
+
array_reduce,
|
|
18
|
+
array_reverse,
|
|
19
|
+
array_search,
|
|
20
|
+
array_shift,
|
|
21
|
+
array_slice,
|
|
22
|
+
array_splice,
|
|
23
|
+
array_sum,
|
|
24
|
+
array_unique,
|
|
25
|
+
array_unshift,
|
|
26
|
+
php_array,
|
|
27
|
+
range,
|
|
28
|
+
rsort,
|
|
29
|
+
shuffle,
|
|
30
|
+
sort,
|
|
31
|
+
uasort,
|
|
32
|
+
uksort,
|
|
33
|
+
usort
|
|
34
|
+
} from "./chunk-42CHLXT7.js";
|
|
35
|
+
import "./chunk-TY75OOIQ.js";
|
|
36
|
+
import "./chunk-LDSWHSRX.js";
|
|
37
|
+
export {
|
|
38
|
+
array_chunk,
|
|
39
|
+
array_column,
|
|
40
|
+
array_count_values,
|
|
41
|
+
array_diff,
|
|
42
|
+
array_filter,
|
|
43
|
+
array_flip,
|
|
44
|
+
array_intersect,
|
|
45
|
+
array_key_exists,
|
|
46
|
+
array_keys,
|
|
47
|
+
array_map,
|
|
48
|
+
array_merge,
|
|
49
|
+
array_pop,
|
|
50
|
+
array_product,
|
|
51
|
+
array_push,
|
|
52
|
+
array_rand,
|
|
53
|
+
array_reduce,
|
|
54
|
+
array_reverse,
|
|
55
|
+
array_search,
|
|
56
|
+
array_shift,
|
|
57
|
+
array_slice,
|
|
58
|
+
array_splice,
|
|
59
|
+
array_sum,
|
|
60
|
+
array_unique,
|
|
61
|
+
array_unshift,
|
|
62
|
+
php_array,
|
|
63
|
+
range,
|
|
64
|
+
rsort,
|
|
65
|
+
shuffle,
|
|
66
|
+
sort,
|
|
67
|
+
uasort,
|
|
68
|
+
uksort,
|
|
69
|
+
usort
|
|
70
|
+
};
|