@catbee/utils 2.0.0-next.0 → 2.0.0-next.1
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 +52 -16
- package/array/index.cjs +180 -71
- package/array/index.d.ts +293 -1
- package/array/index.mjs +171 -72
- package/async/index.cjs +92 -36
- package/async/index.d.ts +275 -1
- package/async/index.mjs +92 -36
- package/cache/index.cjs +1 -1
- package/cache/index.d.ts +155 -1
- package/cache/index.mjs +2 -2
- package/config/index.cjs +78 -64
- package/config/index.d.ts +64 -2
- package/config/index.mjs +76 -64
- package/context-store/index.d.ts +192 -1
- package/crypto/index.d.ts +163 -1
- package/date/index.cjs +46 -1
- package/date/index.d.ts +190 -1
- package/date/index.mjs +45 -2
- package/decorators/index.cjs +1156 -18
- package/decorators/index.d.ts +684 -1
- package/decorators/index.mjs +1156 -18
- package/dir/index.cjs +4 -3
- package/dir/index.d.ts +195 -1
- package/dir/index.mjs +4 -3
- package/env/index.cjs +10 -26
- package/env/index.d.ts +379 -1
- package/env/index.mjs +10 -26
- package/exception/index.d.ts +232 -1
- package/fs/index.cjs +70 -36
- package/fs/index.d.ts +205 -1
- package/fs/index.mjs +64 -34
- package/http-status-codes/index.d.ts +267 -1
- package/id/index.d.ts +37 -1
- package/index.cjs +3 -3
- package/index.d.ts +1 -1
- package/index.mjs +1 -1
- package/logger/index.cjs +11 -11
- package/logger/index.d.ts +189 -1
- package/logger/index.mjs +12 -12
- package/middleware/index.d.ts +103 -1
- package/obj/index.cjs +150 -162
- package/obj/index.d.ts +136 -1
- package/obj/index.mjs +150 -162
- package/package.json +11 -11
- package/performance/index.cjs +2 -2
- package/performance/index.d.ts +138 -1
- package/performance/index.mjs +2 -2
- package/request/index.cjs +1 -1
- package/request/index.d.ts +241 -2
- package/request/index.mjs +1 -1
- package/response/index.d.ts +318 -2
- package/server/index.cjs +27 -23
- package/server/index.d.ts +785 -4
- package/server/index.mjs +28 -23
- package/stream/index.d.ts +90 -1
- package/string/index.d.ts +102 -1
- package/type/index.cjs +1 -1
- package/type/index.d.ts +107 -1
- package/type/index.mjs +1 -1
- package/types/index.d.ts +774 -4
- package/url/index.cjs +2 -4
- package/url/index.d.ts +142 -1
- package/url/index.mjs +2 -4
- package/{validate → validation}/index.cjs +89 -42
- package/{validate/validate.utils.d.ts → validation/index.d.ts} +32 -23
- package/{validate → validation}/index.mjs +85 -42
- package/array/array.utils.d.ts +0 -191
- package/async/async.utils.d.ts +0 -296
- package/cache/cache.utils.d.ts +0 -176
- package/config/config.d.ts +0 -57
- package/context-store/context-store.utils.d.ts +0 -212
- package/crypto/crypto.utils.d.ts +0 -183
- package/date/date.utils.d.ts +0 -190
- package/decorators/decorators.utils.d.ts +0 -705
- package/dir/dir.utils.d.ts +0 -216
- package/env/env.utils.d.ts +0 -400
- package/exception/exception.utils.d.ts +0 -253
- package/fs/fs.utils.d.ts +0 -196
- package/http-status-codes/http-status-codes.d.ts +0 -289
- package/id/id.utils.d.ts +0 -59
- package/logger/logger.utils.d.ts +0 -210
- package/middleware/middleware.utils.d.ts +0 -123
- package/obj/obj.utils.d.ts +0 -156
- package/performance/performance.utils.d.ts +0 -159
- package/request/request.utils.d.ts +0 -109
- package/response/response.utils.d.ts +0 -186
- package/server/server.builder.d.ts +0 -531
- package/server/server.d.ts +0 -303
- package/stream/stream.utils.d.ts +0 -111
- package/string/string.utils.d.ts +0 -124
- package/type/type.utils.d.ts +0 -129
- package/types/api-response.d.ts +0 -175
- package/types/common.d.ts +0 -148
- package/types/config.d.ts +0 -88
- package/types/server.d.ts +0 -291
- package/url/url.utils.d.ts +0 -164
- package/validate/index.d.ts +0 -25
|
@@ -22,25 +22,37 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import net from 'net';
|
|
26
|
+
|
|
25
27
|
var __defProp = Object.defineProperty;
|
|
26
28
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
var PORT_REGEX = /^[0-9]{1,5}$/;
|
|
30
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
31
|
+
var PHONE_ALLOWED_CHARS_REGEX = /^[+]?[0-9\s().-]+$/;
|
|
32
|
+
var ALPHANUMERIC_REGEX = /^[A-Za-z0-9]+$/;
|
|
33
|
+
var HEX_COLOR_REGEX = /^#([a-f0-9]{6}|[a-f0-9]{3})$/i;
|
|
34
|
+
var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
35
|
+
var BASE64_REGEX = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
|
|
36
|
+
var DOT_ATOM_REGEX = /^[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*$/;
|
|
37
|
+
var QUOTED_LOCAL_REGEX = /^"([\s\x21\x23-\x5B\x5D-\x7E]|\\[\x20-\x7E])*"$/;
|
|
38
|
+
var TLD_REGEX = /^[A-Za-z]{2,63}$/;
|
|
29
39
|
function isPort(value) {
|
|
30
|
-
|
|
40
|
+
if (typeof value === "number") return Number.isInteger(value) && value > 0 && value <= 65535;
|
|
41
|
+
if (!value || typeof value !== "string") return false;
|
|
42
|
+
const str = value.trim();
|
|
43
|
+
if (!PORT_REGEX.test(str)) return false;
|
|
44
|
+
const port = Number(str);
|
|
31
45
|
return Number.isInteger(port) && port > 0 && port <= 65535;
|
|
32
46
|
}
|
|
33
47
|
__name(isPort, "isPort");
|
|
34
48
|
function isEmail(str) {
|
|
35
|
-
if (typeof str !== "string" || str.length > 254) return false;
|
|
49
|
+
if (!str || typeof str !== "string" || str.length > 254) return false;
|
|
36
50
|
const atIndex = str.indexOf("@");
|
|
37
51
|
if (atIndex === -1 || atIndex !== str.lastIndexOf("@")) return false;
|
|
38
52
|
const local = str.slice(0, atIndex);
|
|
39
53
|
const domain = str.slice(atIndex + 1);
|
|
40
54
|
if (!local || !domain) return false;
|
|
41
|
-
|
|
42
|
-
const quotedLocal = /^"([\s\x21\x23-\x5B\x5D-\x7E]|\\[\x20-\x7E])*"$/;
|
|
43
|
-
if (!dotAtom.test(local) && !quotedLocal.test(local)) return false;
|
|
55
|
+
if (!DOT_ATOM_REGEX.test(local) && !QUOTED_LOCAL_REGEX.test(local)) return false;
|
|
44
56
|
if (domain.includes("..")) return false;
|
|
45
57
|
const labels = domain.split(".");
|
|
46
58
|
if (labels.some((l) => !l.length)) return false;
|
|
@@ -51,60 +63,74 @@ function isEmail(str) {
|
|
|
51
63
|
if (label.startsWith("-") || label.endsWith("-")) return false;
|
|
52
64
|
}
|
|
53
65
|
const tld = labels[labels.length - 1];
|
|
54
|
-
if (
|
|
66
|
+
if (!TLD_REGEX.test(tld)) return false;
|
|
55
67
|
return true;
|
|
56
68
|
}
|
|
57
69
|
__name(isEmail, "isEmail");
|
|
58
70
|
function isUUID(str) {
|
|
59
|
-
return
|
|
71
|
+
return UUID_REGEX.test(str);
|
|
60
72
|
}
|
|
61
73
|
__name(isUUID, "isUUID");
|
|
62
|
-
function isURL(str
|
|
74
|
+
function isURL(str, allowedProtocols = [
|
|
75
|
+
"http",
|
|
76
|
+
"https",
|
|
77
|
+
"ws",
|
|
78
|
+
"wss"
|
|
79
|
+
]) {
|
|
80
|
+
if (!str || typeof str !== "string") return false;
|
|
63
81
|
try {
|
|
64
|
-
new URL(str);
|
|
65
|
-
return
|
|
82
|
+
const url = new URL(str);
|
|
83
|
+
return allowedProtocols.includes(url.protocol.replace(":", ""));
|
|
66
84
|
} catch {
|
|
67
85
|
return false;
|
|
68
86
|
}
|
|
69
87
|
}
|
|
70
88
|
__name(isURL, "isURL");
|
|
71
89
|
function isPhone(str) {
|
|
72
|
-
if (typeof str !== "string") return false;
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
return
|
|
90
|
+
if (!str || typeof str !== "string") return false;
|
|
91
|
+
const digits = str.replace(/\D/g, "");
|
|
92
|
+
if (digits.length < 6 || digits.length > 15) return false;
|
|
93
|
+
return PHONE_ALLOWED_CHARS_REGEX.test(str);
|
|
76
94
|
}
|
|
77
95
|
__name(isPhone, "isPhone");
|
|
78
96
|
function isAlphanumeric(str) {
|
|
79
|
-
|
|
97
|
+
if (!str || typeof str !== "string") return false;
|
|
98
|
+
return ALPHANUMERIC_REGEX.test(str);
|
|
80
99
|
}
|
|
81
100
|
__name(isAlphanumeric, "isAlphanumeric");
|
|
82
101
|
function isNumeric(value) {
|
|
83
|
-
if (typeof value === "
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
103
|
+
if (!value || typeof value !== "string") return false;
|
|
104
|
+
const str = value.trim();
|
|
105
|
+
if (str === "" || str.length > 16) return false;
|
|
106
|
+
const num = Number(str);
|
|
107
|
+
return Number.isFinite(num);
|
|
86
108
|
}
|
|
87
109
|
__name(isNumeric, "isNumeric");
|
|
88
110
|
function isHexColor(str) {
|
|
89
|
-
|
|
111
|
+
if (!str || typeof str !== "string") return false;
|
|
112
|
+
return HEX_COLOR_REGEX.test(str);
|
|
90
113
|
}
|
|
91
114
|
__name(isHexColor, "isHexColor");
|
|
92
115
|
function isISODate(str) {
|
|
93
|
-
|
|
94
|
-
if (!
|
|
116
|
+
if (!str || typeof str !== "string") return false;
|
|
117
|
+
if (!ISO_DATE_REGEX.test(str)) return false;
|
|
95
118
|
const date = new Date(str);
|
|
96
|
-
return !isNaN(date.getTime())
|
|
119
|
+
return !Number.isNaN(date.getTime());
|
|
97
120
|
}
|
|
98
121
|
__name(isISODate, "isISODate");
|
|
99
122
|
function isLengthBetween(str, min, max) {
|
|
123
|
+
if (typeof str !== "string") return false;
|
|
100
124
|
return str.length >= min && str.length <= max;
|
|
101
125
|
}
|
|
102
126
|
__name(isLengthBetween, "isLengthBetween");
|
|
103
127
|
function isNumberBetween(value, min, max) {
|
|
128
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return false;
|
|
104
129
|
return value >= min && value <= max;
|
|
105
130
|
}
|
|
106
131
|
__name(isNumberBetween, "isNumberBetween");
|
|
107
132
|
function isAlpha(str) {
|
|
133
|
+
if (!str || typeof str !== "string") return false;
|
|
108
134
|
return /^[a-zA-Z]+$/.test(str);
|
|
109
135
|
}
|
|
110
136
|
__name(isAlpha, "isAlpha");
|
|
@@ -118,36 +144,43 @@ function isStrongPassword(str) {
|
|
|
118
144
|
}
|
|
119
145
|
__name(isStrongPassword, "isStrongPassword");
|
|
120
146
|
function isIPv4(str) {
|
|
147
|
+
if (!str || typeof str !== "string") return false;
|
|
121
148
|
const parts = str.split(".");
|
|
122
149
|
if (parts.length !== 4) return false;
|
|
123
|
-
return parts.every((
|
|
124
|
-
|
|
125
|
-
|
|
150
|
+
return parts.every((p) => {
|
|
151
|
+
if (p.length > 3 || p.startsWith("0") && p.length > 1) return false;
|
|
152
|
+
const n = Number(p);
|
|
153
|
+
return Number.isInteger(n) && n >= 0 && n <= 255;
|
|
126
154
|
});
|
|
127
155
|
}
|
|
128
156
|
__name(isIPv4, "isIPv4");
|
|
129
157
|
function isIPv6(str) {
|
|
130
|
-
|
|
158
|
+
if (!str || typeof str !== "string" || str.length > 45) return false;
|
|
159
|
+
try {
|
|
160
|
+
return net.isIP(str) === 6;
|
|
161
|
+
} catch {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
131
164
|
}
|
|
132
165
|
__name(isIPv6, "isIPv6");
|
|
133
166
|
function isCreditCard(str) {
|
|
134
|
-
|
|
135
|
-
|
|
167
|
+
if (!str || typeof str !== "string") return false;
|
|
168
|
+
const s = str.replace(/\D/g, "");
|
|
169
|
+
if (s.length < 13 || s.length > 19) return false;
|
|
136
170
|
let sum = 0;
|
|
137
|
-
let
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (digit > 9) digit -= 9;
|
|
171
|
+
for (let i = 0, dbl = false; i < s.length; i++, dbl = !dbl) {
|
|
172
|
+
let d = s.charCodeAt(s.length - 1 - i) - 48;
|
|
173
|
+
if (dbl) {
|
|
174
|
+
d *= 2;
|
|
175
|
+
if (d > 9) d -= 9;
|
|
143
176
|
}
|
|
144
|
-
sum +=
|
|
145
|
-
shouldDouble = !shouldDouble;
|
|
177
|
+
sum += d;
|
|
146
178
|
}
|
|
147
179
|
return sum % 10 === 0;
|
|
148
180
|
}
|
|
149
181
|
__name(isCreditCard, "isCreditCard");
|
|
150
182
|
function isValidJSON(str) {
|
|
183
|
+
if (!str || typeof str !== "string") return false;
|
|
151
184
|
try {
|
|
152
185
|
JSON.parse(str);
|
|
153
186
|
return true;
|
|
@@ -162,26 +195,36 @@ function isArray(value, itemGuard) {
|
|
|
162
195
|
}
|
|
163
196
|
__name(isArray, "isArray");
|
|
164
197
|
function isBase64(str) {
|
|
165
|
-
|
|
198
|
+
if (!str || typeof str !== "string") return false;
|
|
199
|
+
return BASE64_REGEX.test(str);
|
|
166
200
|
}
|
|
167
201
|
__name(isBase64, "isBase64");
|
|
168
202
|
function hasRequiredProps(obj, requiredProps) {
|
|
169
|
-
|
|
203
|
+
if (!obj || typeof obj !== "object") return false;
|
|
204
|
+
return requiredProps.every((prop) => Object.prototype.hasOwnProperty.call(obj, prop) && obj[prop] != null);
|
|
170
205
|
}
|
|
171
206
|
__name(hasRequiredProps, "hasRequiredProps");
|
|
172
207
|
function isDateInRange(date, minDate, maxDate) {
|
|
173
|
-
if (!(date instanceof Date) ||
|
|
208
|
+
if (!(date instanceof Date) || !Number.isFinite(date.getTime())) return false;
|
|
174
209
|
if (minDate && date < minDate) return false;
|
|
175
210
|
if (maxDate && date > maxDate) return false;
|
|
176
211
|
return true;
|
|
177
212
|
}
|
|
178
213
|
__name(isDateInRange, "isDateInRange");
|
|
179
214
|
function matchesPattern(str, pattern) {
|
|
215
|
+
if (typeof str !== "string") return false;
|
|
180
216
|
return pattern.test(str);
|
|
181
217
|
}
|
|
182
218
|
__name(matchesPattern, "matchesPattern");
|
|
183
219
|
function validateAll(value, validators) {
|
|
184
|
-
|
|
220
|
+
if (!Array.isArray(validators)) return false;
|
|
221
|
+
return validators.every((fn) => {
|
|
222
|
+
try {
|
|
223
|
+
return fn(value);
|
|
224
|
+
} catch {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
185
228
|
}
|
|
186
229
|
__name(validateAll, "validateAll");
|
|
187
230
|
|
package/array/array.utils.d.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Splits an array into chunks of the specified size.
|
|
27
|
-
*
|
|
28
|
-
* @template T The type of array elements.
|
|
29
|
-
* @param {T[]} array - The array to split into chunks.
|
|
30
|
-
* @param {number} size - The number of elements per chunk.
|
|
31
|
-
* @returns {T[][]} A new array containing chunked arrays.
|
|
32
|
-
* @throws {TypeError} If array is not an array.
|
|
33
|
-
* @throws {Error} If chunk size is not a positive integer.
|
|
34
|
-
*/
|
|
35
|
-
export declare function chunk<T>(array: readonly T[], size: number): T[][];
|
|
36
|
-
/**
|
|
37
|
-
* Removes duplicate values from an array.
|
|
38
|
-
* Optionally enforces uniqueness by a key function.
|
|
39
|
-
*
|
|
40
|
-
* @template T The type of array elements.
|
|
41
|
-
* @param {T[]} array - The input array.
|
|
42
|
-
* @param {(item: T) => unknown} [keyFn] - Optional function to determine uniqueness by key.
|
|
43
|
-
* @returns {T[]} A new array with unique values.
|
|
44
|
-
*/
|
|
45
|
-
export declare function unique<T>(array: readonly T[], keyFn?: (item: T) => unknown): T[];
|
|
46
|
-
/**
|
|
47
|
-
* Deeply flattens a nested array to a single-level array.
|
|
48
|
-
*
|
|
49
|
-
* @template T The leaf type of array elements.
|
|
50
|
-
* @param {any[]} array - The (possibly deeply nested) input array.
|
|
51
|
-
* @returns {T[]} A deeply flattened array.
|
|
52
|
-
*/
|
|
53
|
-
export declare function flattenDeep<T>(array: unknown[]): T[];
|
|
54
|
-
/**
|
|
55
|
-
* Returns a random element from an array, or undefined if empty.
|
|
56
|
-
*
|
|
57
|
-
* @template T The type of array elements.
|
|
58
|
-
* @param {T[]} array - The input array.
|
|
59
|
-
* @returns {T | undefined} A randomly selected item, or undefined if array is empty or not an array.
|
|
60
|
-
*/
|
|
61
|
-
export declare function random<T>(array: readonly T[]): T | undefined;
|
|
62
|
-
/**
|
|
63
|
-
* Groups items in an array by a key or key function.
|
|
64
|
-
*
|
|
65
|
-
* @template T The type of array elements.
|
|
66
|
-
* @overload
|
|
67
|
-
* @param {T[]} array - The array to group.
|
|
68
|
-
* @param {keyof T} key - Property key to group by.
|
|
69
|
-
* @returns {Record<string, T[]>}
|
|
70
|
-
* @overload
|
|
71
|
-
* @param {T[]} array - The array to group.
|
|
72
|
-
* @param {(item: T) => string | number | symbol} keyFn - Function to generate group key from item.
|
|
73
|
-
* @returns {Record<K, T[]>}
|
|
74
|
-
* @param {T[]} array - The array to group.
|
|
75
|
-
* @param {keyof T | ((item: T) => string | number | symbol)} keyOrFn - Property key or key-generating function.
|
|
76
|
-
* @returns {Record<string | number | symbol, T[]>} An object mapping group keys to item arrays.
|
|
77
|
-
*/
|
|
78
|
-
export declare function groupBy<T>(array: T[], key: keyof T): Record<string, T[]>;
|
|
79
|
-
export declare function groupBy<T, K extends string | number | symbol>(array: T[], keyFn: (item: T) => K): Record<K, T[]>;
|
|
80
|
-
/**
|
|
81
|
-
* Shuffles an array using the Fisher-Yates algorithm.
|
|
82
|
-
*
|
|
83
|
-
* @template T The type of array elements.
|
|
84
|
-
* @param {T[]} array - The input array.
|
|
85
|
-
* @returns {T[]} A new shuffled array.
|
|
86
|
-
* @throws {TypeError} If array is not an array.
|
|
87
|
-
*/
|
|
88
|
-
export declare function shuffle<T>(array: T[]): T[];
|
|
89
|
-
/**
|
|
90
|
-
* Returns an array of property values from an array of objects.
|
|
91
|
-
*
|
|
92
|
-
* @template T The type of array elements.
|
|
93
|
-
* @template K The object property to pluck.
|
|
94
|
-
* @param {T[]} array - The input array.
|
|
95
|
-
* @param {K} key - The property name to pluck.
|
|
96
|
-
* @returns {T[K][]} Array of property values.
|
|
97
|
-
*/
|
|
98
|
-
export declare function pluck<T, K extends keyof T>(array: readonly T[], key: K): T[K][];
|
|
99
|
-
/**
|
|
100
|
-
* Returns values in array A that are not in array B.
|
|
101
|
-
*
|
|
102
|
-
* @template T The type of array elements.
|
|
103
|
-
* @param {T[]} a - First array.
|
|
104
|
-
* @param {T[]} b - Second array.
|
|
105
|
-
* @returns {T[]} Elements in A that are not in B.
|
|
106
|
-
*/
|
|
107
|
-
export declare function difference<T>(a: readonly T[], b: readonly T[]): T[];
|
|
108
|
-
/**
|
|
109
|
-
* Returns common values between arrays A and B.
|
|
110
|
-
*
|
|
111
|
-
* @template T The type of array elements.
|
|
112
|
-
* @param {T[]} a - First array.
|
|
113
|
-
* @param {T[]} b - Second array.
|
|
114
|
-
* @returns {T[]} Elements that exist in both arrays.
|
|
115
|
-
*/
|
|
116
|
-
export declare function intersect<T>(a: readonly T[], b: readonly T[]): T[];
|
|
117
|
-
/**
|
|
118
|
-
* Sorts an array of objects by a nested key using Merge Sort (O(n log n)).
|
|
119
|
-
* Missing/undefined keys are sorted to the "end" (asc) or "start" (desc).
|
|
120
|
-
*
|
|
121
|
-
* @template T The type of array elements (objects).
|
|
122
|
-
* @param {T[]} array - Array of objects to sort.
|
|
123
|
-
* @param {string | ((item: T) => any)} key - Dot-notated key (e.g., "profile.age") or function.
|
|
124
|
-
* @param {"asc" | "desc"} [direction="asc"] - Sort direction: 'asc' or 'desc'.
|
|
125
|
-
* @returns {T[]} A new sorted array.
|
|
126
|
-
* @throws {TypeError} If array is not an array.
|
|
127
|
-
*/
|
|
128
|
-
export declare function mergeSort<T>(array: T[], key: string | ((item: T) => any), direction?: 'asc' | 'desc'): T[];
|
|
129
|
-
/**
|
|
130
|
-
* Combines multiple arrays into a single array of grouped elements.
|
|
131
|
-
* Output array length equals the length of the shortest input array.
|
|
132
|
-
*
|
|
133
|
-
* @example zip([1, 2], ['a', 'b']) => [[1, 'a'], [2, 'b']]
|
|
134
|
-
* @param {...Array<T>[]} arrays - Two or more arrays to zip together.
|
|
135
|
-
* @returns {Array<T[]>} Array of grouped elements.
|
|
136
|
-
*/
|
|
137
|
-
export declare function zip<T>(...arrays: ReadonlyArray<T>[]): T[][];
|
|
138
|
-
/**
|
|
139
|
-
* Splits an array into two arrays based on a predicate function.
|
|
140
|
-
*
|
|
141
|
-
* @template T The type of array elements.
|
|
142
|
-
* @param {T[]} array - The input array.
|
|
143
|
-
* @param {(item: T, index: number, array: T[]) => boolean} predicate - Function to test each element.
|
|
144
|
-
* @returns {[T[], T[]]} A tuple of two arrays: [matched, unmatched].
|
|
145
|
-
*/
|
|
146
|
-
export declare function partition<T>(array: T[], predicate: (item: T, index: number, array: T[]) => boolean): [T[], T[]];
|
|
147
|
-
/**
|
|
148
|
-
* Generates an array of numbers within a specified range.
|
|
149
|
-
*
|
|
150
|
-
* @param {number} start - Start of range (inclusive).
|
|
151
|
-
* @param {number} end - End of range (exclusive).
|
|
152
|
-
* @param {number} [step=1] - Step between numbers.
|
|
153
|
-
* @returns {number[]} Array of numbers in range.
|
|
154
|
-
*/
|
|
155
|
-
export declare function range(start: number, end: number, step?: number): number[];
|
|
156
|
-
/**
|
|
157
|
-
* Returns the first n elements of an array.
|
|
158
|
-
*
|
|
159
|
-
* @template T The type of array elements.
|
|
160
|
-
* @param {T[]} array - The input array.
|
|
161
|
-
* @param {number} [n=1] - Number of elements to take.
|
|
162
|
-
* @returns {T[]} New array with first n elements.
|
|
163
|
-
*/
|
|
164
|
-
export declare function take<T>(array: T[], n?: number): T[];
|
|
165
|
-
/**
|
|
166
|
-
* Takes elements from the array while predicate returns true.
|
|
167
|
-
*
|
|
168
|
-
* @template T The type of array elements.
|
|
169
|
-
* @param {T[]} array - The input array.
|
|
170
|
-
* @param {(item: T, index: number) => boolean} predicate - Function to test each element.
|
|
171
|
-
* @returns {T[]} New array with taken elements.
|
|
172
|
-
*/
|
|
173
|
-
export declare function takeWhile<T>(array: T[], predicate: (item: T, index: number) => boolean): T[];
|
|
174
|
-
/**
|
|
175
|
-
* Removes all falsy values from an array.
|
|
176
|
-
* False, null, 0, "", undefined, and NaN are falsy.
|
|
177
|
-
*
|
|
178
|
-
* @template T The type of array elements.
|
|
179
|
-
* @param {T[]} array - The input array.
|
|
180
|
-
* @returns {NonNullable<T>[]} New array with falsy values removed.
|
|
181
|
-
*/
|
|
182
|
-
export declare function compact<T>(array: T[]): NonNullable<T>[];
|
|
183
|
-
/**
|
|
184
|
-
* Counts array elements by a key function.
|
|
185
|
-
*
|
|
186
|
-
* @template T The type of array elements.
|
|
187
|
-
* @param {T[]} array - The input array.
|
|
188
|
-
* @param {(item: T) => string | number | symbol} keyFn - Function to generate count key.
|
|
189
|
-
* @returns {Record<string, number>} Object with counts by key.
|
|
190
|
-
*/
|
|
191
|
-
export declare function countBy<T>(array: T[], keyFn: (item: T) => string | number | symbol): Record<string, number>;
|