@catbee/utils 2.0.0-next.1 → 2.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 +1 -1
- package/README.md +50 -36
- package/array/index.cjs +37 -5
- package/array/index.d.ts +59 -8
- package/array/index.mjs +32 -4
- package/async/index.cjs +24 -3
- package/async/index.d.ts +18 -2
- package/async/index.mjs +24 -4
- package/cache/index.cjs +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.mjs +1 -1
- package/config/index.cjs +8 -8
- package/config/index.d.ts +1 -1
- package/config/index.mjs +4 -4
- package/context-store/index.cjs +2 -3
- package/context-store/index.d.ts +1 -1
- package/context-store/index.mjs +2 -3
- package/crypto/index.cjs +55 -5
- package/crypto/index.d.ts +63 -2
- package/crypto/index.mjs +52 -7
- package/date/index.cjs +630 -1
- package/date/index.d.ts +487 -2
- package/date/index.mjs +621 -2
- package/{decorators → decorator}/index.cjs +425 -304
- package/{decorators → decorator}/index.d.ts +3 -2
- package/{decorators → decorator}/index.mjs +425 -304
- package/{dir → directory}/index.cjs +1 -1
- package/{dir → directory}/index.d.ts +1 -1
- package/{dir → directory}/index.mjs +1 -1
- package/env/index.cjs +90 -42
- package/env/index.d.ts +12 -1
- package/env/index.mjs +90 -42
- package/exception/index.cjs +1 -1
- package/exception/index.d.ts +1 -1
- package/exception/index.mjs +1 -1
- package/fs/index.cjs +1 -1
- package/fs/index.d.ts +1 -1
- package/fs/index.mjs +1 -1
- package/http-status-codes/index.cjs +1 -1
- package/http-status-codes/index.d.ts +1 -1
- package/http-status-codes/index.mjs +1 -1
- package/id/index.cjs +1 -1
- package/id/index.d.ts +1 -1
- package/id/index.mjs +1 -1
- package/index.cjs +10 -10
- package/index.d.ts +4 -4
- package/index.mjs +4 -4
- package/logger/index.cjs +2 -4
- package/logger/index.d.ts +2 -2
- package/logger/index.mjs +2 -4
- package/middleware/index.cjs +1 -1
- package/middleware/index.d.ts +1 -1
- package/middleware/index.mjs +1 -1
- package/{obj → object}/index.cjs +182 -108
- package/{obj → object}/index.d.ts +38 -2
- package/{obj → object}/index.mjs +180 -109
- package/package.json +31 -13
- package/performance/index.cjs +2 -2
- package/performance/index.d.ts +1 -1
- package/performance/index.mjs +2 -2
- package/request/index.cjs +36 -24
- package/request/index.d.ts +1 -1
- package/request/index.mjs +36 -24
- package/response/index.cjs +1 -1
- package/response/index.d.ts +1 -1
- package/response/index.mjs +1 -1
- package/server/index.cjs +230 -131
- package/server/index.d.ts +81 -1
- package/server/index.mjs +226 -127
- package/stream/index.cjs +1 -1
- package/stream/index.d.ts +1 -1
- package/stream/index.mjs +1 -1
- package/string/index.cjs +34 -1
- package/string/index.d.ts +45 -2
- package/string/index.mjs +31 -2
- package/type/index.cjs +18 -1
- package/type/index.d.ts +38 -2
- package/type/index.mjs +16 -2
- package/types/index.cjs +1 -1
- package/types/index.d.ts +3 -3
- package/types/index.mjs +1 -1
- package/url/index.cjs +61 -1
- package/url/index.d.ts +59 -2
- package/url/index.mjs +57 -2
- package/validation/index.cjs +3 -3
- package/validation/index.d.ts +1 -1
- package/validation/index.mjs +3 -3
package/{obj → object}/index.mjs
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
var __defProp = Object.defineProperty;
|
|
26
26
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
27
27
|
|
|
28
|
-
// src/
|
|
28
|
+
// src/object/object.utils.ts
|
|
29
29
|
function isObject(value) {
|
|
30
30
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
31
31
|
}
|
|
@@ -47,41 +47,42 @@ function omit(obj, keys) {
|
|
|
47
47
|
__name(omit, "omit");
|
|
48
48
|
function deepObjMerge(target, ...sources) {
|
|
49
49
|
const seen = /* @__PURE__ */ new WeakMap();
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
for (const s of sources) {
|
|
51
|
+
target = mergeInto(target, s, seen);
|
|
52
|
+
}
|
|
53
|
+
return target;
|
|
54
|
+
}
|
|
55
|
+
__name(deepObjMerge, "deepObjMerge");
|
|
56
|
+
function mergeInto(t, s, seen) {
|
|
57
|
+
if (s === void 0) return t;
|
|
58
|
+
if (typeof s === "function" || typeof s === "symbol") return s;
|
|
59
|
+
if (Array.isArray(s)) {
|
|
60
|
+
const cloned = deepClone(s);
|
|
61
|
+
seen.set(s, cloned);
|
|
62
|
+
return cloned;
|
|
63
|
+
}
|
|
64
|
+
if (s && typeof s === "object") {
|
|
65
|
+
if (seen.has(s)) return seen.get(s);
|
|
66
|
+
if (s instanceof Date || s instanceof Map || s instanceof Set || s instanceof RegExp || s instanceof ArrayBuffer || ArrayBuffer.isView(s)) {
|
|
54
67
|
const cloned = deepClone(s);
|
|
55
68
|
seen.set(s, cloned);
|
|
56
69
|
return cloned;
|
|
57
70
|
}
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
if (s instanceof Date || s instanceof Map || s instanceof Set || s instanceof RegExp || s instanceof ArrayBuffer || ArrayBuffer.isView(s)) {
|
|
61
|
-
const cloned = deepClone(s);
|
|
62
|
-
seen.set(s, cloned);
|
|
63
|
-
return cloned;
|
|
64
|
-
}
|
|
65
|
-
if (!t || typeof t !== "object") {
|
|
66
|
-
t = Object.create(Object.getPrototypeOf(s));
|
|
67
|
-
}
|
|
68
|
-
seen.set(s, t);
|
|
69
|
-
for (const key of Reflect.ownKeys(s)) {
|
|
70
|
-
if (key === "__proto__") continue;
|
|
71
|
-
const sv = s[key];
|
|
72
|
-
if (sv === void 0) continue;
|
|
73
|
-
t[key] = mergeInto(t[key], sv);
|
|
74
|
-
}
|
|
75
|
-
return t;
|
|
71
|
+
if (!t || typeof t !== "object") {
|
|
72
|
+
t = Object.create(Object.getPrototypeOf(s));
|
|
76
73
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
seen.set(s, t);
|
|
75
|
+
for (const key of Reflect.ownKeys(s)) {
|
|
76
|
+
if (key === "__proto__") continue;
|
|
77
|
+
const sv = s[key];
|
|
78
|
+
if (sv === void 0) continue;
|
|
79
|
+
t[key] = mergeInto(t[key], sv, seen);
|
|
80
|
+
}
|
|
81
|
+
return t;
|
|
81
82
|
}
|
|
82
|
-
return
|
|
83
|
+
return s;
|
|
83
84
|
}
|
|
84
|
-
__name(
|
|
85
|
+
__name(mergeInto, "mergeInto");
|
|
85
86
|
function isPlainObject(value) {
|
|
86
87
|
if (typeof value !== "object" || value === null) return false;
|
|
87
88
|
if (Array.isArray(value)) return false;
|
|
@@ -143,19 +144,59 @@ __name(setValueByPath, "setValueByPath");
|
|
|
143
144
|
function isEqual(a, b) {
|
|
144
145
|
if (a === b) return true;
|
|
145
146
|
if (a == null || b == null || typeof a !== "object" || typeof b !== "object") return false;
|
|
146
|
-
if (a instanceof Date && b instanceof Date) return a
|
|
147
|
-
if (a instanceof RegExp && b instanceof RegExp) return a
|
|
148
|
-
if (a instanceof Set && b instanceof Set) return a
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (a
|
|
152
|
-
|
|
153
|
-
].every(([k, v]) => isEqual(v, b.get(k)));
|
|
154
|
-
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) return isEqual(new Uint8Array(a), new Uint8Array(b));
|
|
155
|
-
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((v, i) => isEqual(v, b[i]));
|
|
156
|
-
return Object.keys(a).length === Object.keys(b).length && Object.keys(a).every((key) => isEqual(a[key], b[key]));
|
|
147
|
+
if (a instanceof Date && b instanceof Date) return equalDates(a, b);
|
|
148
|
+
if (a instanceof RegExp && b instanceof RegExp) return equalRegExp(a, b);
|
|
149
|
+
if (a instanceof Set && b instanceof Set) return equalSet(a, b);
|
|
150
|
+
if (a instanceof Map && b instanceof Map) return equalMap(a, b);
|
|
151
|
+
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) return equalArrayBuffer(a, b);
|
|
152
|
+
if (Array.isArray(a) && Array.isArray(b)) return equalArray(a, b);
|
|
153
|
+
return equalPlainObjects(a, b);
|
|
157
154
|
}
|
|
158
155
|
__name(isEqual, "isEqual");
|
|
156
|
+
function equalDates(a, b) {
|
|
157
|
+
return a.getTime() === b.getTime();
|
|
158
|
+
}
|
|
159
|
+
__name(equalDates, "equalDates");
|
|
160
|
+
function equalRegExp(a, b) {
|
|
161
|
+
return a.source === b.source && a.flags === b.flags;
|
|
162
|
+
}
|
|
163
|
+
__name(equalRegExp, "equalRegExp");
|
|
164
|
+
function equalSet(a, b) {
|
|
165
|
+
if (a.size !== b.size) return false;
|
|
166
|
+
for (const v of a) if (!b.has(v)) return false;
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
__name(equalSet, "equalSet");
|
|
170
|
+
function equalMap(a, b) {
|
|
171
|
+
if (a.size !== b.size) return false;
|
|
172
|
+
for (const [k, v] of a) {
|
|
173
|
+
if (!b.has(k)) return false;
|
|
174
|
+
if (!isEqual(v, b.get(k))) return false;
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
__name(equalMap, "equalMap");
|
|
179
|
+
function equalArrayBuffer(a, b) {
|
|
180
|
+
return isEqual(new Uint8Array(a), new Uint8Array(b));
|
|
181
|
+
}
|
|
182
|
+
__name(equalArrayBuffer, "equalArrayBuffer");
|
|
183
|
+
function equalArray(a, b) {
|
|
184
|
+
if (a.length !== b.length) return false;
|
|
185
|
+
for (let i = 0; i < a.length; i++) if (!isEqual(a[i], b[i])) return false;
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
__name(equalArray, "equalArray");
|
|
189
|
+
function equalPlainObjects(a, b) {
|
|
190
|
+
const aKeys = Object.keys(a);
|
|
191
|
+
const bKeys = Object.keys(b);
|
|
192
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
193
|
+
for (const key of aKeys) {
|
|
194
|
+
if (!Object.hasOwn(b, key)) return false;
|
|
195
|
+
if (!isEqual(a[key], b[key])) return false;
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
__name(equalPlainObjects, "equalPlainObjects");
|
|
159
200
|
function filterObject(obj, predicate) {
|
|
160
201
|
return Object.fromEntries(Object.entries(obj).filter(([key, value]) => predicate(value, key, obj)));
|
|
161
202
|
}
|
|
@@ -168,72 +209,75 @@ function mapObject(obj, mapFn) {
|
|
|
168
209
|
}
|
|
169
210
|
__name(mapObject, "mapObject");
|
|
170
211
|
function _deepClone(value, seen) {
|
|
171
|
-
if (typeof value === "function" || typeof value === "symbol")
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (value
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
const typed = value;
|
|
223
|
-
const buf = _deepClone(typed.buffer, seen);
|
|
224
|
-
const clone = new typed.constructor(buf, typed.byteOffset, typed.length);
|
|
225
|
-
seen.set(value, clone);
|
|
226
|
-
return clone;
|
|
227
|
-
}
|
|
228
|
-
if (value instanceof ArrayBuffer) {
|
|
229
|
-
result = value.slice(0);
|
|
230
|
-
seen.set(value, result);
|
|
231
|
-
return result;
|
|
212
|
+
if (typeof value === "function" || typeof value === "symbol") return value;
|
|
213
|
+
if (value === null || typeof value !== "object") return value;
|
|
214
|
+
if (seen.has(value)) return seen.get(value);
|
|
215
|
+
if (Array.isArray(value)) return cloneArray(value, seen);
|
|
216
|
+
if (value instanceof Date) return cloneDate(value);
|
|
217
|
+
if (value instanceof Map) return cloneMap(value, seen);
|
|
218
|
+
if (value instanceof Set) return cloneSet(value, seen);
|
|
219
|
+
if (value instanceof RegExp) return cloneRegExp(value);
|
|
220
|
+
if (ArrayBuffer.isView(value)) return cloneArrayBufferView(value, seen);
|
|
221
|
+
if (value instanceof ArrayBuffer) return cloneArrayBuffer(value, seen);
|
|
222
|
+
return cloneObject(value, seen);
|
|
223
|
+
}
|
|
224
|
+
__name(_deepClone, "_deepClone");
|
|
225
|
+
function cloneArray(arr, seen) {
|
|
226
|
+
const result = [];
|
|
227
|
+
seen.set(arr, result);
|
|
228
|
+
for (const item of arr) result.push(_deepClone(item, seen));
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
__name(cloneArray, "cloneArray");
|
|
232
|
+
function cloneDate(d) {
|
|
233
|
+
const r = new Date(d.getTime());
|
|
234
|
+
return r;
|
|
235
|
+
}
|
|
236
|
+
__name(cloneDate, "cloneDate");
|
|
237
|
+
function cloneMap(m, seen) {
|
|
238
|
+
const result = /* @__PURE__ */ new Map();
|
|
239
|
+
seen.set(m, result);
|
|
240
|
+
for (const [k, v] of m) result.set(_deepClone(k, seen), _deepClone(v, seen));
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
__name(cloneMap, "cloneMap");
|
|
244
|
+
function cloneSet(s, seen) {
|
|
245
|
+
const result = /* @__PURE__ */ new Set();
|
|
246
|
+
seen.set(s, result);
|
|
247
|
+
for (const v of s) result.add(_deepClone(v, seen));
|
|
248
|
+
return result;
|
|
249
|
+
}
|
|
250
|
+
__name(cloneSet, "cloneSet");
|
|
251
|
+
function cloneRegExp(r) {
|
|
252
|
+
const result = new RegExp(r.source, r.flags);
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
255
|
+
__name(cloneRegExp, "cloneRegExp");
|
|
256
|
+
function cloneArrayBufferView(view, seen) {
|
|
257
|
+
if (view instanceof DataView) {
|
|
258
|
+
const buf2 = _deepClone(view.buffer, seen);
|
|
259
|
+
const clone2 = new DataView(buf2, view.byteOffset, view.byteLength);
|
|
260
|
+
seen.set(view, clone2);
|
|
261
|
+
return clone2;
|
|
232
262
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
263
|
+
const typed = view;
|
|
264
|
+
const buf = _deepClone(typed.buffer, seen);
|
|
265
|
+
const clone = new typed.constructor(buf, typed.byteOffset, typed.length);
|
|
266
|
+
seen.set(view, clone);
|
|
267
|
+
return clone;
|
|
268
|
+
}
|
|
269
|
+
__name(cloneArrayBufferView, "cloneArrayBufferView");
|
|
270
|
+
function cloneArrayBuffer(buf, seen) {
|
|
271
|
+
const result = buf.slice(0);
|
|
272
|
+
seen.set(buf, result);
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
__name(cloneArrayBuffer, "cloneArrayBuffer");
|
|
276
|
+
function cloneObject(obj, seen) {
|
|
277
|
+
const result = Object.create(Object.getPrototypeOf(obj));
|
|
278
|
+
seen.set(obj, result);
|
|
279
|
+
for (const key of Reflect.ownKeys(obj)) {
|
|
280
|
+
const desc = Object.getOwnPropertyDescriptor(obj, key);
|
|
237
281
|
if (desc?.get || desc?.set) {
|
|
238
282
|
Object.defineProperty(result, key, {
|
|
239
283
|
get: desc.get,
|
|
@@ -243,7 +287,7 @@ function _deepClone(value, seen) {
|
|
|
243
287
|
});
|
|
244
288
|
} else {
|
|
245
289
|
Object.defineProperty(result, key, {
|
|
246
|
-
value: _deepClone(
|
|
290
|
+
value: _deepClone(obj[key], seen),
|
|
247
291
|
writable: desc?.writable ?? true,
|
|
248
292
|
enumerable: desc?.enumerable ?? true,
|
|
249
293
|
configurable: desc?.configurable ?? true
|
|
@@ -252,7 +296,7 @@ function _deepClone(value, seen) {
|
|
|
252
296
|
}
|
|
253
297
|
return result;
|
|
254
298
|
}
|
|
255
|
-
__name(
|
|
299
|
+
__name(cloneObject, "cloneObject");
|
|
256
300
|
function deepClone(value) {
|
|
257
301
|
const seen = /* @__PURE__ */ new WeakMap();
|
|
258
302
|
return _deepClone(value, seen);
|
|
@@ -285,5 +329,32 @@ function getAllPaths(obj, parentPath = "") {
|
|
|
285
329
|
});
|
|
286
330
|
}
|
|
287
331
|
__name(getAllPaths, "getAllPaths");
|
|
332
|
+
function invert(obj) {
|
|
333
|
+
if (!isObject(obj)) return {};
|
|
334
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
|
|
335
|
+
String(v),
|
|
336
|
+
k
|
|
337
|
+
]));
|
|
338
|
+
}
|
|
339
|
+
__name(invert, "invert");
|
|
340
|
+
function invertBy(obj, keyFn) {
|
|
341
|
+
if (!isObject(obj)) return {};
|
|
342
|
+
const result = {};
|
|
343
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
344
|
+
const newKey = keyFn(value);
|
|
345
|
+
if (!result[newKey]) result[newKey] = [];
|
|
346
|
+
result[newKey].push(key);
|
|
347
|
+
}
|
|
348
|
+
return result;
|
|
349
|
+
}
|
|
350
|
+
__name(invertBy, "invertBy");
|
|
351
|
+
function transform(obj, fn) {
|
|
352
|
+
if (!isObject(obj)) return {};
|
|
353
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
|
|
354
|
+
k,
|
|
355
|
+
fn(v, k)
|
|
356
|
+
]));
|
|
357
|
+
}
|
|
358
|
+
__name(transform, "transform");
|
|
288
359
|
|
|
289
|
-
export { deepClone, deepFreeze, deepObjMerge, filterObject, flattenObject, getAllPaths, getValueByPath, isEqual, isObjEmpty, isObject, isPlainObject, mapObject, omit, pick, setValueByPath };
|
|
360
|
+
export { deepClone, deepFreeze, deepObjMerge, filterObject, flattenObject, getAllPaths, getValueByPath, invert, invertBy, isEqual, isObjEmpty, isObject, isPlainObject, mapObject, omit, pick, setValueByPath, transform };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@catbee/utils",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.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
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -57,6 +57,24 @@
|
|
|
57
57
|
"LICENSE",
|
|
58
58
|
"README.md"
|
|
59
59
|
],
|
|
60
|
+
"keywords": [
|
|
61
|
+
"catbee",
|
|
62
|
+
"catbee-utils",
|
|
63
|
+
"utils",
|
|
64
|
+
"utilities",
|
|
65
|
+
"helper",
|
|
66
|
+
"helpers",
|
|
67
|
+
"tools",
|
|
68
|
+
"typescript",
|
|
69
|
+
"nodejs",
|
|
70
|
+
"node",
|
|
71
|
+
"esm",
|
|
72
|
+
"commonjs",
|
|
73
|
+
"express",
|
|
74
|
+
"expressjs",
|
|
75
|
+
"express-server",
|
|
76
|
+
"developer-tools"
|
|
77
|
+
],
|
|
60
78
|
"exports": {
|
|
61
79
|
".": {
|
|
62
80
|
"import": "./index.mjs",
|
|
@@ -98,15 +116,15 @@
|
|
|
98
116
|
"require": "./date/index.cjs",
|
|
99
117
|
"types": "./date/index.d.ts"
|
|
100
118
|
},
|
|
101
|
-
"./
|
|
102
|
-
"import": "./
|
|
103
|
-
"require": "./
|
|
104
|
-
"types": "./
|
|
119
|
+
"./decorator": {
|
|
120
|
+
"import": "./decorator/index.mjs",
|
|
121
|
+
"require": "./decorator/index.cjs",
|
|
122
|
+
"types": "./decorator/index.d.ts"
|
|
105
123
|
},
|
|
106
|
-
"./
|
|
107
|
-
"import": "./
|
|
108
|
-
"require": "./
|
|
109
|
-
"types": "./
|
|
124
|
+
"./directory": {
|
|
125
|
+
"import": "./directory/index.mjs",
|
|
126
|
+
"require": "./directory/index.cjs",
|
|
127
|
+
"types": "./directory/index.d.ts"
|
|
110
128
|
},
|
|
111
129
|
"./env": {
|
|
112
130
|
"import": "./env/index.mjs",
|
|
@@ -143,10 +161,10 @@
|
|
|
143
161
|
"require": "./middleware/index.cjs",
|
|
144
162
|
"types": "./middleware/index.d.ts"
|
|
145
163
|
},
|
|
146
|
-
"./
|
|
147
|
-
"import": "./
|
|
148
|
-
"require": "./
|
|
149
|
-
"types": "./
|
|
164
|
+
"./object": {
|
|
165
|
+
"import": "./object/index.mjs",
|
|
166
|
+
"require": "./object/index.cjs",
|
|
167
|
+
"types": "./object/index.d.ts"
|
|
150
168
|
},
|
|
151
169
|
"./performance": {
|
|
152
170
|
"import": "./performance/index.mjs",
|
package/performance/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -201,7 +201,7 @@ function trackMemoryUsage(fn, options = {}) {
|
|
|
201
201
|
const afterMemory = process.memoryUsage();
|
|
202
202
|
const diff = {};
|
|
203
203
|
for (const key in afterMemory) {
|
|
204
|
-
if (Object.
|
|
204
|
+
if (Object.hasOwn(afterMemory, key)) {
|
|
205
205
|
diff[key] = afterMemory[key] - beforeMemory[key];
|
|
206
206
|
}
|
|
207
207
|
}
|
package/performance/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
package/performance/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -199,7 +199,7 @@ function trackMemoryUsage(fn, options = {}) {
|
|
|
199
199
|
const afterMemory = process.memoryUsage();
|
|
200
200
|
const diff = {};
|
|
201
201
|
for (const key in afterMemory) {
|
|
202
|
-
if (Object.
|
|
202
|
+
if (Object.hasOwn(afterMemory, key)) {
|
|
203
203
|
diff[key] = afterMemory[key] - beforeMemory[key];
|
|
204
204
|
}
|
|
205
205
|
}
|
package/request/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -143,38 +143,50 @@ function extractPaginationParams(query, defaultPage = 1, defaultLimit = 20, maxL
|
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
__name(extractPaginationParams, "extractPaginationParams");
|
|
146
|
-
|
|
146
|
+
var DEFAULT_SORT = {
|
|
147
147
|
sortBy: "createdAt",
|
|
148
148
|
sortOrder: "desc"
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
} else if (typeof query.sort === "string") {
|
|
157
|
-
sortBy = query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
|
|
158
|
-
sortOrder = query.sort.startsWith("-") ? "desc" : "asc";
|
|
159
|
-
} else if (Array.isArray(query.sort)) {
|
|
160
|
-
sortBy = query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
|
|
161
|
-
sortOrder = query.sort[0].startsWith("-") ? "desc" : "asc";
|
|
162
|
-
}
|
|
163
|
-
if (typeof query.sortOrder === "string") {
|
|
164
|
-
const order = query.sortOrder.toLowerCase();
|
|
165
|
-
if (order === "asc" || order === "desc") {
|
|
166
|
-
sortOrder = order;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
if (allowedFields.length && !allowedFields.includes(sortBy)) {
|
|
170
|
-
sortBy = defaultSort.sortBy;
|
|
149
|
+
};
|
|
150
|
+
function extractSortParams(query, allowedFields, defaultSort = DEFAULT_SORT) {
|
|
151
|
+
const inferredSortBy = getSortByFromQuery(query, defaultSort);
|
|
152
|
+
let sortOrder = getSortOrderFromQuery(query, defaultSort);
|
|
153
|
+
const explicit = applyExplicitSortOrder(query.sortOrder);
|
|
154
|
+
if (explicit) {
|
|
155
|
+
sortOrder = explicit;
|
|
171
156
|
}
|
|
157
|
+
const sortBy = validateSortField(inferredSortBy, allowedFields, defaultSort.sortBy);
|
|
172
158
|
return {
|
|
173
159
|
sortBy,
|
|
174
160
|
sortOrder
|
|
175
161
|
};
|
|
176
162
|
}
|
|
177
163
|
__name(extractSortParams, "extractSortParams");
|
|
164
|
+
function getSortByFromQuery(query, defaultSort) {
|
|
165
|
+
if (typeof query.sortBy === "string") return query.sortBy;
|
|
166
|
+
if (Array.isArray(query.sortBy)) return query.sortBy[0];
|
|
167
|
+
if (typeof query.sort === "string") return query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
|
|
168
|
+
if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
|
|
169
|
+
return defaultSort.sortBy;
|
|
170
|
+
}
|
|
171
|
+
__name(getSortByFromQuery, "getSortByFromQuery");
|
|
172
|
+
function getSortOrderFromQuery(query, defaultSort) {
|
|
173
|
+
if (typeof query.sort === "string") return query.sort.startsWith("-") ? "desc" : "asc";
|
|
174
|
+
if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? "desc" : "asc";
|
|
175
|
+
return defaultSort.sortOrder;
|
|
176
|
+
}
|
|
177
|
+
__name(getSortOrderFromQuery, "getSortOrderFromQuery");
|
|
178
|
+
function applyExplicitSortOrder(sortOrderParam) {
|
|
179
|
+
if (typeof sortOrderParam !== "string") return null;
|
|
180
|
+
const order = sortOrderParam.toLowerCase();
|
|
181
|
+
if (order === "asc" || order === "desc") return order;
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
__name(applyExplicitSortOrder, "applyExplicitSortOrder");
|
|
185
|
+
function validateSortField(sortBy, allowedFields, defaultSortBy) {
|
|
186
|
+
if (allowedFields.length && !allowedFields.includes(sortBy)) return defaultSortBy;
|
|
187
|
+
return sortBy;
|
|
188
|
+
}
|
|
189
|
+
__name(validateSortField, "validateSortField");
|
|
178
190
|
function extractFilterParams(query, allowedFilters) {
|
|
179
191
|
const filters = {};
|
|
180
192
|
for (const field of allowedFilters) {
|
package/request/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
package/request/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -141,38 +141,50 @@ function extractPaginationParams(query, defaultPage = 1, defaultLimit = 20, maxL
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
__name(extractPaginationParams, "extractPaginationParams");
|
|
144
|
-
|
|
144
|
+
var DEFAULT_SORT = {
|
|
145
145
|
sortBy: "createdAt",
|
|
146
146
|
sortOrder: "desc"
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
} else if (typeof query.sort === "string") {
|
|
155
|
-
sortBy = query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
|
|
156
|
-
sortOrder = query.sort.startsWith("-") ? "desc" : "asc";
|
|
157
|
-
} else if (Array.isArray(query.sort)) {
|
|
158
|
-
sortBy = query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
|
|
159
|
-
sortOrder = query.sort[0].startsWith("-") ? "desc" : "asc";
|
|
160
|
-
}
|
|
161
|
-
if (typeof query.sortOrder === "string") {
|
|
162
|
-
const order = query.sortOrder.toLowerCase();
|
|
163
|
-
if (order === "asc" || order === "desc") {
|
|
164
|
-
sortOrder = order;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (allowedFields.length && !allowedFields.includes(sortBy)) {
|
|
168
|
-
sortBy = defaultSort.sortBy;
|
|
147
|
+
};
|
|
148
|
+
function extractSortParams(query, allowedFields, defaultSort = DEFAULT_SORT) {
|
|
149
|
+
const inferredSortBy = getSortByFromQuery(query, defaultSort);
|
|
150
|
+
let sortOrder = getSortOrderFromQuery(query, defaultSort);
|
|
151
|
+
const explicit = applyExplicitSortOrder(query.sortOrder);
|
|
152
|
+
if (explicit) {
|
|
153
|
+
sortOrder = explicit;
|
|
169
154
|
}
|
|
155
|
+
const sortBy = validateSortField(inferredSortBy, allowedFields, defaultSort.sortBy);
|
|
170
156
|
return {
|
|
171
157
|
sortBy,
|
|
172
158
|
sortOrder
|
|
173
159
|
};
|
|
174
160
|
}
|
|
175
161
|
__name(extractSortParams, "extractSortParams");
|
|
162
|
+
function getSortByFromQuery(query, defaultSort) {
|
|
163
|
+
if (typeof query.sortBy === "string") return query.sortBy;
|
|
164
|
+
if (Array.isArray(query.sortBy)) return query.sortBy[0];
|
|
165
|
+
if (typeof query.sort === "string") return query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
|
|
166
|
+
if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
|
|
167
|
+
return defaultSort.sortBy;
|
|
168
|
+
}
|
|
169
|
+
__name(getSortByFromQuery, "getSortByFromQuery");
|
|
170
|
+
function getSortOrderFromQuery(query, defaultSort) {
|
|
171
|
+
if (typeof query.sort === "string") return query.sort.startsWith("-") ? "desc" : "asc";
|
|
172
|
+
if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? "desc" : "asc";
|
|
173
|
+
return defaultSort.sortOrder;
|
|
174
|
+
}
|
|
175
|
+
__name(getSortOrderFromQuery, "getSortOrderFromQuery");
|
|
176
|
+
function applyExplicitSortOrder(sortOrderParam) {
|
|
177
|
+
if (typeof sortOrderParam !== "string") return null;
|
|
178
|
+
const order = sortOrderParam.toLowerCase();
|
|
179
|
+
if (order === "asc" || order === "desc") return order;
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
__name(applyExplicitSortOrder, "applyExplicitSortOrder");
|
|
183
|
+
function validateSortField(sortBy, allowedFields, defaultSortBy) {
|
|
184
|
+
if (allowedFields.length && !allowedFields.includes(sortBy)) return defaultSortBy;
|
|
185
|
+
return sortBy;
|
|
186
|
+
}
|
|
187
|
+
__name(validateSortField, "validateSortField");
|
|
176
188
|
function extractFilterParams(query, allowedFilters) {
|
|
177
189
|
const filters = {};
|
|
178
190
|
for (const field of allowedFilters) {
|
package/response/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
package/response/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* The MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright (c)
|
|
4
|
+
* Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|