@catbee/utils 1.0.5 → 2.0.0-next.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 +1 -1
- package/README.md +27 -27
- package/array/array.utils.d.ts +191 -0
- package/array/index.cjs +246 -0
- package/array/index.d.ts +25 -0
- package/array/index.mjs +228 -0
- package/async/async.utils.d.ts +296 -0
- package/async/index.cjs +428 -0
- package/async/index.d.ts +25 -0
- package/async/index.mjs +407 -0
- package/cache/cache.utils.d.ts +176 -0
- package/cache/index.cjs +292 -0
- package/cache/index.d.ts +25 -0
- package/cache/index.mjs +290 -0
- package/config/config.d.ts +57 -0
- package/config/index.cjs +136 -0
- package/config/index.d.ts +26 -0
- package/config/index.mjs +131 -0
- package/context-store/context-store.utils.d.ts +212 -0
- package/context-store/index.cjs +267 -0
- package/context-store/index.d.ts +25 -0
- package/context-store/index.mjs +261 -0
- package/crypto/crypto.utils.d.ts +183 -0
- package/crypto/index.cjs +182 -0
- package/crypto/index.d.ts +25 -0
- package/crypto/index.mjs +166 -0
- package/date/date.utils.d.ts +190 -0
- package/date/index.cjs +295 -0
- package/date/index.d.ts +25 -0
- package/date/index.mjs +283 -0
- package/decorators/decorators.utils.d.ts +705 -0
- package/decorators/index.cjs +913 -0
- package/decorators/index.d.ts +25 -0
- package/decorators/index.mjs +872 -0
- package/dir/dir.utils.d.ts +216 -0
- package/dir/index.cjs +416 -0
- package/dir/index.d.ts +25 -0
- package/dir/index.mjs +389 -0
- package/env/env.utils.d.ts +400 -0
- package/env/index.cjs +761 -0
- package/env/index.d.ts +25 -0
- package/env/index.mjs +758 -0
- package/exception/exception.utils.d.ts +253 -0
- package/exception/index.cjs +362 -0
- package/exception/index.d.ts +25 -0
- package/exception/index.mjs +338 -0
- package/fs/fs.utils.d.ts +196 -0
- package/fs/index.cjs +253 -0
- package/fs/index.d.ts +25 -0
- package/fs/index.mjs +228 -0
- package/http-status-codes/http-status-codes.d.ts +289 -0
- package/http-status-codes/index.cjs +96 -0
- package/http-status-codes/index.d.ts +25 -0
- package/http-status-codes/index.mjs +94 -0
- package/id/id.utils.d.ts +59 -0
- package/id/index.cjs +62 -0
- package/id/index.d.ts +25 -0
- package/id/index.mjs +56 -0
- package/index.cjs +218 -0
- package/index.d.ts +51 -0
- package/index.mjs +51 -0
- package/logger/index.cjs +334 -0
- package/logger/index.d.ts +25 -0
- package/logger/index.mjs +313 -0
- package/logger/logger.utils.d.ts +210 -0
- package/middleware/index.cjs +177 -0
- package/middleware/index.d.ts +25 -0
- package/middleware/index.mjs +170 -0
- package/middleware/middleware.utils.d.ts +123 -0
- package/obj/index.cjs +317 -0
- package/obj/index.d.ts +25 -0
- package/obj/index.mjs +301 -0
- package/obj/obj.utils.d.ts +156 -0
- package/package.json +172 -20
- package/performance/index.cjs +231 -0
- package/performance/index.d.ts +25 -0
- package/performance/index.mjs +225 -0
- package/performance/performance.utils.d.ts +159 -0
- package/request/index.cjs +202 -0
- package/request/index.d.ts +26 -0
- package/request/index.mjs +194 -0
- package/request/request.utils.d.ts +109 -0
- package/response/index.cjs +234 -0
- package/response/index.d.ts +26 -0
- package/response/index.mjs +222 -0
- package/response/response.utils.d.ts +186 -0
- package/server/index.cjs +1627 -0
- package/server/index.d.ts +28 -0
- package/server/index.mjs +1617 -0
- package/server/server.builder.d.ts +531 -0
- package/server/server.d.ts +303 -0
- package/stream/index.cjs +151 -0
- package/stream/index.d.ts +25 -0
- package/stream/index.mjs +144 -0
- package/stream/stream.utils.d.ts +111 -0
- package/string/index.cjs +109 -0
- package/string/index.d.ts +25 -0
- package/string/index.mjs +95 -0
- package/string/string.utils.d.ts +124 -0
- package/type/index.cjs +129 -0
- package/type/index.d.ts +25 -0
- package/type/index.mjs +119 -0
- package/type/type.utils.d.ts +129 -0
- package/types/api-response.d.ts +175 -0
- package/types/common.d.ts +148 -0
- package/types/config.d.ts +88 -0
- package/types/index.cjs +34 -0
- package/types/index.d.ts +28 -0
- package/types/index.mjs +32 -0
- package/types/server.d.ts +291 -0
- package/url/index.cjs +201 -0
- package/url/index.d.ts +25 -0
- package/url/index.mjs +189 -0
- package/url/url.utils.d.ts +164 -0
- package/validate/index.cjs +212 -0
- package/validate/index.d.ts +25 -0
- package/validate/index.mjs +188 -0
- package/validate/validate.utils.d.ts +200 -0
- package/build/index.cjs +0 -7579
- package/build/index.d.ts +0 -5774
- package/build/index.mjs +0 -7274
package/obj/index.mjs
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
26
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
27
|
+
|
|
28
|
+
// src/obj/obj.utils.ts
|
|
29
|
+
function isObjEmpty(obj) {
|
|
30
|
+
return !!obj && typeof obj === "object" && Object.keys(obj).length === 0;
|
|
31
|
+
}
|
|
32
|
+
__name(isObjEmpty, "isObjEmpty");
|
|
33
|
+
function pick(obj, keys) {
|
|
34
|
+
return Object.fromEntries(keys.map((key) => [
|
|
35
|
+
key,
|
|
36
|
+
obj[key]
|
|
37
|
+
]));
|
|
38
|
+
}
|
|
39
|
+
__name(pick, "pick");
|
|
40
|
+
function omit(obj, keys) {
|
|
41
|
+
return Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key)));
|
|
42
|
+
}
|
|
43
|
+
__name(omit, "omit");
|
|
44
|
+
function deepObjMerge(target, ...sources) {
|
|
45
|
+
if (!sources.length) return target;
|
|
46
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
47
|
+
seen.set(target, target);
|
|
48
|
+
for (const s of sources) {
|
|
49
|
+
if (s && typeof s === "object") {
|
|
50
|
+
seen.set(s, target);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function deepClone2(value) {
|
|
54
|
+
if (value === null || typeof value !== "object") return value;
|
|
55
|
+
if (seen.has(value)) return seen.get(value);
|
|
56
|
+
if (value instanceof Date) {
|
|
57
|
+
return new Date(value.getTime());
|
|
58
|
+
}
|
|
59
|
+
if (Array.isArray(value)) {
|
|
60
|
+
const clone2 = [];
|
|
61
|
+
seen.set(value, clone2);
|
|
62
|
+
value.forEach((item, i) => clone2[i] = deepClone2(item));
|
|
63
|
+
return clone2;
|
|
64
|
+
}
|
|
65
|
+
if (value instanceof Set) {
|
|
66
|
+
const clone2 = /* @__PURE__ */ new Set();
|
|
67
|
+
seen.set(value, clone2);
|
|
68
|
+
value.forEach((item) => clone2.add(deepClone2(item)));
|
|
69
|
+
return clone2;
|
|
70
|
+
}
|
|
71
|
+
if (value instanceof Map) {
|
|
72
|
+
const clone2 = /* @__PURE__ */ new Map();
|
|
73
|
+
seen.set(value, clone2);
|
|
74
|
+
value.forEach((val, key) => clone2.set(key, deepClone2(val)));
|
|
75
|
+
return clone2;
|
|
76
|
+
}
|
|
77
|
+
if (value instanceof RegExp) {
|
|
78
|
+
return new RegExp(value.source, value.flags);
|
|
79
|
+
}
|
|
80
|
+
if (value instanceof ArrayBuffer) {
|
|
81
|
+
return value.slice(0);
|
|
82
|
+
}
|
|
83
|
+
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
|
|
84
|
+
const typed = value;
|
|
85
|
+
const ctor = typed.constructor;
|
|
86
|
+
const typedArrayCtors = [
|
|
87
|
+
Int8Array,
|
|
88
|
+
Uint8Array,
|
|
89
|
+
Uint8ClampedArray,
|
|
90
|
+
Int16Array,
|
|
91
|
+
Uint16Array,
|
|
92
|
+
Int32Array,
|
|
93
|
+
Uint32Array,
|
|
94
|
+
Float32Array,
|
|
95
|
+
Float64Array,
|
|
96
|
+
BigInt64Array,
|
|
97
|
+
BigUint64Array
|
|
98
|
+
].filter(Boolean);
|
|
99
|
+
const typedArrayCtorSet = new Set(typedArrayCtors);
|
|
100
|
+
if (typeof ctor === "function" && typedArrayCtorSet.has(ctor)) {
|
|
101
|
+
const buffer = typed.buffer && typeof typed.buffer.slice === "function" ? typed.buffer.slice(0) : typed.buffer;
|
|
102
|
+
const clone2 = new ctor(buffer, typed.byteOffset, typed.length);
|
|
103
|
+
seen.set(value, clone2);
|
|
104
|
+
return clone2;
|
|
105
|
+
} else if (typeof typed.slice === "function") {
|
|
106
|
+
const clone2 = typed.slice();
|
|
107
|
+
seen.set(value, clone2);
|
|
108
|
+
return clone2;
|
|
109
|
+
} else {
|
|
110
|
+
throw new Error("Cannot deep clone unknown TypedArray type: " + (typed && typed.constructor && typed.constructor.name));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const clone = Object.create(Object.getPrototypeOf(value));
|
|
114
|
+
seen.set(value, clone);
|
|
115
|
+
Reflect.ownKeys(value).forEach((key) => {
|
|
116
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
117
|
+
if (descriptor.get || descriptor.set) {
|
|
118
|
+
Object.defineProperty(clone, key, descriptor);
|
|
119
|
+
} else {
|
|
120
|
+
clone[key] = deepClone2(value[key]);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
return clone;
|
|
124
|
+
}
|
|
125
|
+
__name(deepClone2, "deepClone");
|
|
126
|
+
function mergeProp(target2, source, key) {
|
|
127
|
+
const targetValue = target2[key];
|
|
128
|
+
const sourceValue = source[key];
|
|
129
|
+
if (sourceValue === void 0) return;
|
|
130
|
+
if (sourceValue === null || typeof sourceValue !== "object") {
|
|
131
|
+
target2[key] = sourceValue;
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (Array.isArray(sourceValue)) {
|
|
135
|
+
target2[key] = deepClone2(sourceValue);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (sourceValue instanceof Date || sourceValue instanceof RegExp || sourceValue instanceof Set || sourceValue instanceof Map || sourceValue instanceof ArrayBuffer || ArrayBuffer.isView(sourceValue) && !(sourceValue instanceof DataView)) {
|
|
139
|
+
target2[key] = deepClone2(sourceValue);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
143
|
+
for (const k of Reflect.ownKeys(sourceValue)) {
|
|
144
|
+
mergeProp(targetValue, sourceValue, k);
|
|
145
|
+
}
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
target2[key] = deepClone2(sourceValue);
|
|
149
|
+
}
|
|
150
|
+
__name(mergeProp, "mergeProp");
|
|
151
|
+
for (const source of sources) {
|
|
152
|
+
if (source == null) continue;
|
|
153
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
154
|
+
mergeProp(target, source, key);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return target;
|
|
158
|
+
}
|
|
159
|
+
__name(deepObjMerge, "deepObjMerge");
|
|
160
|
+
function isPlainObject(value) {
|
|
161
|
+
if (typeof value !== "object" || value === null) return false;
|
|
162
|
+
if (Array.isArray(value)) return false;
|
|
163
|
+
const proto = Object.getPrototypeOf(value);
|
|
164
|
+
return proto === Object.prototype || proto === null;
|
|
165
|
+
}
|
|
166
|
+
__name(isPlainObject, "isPlainObject");
|
|
167
|
+
function flattenObject(obj, prefix = "") {
|
|
168
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
169
|
+
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
170
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
171
|
+
Object.assign(acc, flattenObject(value, newKey));
|
|
172
|
+
} else {
|
|
173
|
+
acc[newKey] = value;
|
|
174
|
+
}
|
|
175
|
+
return acc;
|
|
176
|
+
}, {});
|
|
177
|
+
}
|
|
178
|
+
__name(flattenObject, "flattenObject");
|
|
179
|
+
function getValueByPath(obj, path) {
|
|
180
|
+
if (!obj || typeof obj !== "object") return void 0;
|
|
181
|
+
const parts = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
182
|
+
return parts.reduce((acc, key) => acc?.[key], obj);
|
|
183
|
+
}
|
|
184
|
+
__name(getValueByPath, "getValueByPath");
|
|
185
|
+
function setValueByPath(obj, path, value) {
|
|
186
|
+
if (!obj || typeof obj !== "object") return obj;
|
|
187
|
+
const parts = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
|
|
188
|
+
if (parts.length === 0) return obj;
|
|
189
|
+
const forbiddenKeys = /* @__PURE__ */ new Set([
|
|
190
|
+
"__proto__",
|
|
191
|
+
"prototype",
|
|
192
|
+
"constructor"
|
|
193
|
+
]);
|
|
194
|
+
let current = obj;
|
|
195
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
196
|
+
const key = parts[i];
|
|
197
|
+
if (forbiddenKeys.has(key)) {
|
|
198
|
+
return obj;
|
|
199
|
+
}
|
|
200
|
+
const nextKey = parts[i + 1];
|
|
201
|
+
const isArrayIndex = !isNaN(Number(nextKey));
|
|
202
|
+
if (current[key] === void 0) {
|
|
203
|
+
current[key] = isArrayIndex ? [] : /* @__PURE__ */ Object.create(null);
|
|
204
|
+
} else if (typeof current[key] !== "object" || current[key] === null) {
|
|
205
|
+
current[key] = isArrayIndex ? [] : /* @__PURE__ */ Object.create(null);
|
|
206
|
+
}
|
|
207
|
+
current = current[key];
|
|
208
|
+
}
|
|
209
|
+
const finalKey = parts[parts.length - 1];
|
|
210
|
+
if (forbiddenKeys.has(finalKey)) {
|
|
211
|
+
return obj;
|
|
212
|
+
}
|
|
213
|
+
current[finalKey] = value;
|
|
214
|
+
return obj;
|
|
215
|
+
}
|
|
216
|
+
__name(setValueByPath, "setValueByPath");
|
|
217
|
+
function isEqual(a, b) {
|
|
218
|
+
if (a === b) return true;
|
|
219
|
+
if (a == null || b == null || typeof a !== "object" || typeof b !== "object") {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (a instanceof Date && b instanceof Date) {
|
|
223
|
+
return a.getTime() === b.getTime();
|
|
224
|
+
}
|
|
225
|
+
if (a instanceof Date || b instanceof Date) {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
229
|
+
if (a.length !== b.length) return false;
|
|
230
|
+
for (let i = 0; i < a.length; i++) {
|
|
231
|
+
if (!isEqual(a[i], b[i])) return false;
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const keysA = Object.keys(a);
|
|
239
|
+
const keysB = Object.keys(b);
|
|
240
|
+
if (keysA.length !== keysB.length) return false;
|
|
241
|
+
return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]));
|
|
242
|
+
}
|
|
243
|
+
__name(isEqual, "isEqual");
|
|
244
|
+
function filterObject(obj, predicate) {
|
|
245
|
+
return Object.fromEntries(Object.entries(obj).filter(([key, value]) => predicate(value, key, obj)));
|
|
246
|
+
}
|
|
247
|
+
__name(filterObject, "filterObject");
|
|
248
|
+
function mapObject(obj, mapFn) {
|
|
249
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
|
|
250
|
+
key,
|
|
251
|
+
mapFn(value, key, obj)
|
|
252
|
+
]));
|
|
253
|
+
}
|
|
254
|
+
__name(mapObject, "mapObject");
|
|
255
|
+
function deepClone(value) {
|
|
256
|
+
try {
|
|
257
|
+
if (typeof globalThis.structuredClone === "function") {
|
|
258
|
+
return globalThis.structuredClone(value);
|
|
259
|
+
}
|
|
260
|
+
} catch (_) {
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
return JSON.parse(JSON.stringify(value));
|
|
264
|
+
} catch (_) {
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
__name(deepClone, "deepClone");
|
|
269
|
+
function deepFreeze(obj) {
|
|
270
|
+
Object.freeze(obj);
|
|
271
|
+
for (const prop of Object.getOwnPropertyNames(obj)) {
|
|
272
|
+
const value = obj[prop];
|
|
273
|
+
if (value !== null && typeof value === "object" && !Object.isFrozen(value)) {
|
|
274
|
+
deepFreeze(value);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return obj;
|
|
278
|
+
}
|
|
279
|
+
__name(deepFreeze, "deepFreeze");
|
|
280
|
+
function isObject(value) {
|
|
281
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
282
|
+
}
|
|
283
|
+
__name(isObject, "isObject");
|
|
284
|
+
function getAllPaths(obj, parentPath = "") {
|
|
285
|
+
if (!isObject(obj)) return [];
|
|
286
|
+
return Object.entries(obj).flatMap(([key, value]) => {
|
|
287
|
+
const currentPath = parentPath ? `${parentPath}.${key}` : key;
|
|
288
|
+
if (isObject(value)) {
|
|
289
|
+
return [
|
|
290
|
+
currentPath,
|
|
291
|
+
...getAllPaths(value, currentPath)
|
|
292
|
+
];
|
|
293
|
+
}
|
|
294
|
+
return [
|
|
295
|
+
currentPath
|
|
296
|
+
];
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
__name(getAllPaths, "getAllPaths");
|
|
300
|
+
|
|
301
|
+
export { deepClone, deepFreeze, deepObjMerge, filterObject, flattenObject, getAllPaths, getValueByPath, isEqual, isObjEmpty, isObject, isPlainObject, mapObject, omit, pick, setValueByPath };
|
|
@@ -0,0 +1,156 @@
|
|
|
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
|
+
* Checks whether the object has no own enumerable properties.
|
|
27
|
+
*
|
|
28
|
+
* @param {Record<any, any>} obj - The object to check.
|
|
29
|
+
* @returns {boolean} True if the object is empty, false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isObjEmpty(obj: Record<any, any>): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Returns a new object with only the specified keys picked.
|
|
34
|
+
*
|
|
35
|
+
* @template T
|
|
36
|
+
* @template K
|
|
37
|
+
* @param {T} obj - The source object.
|
|
38
|
+
* @param {K[]} keys - Keys to pick from the object.
|
|
39
|
+
* @returns {Pick<T, K>} New object with picked keys.
|
|
40
|
+
*/
|
|
41
|
+
export declare function pick<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
42
|
+
/**
|
|
43
|
+
* Returns a new object with the specified keys omitted.
|
|
44
|
+
*
|
|
45
|
+
* @template T
|
|
46
|
+
* @template K
|
|
47
|
+
* @param {T} obj - The source object.
|
|
48
|
+
* @param {K[]} keys - Keys to omit from the object.
|
|
49
|
+
* @returns {Omit<T, K>} New object without omitted keys.
|
|
50
|
+
*/
|
|
51
|
+
export declare function omit<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
52
|
+
/**
|
|
53
|
+
* Deeply merges multiple objects into the target object (mutates and returns the target object, not pure).
|
|
54
|
+
*
|
|
55
|
+
* @template T
|
|
56
|
+
* @param {T} target - The object to merge into (will be mutated).
|
|
57
|
+
* @param {...any[]} sources - The objects to merge from.
|
|
58
|
+
* @returns {T} The merged object (same as target).
|
|
59
|
+
*/
|
|
60
|
+
export declare function deepObjMerge<T extends object>(target: T, ...sources: any[]): T;
|
|
61
|
+
/**
|
|
62
|
+
* Checks if a value is a plain object (i.e., not an array, null, or a built-in object).
|
|
63
|
+
*
|
|
64
|
+
* @param value - The value to check.
|
|
65
|
+
* @returns True if the value is a plain object, false otherwise.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isPlainObject(value: any): value is Record<string, any>;
|
|
68
|
+
/**
|
|
69
|
+
* Flattens a nested object using dot notation for keys (e.g., `{a: {b: 1}}` → `{ "a.b": 1 }`).
|
|
70
|
+
*
|
|
71
|
+
* @template T
|
|
72
|
+
* @param {T} obj - The object to flatten.
|
|
73
|
+
* @param {string} [prefix=""] - Optional prefix for nested keys (used internally).
|
|
74
|
+
* @returns {Record<string, any>} A new object with flattened keys.
|
|
75
|
+
*/
|
|
76
|
+
export declare function flattenObject<T extends Record<string, any>>(obj: T, prefix?: string): Record<string, any>;
|
|
77
|
+
/**
|
|
78
|
+
* Safely gets the value of a deeply nested key in an object using dot/bracket notation path.
|
|
79
|
+
*
|
|
80
|
+
* @template T
|
|
81
|
+
* @param {T} obj - The object to extract from.
|
|
82
|
+
* @param {string} path - String path using dot and/or bracket notation (e.g., 'user.friends[0].name').
|
|
83
|
+
* @returns {any} The value at the given path, or undefined if not found.
|
|
84
|
+
*/
|
|
85
|
+
export declare function getValueByPath<T extends object>(obj: T, path: string): any;
|
|
86
|
+
/**
|
|
87
|
+
* Sets a value at a deeply nested key in an object using dot/bracket notation path.
|
|
88
|
+
* Secured against prototype pollution.
|
|
89
|
+
*
|
|
90
|
+
* @template T
|
|
91
|
+
* @param {T} obj - The object to modify.
|
|
92
|
+
* @param {string} path - Dot/bracket notation path (e.g., "user.friends[0].name").
|
|
93
|
+
* @param {any} value - Value to assign.
|
|
94
|
+
* @returns {T} The modified object.
|
|
95
|
+
*/
|
|
96
|
+
export declare function setValueByPath<T extends object>(obj: T, path: string, value: any): T;
|
|
97
|
+
/**
|
|
98
|
+
* Performs a deep equality check between two objects.
|
|
99
|
+
*
|
|
100
|
+
* @param {any} a - First value to compare.
|
|
101
|
+
* @param {any} b - Second value to compare.
|
|
102
|
+
* @returns {boolean} True if values are deeply equal.
|
|
103
|
+
*/
|
|
104
|
+
export declare function isEqual(a: any, b: any): boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Filters object properties based on a predicate function.
|
|
107
|
+
*
|
|
108
|
+
* @template T
|
|
109
|
+
* @param {T} obj - The source object.
|
|
110
|
+
* @param {(value: any, key: string, obj: T) => boolean} predicate - Filter function.
|
|
111
|
+
* @returns {Partial<T>} New object with filtered properties.
|
|
112
|
+
*/
|
|
113
|
+
export declare function filterObject<T extends object>(obj: T, predicate: (value: any, key: string, obj: T) => boolean): Partial<T>;
|
|
114
|
+
/**
|
|
115
|
+
* Maps object values to new values using a mapping function.
|
|
116
|
+
*
|
|
117
|
+
* @template T
|
|
118
|
+
* @template U
|
|
119
|
+
* @param {T} obj - The source object.
|
|
120
|
+
* @param {(value: any, key: string, obj: T) => U} mapFn - Mapping function.
|
|
121
|
+
* @returns {Record<keyof T, U>} New object with mapped values.
|
|
122
|
+
*/
|
|
123
|
+
export declare function mapObject<T extends object, U>(obj: T, mapFn: (value: any, key: string, obj: T) => U): Record<keyof T, U>;
|
|
124
|
+
/**
|
|
125
|
+
* Create a deep clone of a value. Uses structuredClone when available, falls back to JSON
|
|
126
|
+
* serialization as a best-effort fallback (may lose functions and special objects).
|
|
127
|
+
*
|
|
128
|
+
* @template T
|
|
129
|
+
* @param {T} value
|
|
130
|
+
* @returns {T}
|
|
131
|
+
*/
|
|
132
|
+
export declare function deepClone<T>(value: T): T;
|
|
133
|
+
/**
|
|
134
|
+
* Recursively freezes an object and all its properties.
|
|
135
|
+
* Makes an object immutable.
|
|
136
|
+
*
|
|
137
|
+
* @template T
|
|
138
|
+
* @param {T} obj - The object to freeze.
|
|
139
|
+
* @returns {Readonly<T>} The frozen object.
|
|
140
|
+
*/
|
|
141
|
+
export declare function deepFreeze<T extends object>(obj: T): Readonly<T>;
|
|
142
|
+
/**
|
|
143
|
+
* Safely checks if a value is an object (not null, not array).
|
|
144
|
+
*
|
|
145
|
+
* @param {unknown} value - Value to check.
|
|
146
|
+
* @returns {boolean} True if value is a non-null, non-array object.
|
|
147
|
+
*/
|
|
148
|
+
export declare function isObject(value: unknown): value is Record<string, any>;
|
|
149
|
+
/**
|
|
150
|
+
* Gets all paths in an object using dot notation.
|
|
151
|
+
*
|
|
152
|
+
* @param {Record<string, any>} obj - Object to analyze.
|
|
153
|
+
* @param {string} [parentPath=""] - Internal param for recursion.
|
|
154
|
+
* @returns {string[]} Array of all paths in dot notation.
|
|
155
|
+
*/
|
|
156
|
+
export declare function getAllPaths(obj: Record<string, any>, parentPath?: string): string[];
|
package/package.json
CHANGED
|
@@ -1,50 +1,202 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catbee/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-next.0",
|
|
4
4
|
"description": "A modular, production-grade utility toolkit for Node.js and TypeScript, designed for robust, scalable applications (including Express-based services). All utilities are tree-shakable and can be imported independently.",
|
|
5
|
-
"main": "build/index.cjs",
|
|
6
|
-
"module": "build/index.mjs",
|
|
7
|
-
"types": "build/index.d.ts",
|
|
8
5
|
"publishConfig": {
|
|
9
6
|
"access": "public"
|
|
10
7
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
"main": "index.cjs",
|
|
9
|
+
"module": "index.mjs",
|
|
10
|
+
"types": "index.d.ts",
|
|
11
|
+
"author": "Hari G <harig@catbee.in>",
|
|
12
|
+
"maintainers": [
|
|
13
|
+
"Hari G <harig@catbee.in>",
|
|
14
|
+
"Bavi R <bavithra@catbee.in>"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://catbee.in/docs/@catbee/utils/intro",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/catbee-technologies/catbee-utils.git"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/catbee-technologies/catbee-utils/issues"
|
|
14
23
|
},
|
|
15
24
|
"license": "MIT",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"pino": "^10.1.0",
|
|
27
|
+
"reflect-metadata": "^0.2.2"
|
|
28
|
+
},
|
|
16
29
|
"optionalDependencies": {
|
|
17
|
-
"@scalar/express-api-reference": "^0.8.
|
|
30
|
+
"@scalar/express-api-reference": "^0.8.30",
|
|
18
31
|
"abort-controller": "^3.0.0",
|
|
19
32
|
"compression": "^1.8.1",
|
|
20
33
|
"cookie-parser": "^1.4.7",
|
|
21
34
|
"cors": "^2.8.5",
|
|
22
|
-
"
|
|
35
|
+
"dotenv": "^17.2.3",
|
|
36
|
+
"express-rate-limit": "^8.2.1",
|
|
23
37
|
"helmet": "^8.1.0",
|
|
24
|
-
"pino": "^
|
|
25
|
-
"pino-pretty": "^13.1.1",
|
|
38
|
+
"pino-pretty": "^13.1.3",
|
|
26
39
|
"prom-client": "^15.1.3"
|
|
27
40
|
},
|
|
28
41
|
"peerDependencies": {
|
|
29
|
-
"express": "^5.1.0"
|
|
30
|
-
"reflect-metadata": "^0.2.2"
|
|
42
|
+
"express": "^5.1.0"
|
|
31
43
|
},
|
|
32
44
|
"peerDependenciesMeta": {
|
|
33
45
|
"express": {
|
|
34
46
|
"optional": true
|
|
35
|
-
},
|
|
36
|
-
"reflect-metadata": {
|
|
37
|
-
"optional": true
|
|
38
47
|
}
|
|
39
48
|
},
|
|
40
49
|
"engines": {
|
|
41
50
|
"node": ">=18.4"
|
|
42
51
|
},
|
|
43
52
|
"files": [
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
53
|
+
"**/*.mjs",
|
|
54
|
+
"**/*.cjs",
|
|
55
|
+
"**/*.d.ts",
|
|
56
|
+
"**/*.d.mts",
|
|
47
57
|
"LICENSE",
|
|
48
58
|
"README.md"
|
|
49
|
-
]
|
|
59
|
+
],
|
|
60
|
+
"exports": {
|
|
61
|
+
".": {
|
|
62
|
+
"import": "./index.mjs",
|
|
63
|
+
"require": "./index.cjs",
|
|
64
|
+
"types": "./index.d.ts"
|
|
65
|
+
},
|
|
66
|
+
"./array": {
|
|
67
|
+
"import": "./array/index.mjs",
|
|
68
|
+
"require": "./array/index.cjs",
|
|
69
|
+
"types": "./array/index.d.ts"
|
|
70
|
+
},
|
|
71
|
+
"./async": {
|
|
72
|
+
"import": "./async/index.mjs",
|
|
73
|
+
"require": "./async/index.cjs",
|
|
74
|
+
"types": "./async/index.d.ts"
|
|
75
|
+
},
|
|
76
|
+
"./cache": {
|
|
77
|
+
"import": "./cache/index.mjs",
|
|
78
|
+
"require": "./cache/index.cjs",
|
|
79
|
+
"types": "./cache/index.d.ts"
|
|
80
|
+
},
|
|
81
|
+
"./config": {
|
|
82
|
+
"import": "./config/index.mjs",
|
|
83
|
+
"require": "./config/index.cjs",
|
|
84
|
+
"types": "./config/index.d.ts"
|
|
85
|
+
},
|
|
86
|
+
"./context-store": {
|
|
87
|
+
"import": "./context-store/index.mjs",
|
|
88
|
+
"require": "./context-store/index.cjs",
|
|
89
|
+
"types": "./context-store/index.d.ts"
|
|
90
|
+
},
|
|
91
|
+
"./crypto": {
|
|
92
|
+
"import": "./crypto/index.mjs",
|
|
93
|
+
"require": "./crypto/index.cjs",
|
|
94
|
+
"types": "./crypto/index.d.ts"
|
|
95
|
+
},
|
|
96
|
+
"./date": {
|
|
97
|
+
"import": "./date/index.mjs",
|
|
98
|
+
"require": "./date/index.cjs",
|
|
99
|
+
"types": "./date/index.d.ts"
|
|
100
|
+
},
|
|
101
|
+
"./decorators": {
|
|
102
|
+
"import": "./decorators/index.mjs",
|
|
103
|
+
"require": "./decorators/index.cjs",
|
|
104
|
+
"types": "./decorators/index.d.ts"
|
|
105
|
+
},
|
|
106
|
+
"./dir": {
|
|
107
|
+
"import": "./dir/index.mjs",
|
|
108
|
+
"require": "./dir/index.cjs",
|
|
109
|
+
"types": "./dir/index.d.ts"
|
|
110
|
+
},
|
|
111
|
+
"./env": {
|
|
112
|
+
"import": "./env/index.mjs",
|
|
113
|
+
"require": "./env/index.cjs",
|
|
114
|
+
"types": "./env/index.d.ts"
|
|
115
|
+
},
|
|
116
|
+
"./exception": {
|
|
117
|
+
"import": "./exception/index.mjs",
|
|
118
|
+
"require": "./exception/index.cjs",
|
|
119
|
+
"types": "./exception/index.d.ts"
|
|
120
|
+
},
|
|
121
|
+
"./fs": {
|
|
122
|
+
"import": "./fs/index.mjs",
|
|
123
|
+
"require": "./fs/index.cjs",
|
|
124
|
+
"types": "./fs/index.d.ts"
|
|
125
|
+
},
|
|
126
|
+
"./http-status-codes": {
|
|
127
|
+
"import": "./http-status-codes/index.mjs",
|
|
128
|
+
"require": "./http-status-codes/index.cjs",
|
|
129
|
+
"types": "./http-status-codes/index.d.ts"
|
|
130
|
+
},
|
|
131
|
+
"./id": {
|
|
132
|
+
"import": "./id/index.mjs",
|
|
133
|
+
"require": "./id/index.cjs",
|
|
134
|
+
"types": "./id/index.d.ts"
|
|
135
|
+
},
|
|
136
|
+
"./logger": {
|
|
137
|
+
"import": "./logger/index.mjs",
|
|
138
|
+
"require": "./logger/index.cjs",
|
|
139
|
+
"types": "./logger/index.d.ts"
|
|
140
|
+
},
|
|
141
|
+
"./middleware": {
|
|
142
|
+
"import": "./middleware/index.mjs",
|
|
143
|
+
"require": "./middleware/index.cjs",
|
|
144
|
+
"types": "./middleware/index.d.ts"
|
|
145
|
+
},
|
|
146
|
+
"./obj": {
|
|
147
|
+
"import": "./obj/index.mjs",
|
|
148
|
+
"require": "./obj/index.cjs",
|
|
149
|
+
"types": "./obj/index.d.ts"
|
|
150
|
+
},
|
|
151
|
+
"./performance": {
|
|
152
|
+
"import": "./performance/index.mjs",
|
|
153
|
+
"require": "./performance/index.cjs",
|
|
154
|
+
"types": "./performance/index.d.ts"
|
|
155
|
+
},
|
|
156
|
+
"./request": {
|
|
157
|
+
"import": "./request/index.mjs",
|
|
158
|
+
"require": "./request/index.cjs",
|
|
159
|
+
"types": "./request/index.d.ts"
|
|
160
|
+
},
|
|
161
|
+
"./response": {
|
|
162
|
+
"import": "./response/index.mjs",
|
|
163
|
+
"require": "./response/index.cjs",
|
|
164
|
+
"types": "./response/index.d.ts"
|
|
165
|
+
},
|
|
166
|
+
"./server": {
|
|
167
|
+
"import": "./server/index.mjs",
|
|
168
|
+
"require": "./server/index.cjs",
|
|
169
|
+
"types": "./server/index.d.ts"
|
|
170
|
+
},
|
|
171
|
+
"./stream": {
|
|
172
|
+
"import": "./stream/index.mjs",
|
|
173
|
+
"require": "./stream/index.cjs",
|
|
174
|
+
"types": "./stream/index.d.ts"
|
|
175
|
+
},
|
|
176
|
+
"./string": {
|
|
177
|
+
"import": "./string/index.mjs",
|
|
178
|
+
"require": "./string/index.cjs",
|
|
179
|
+
"types": "./string/index.d.ts"
|
|
180
|
+
},
|
|
181
|
+
"./type": {
|
|
182
|
+
"import": "./type/index.mjs",
|
|
183
|
+
"require": "./type/index.cjs",
|
|
184
|
+
"types": "./type/index.d.ts"
|
|
185
|
+
},
|
|
186
|
+
"./types": {
|
|
187
|
+
"import": "./types/index.mjs",
|
|
188
|
+
"require": "./types/index.cjs",
|
|
189
|
+
"types": "./types/index.d.ts"
|
|
190
|
+
},
|
|
191
|
+
"./url": {
|
|
192
|
+
"import": "./url/index.mjs",
|
|
193
|
+
"require": "./url/index.cjs",
|
|
194
|
+
"types": "./url/index.d.ts"
|
|
195
|
+
},
|
|
196
|
+
"./validate": {
|
|
197
|
+
"import": "./validate/index.mjs",
|
|
198
|
+
"require": "./validate/index.cjs",
|
|
199
|
+
"types": "./validate/index.d.ts"
|
|
200
|
+
}
|
|
201
|
+
}
|
|
50
202
|
}
|