@catbee/utils 2.0.0-next.0 → 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.
Files changed (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +102 -52
  3. package/array/index.cjs +215 -74
  4. package/array/index.d.ts +345 -2
  5. package/array/index.mjs +201 -74
  6. package/async/index.cjs +116 -39
  7. package/async/index.d.ts +292 -2
  8. package/async/index.mjs +116 -40
  9. package/cache/index.cjs +2 -2
  10. package/cache/index.d.ts +156 -2
  11. package/cache/index.mjs +3 -3
  12. package/config/index.cjs +80 -66
  13. package/config/index.d.ts +65 -3
  14. package/config/index.mjs +77 -65
  15. package/context-store/index.cjs +2 -3
  16. package/context-store/index.d.ts +193 -2
  17. package/context-store/index.mjs +2 -3
  18. package/crypto/index.cjs +55 -5
  19. package/crypto/index.d.ts +225 -2
  20. package/crypto/index.mjs +52 -7
  21. package/date/index.cjs +676 -2
  22. package/date/index.d.ts +676 -2
  23. package/date/index.mjs +665 -3
  24. package/decorator/index.cjs +2172 -0
  25. package/{decorators/decorators.utils.d.ts → decorator/index.d.ts} +58 -54
  26. package/decorator/index.mjs +2131 -0
  27. package/{dir → directory}/index.cjs +5 -4
  28. package/{dir/dir.utils.d.ts → directory/index.d.ts} +24 -21
  29. package/{dir → directory}/index.mjs +5 -4
  30. package/env/index.cjs +100 -68
  31. package/env/index.d.ts +391 -2
  32. package/env/index.mjs +100 -68
  33. package/exception/index.cjs +1 -1
  34. package/exception/index.d.ts +233 -2
  35. package/exception/index.mjs +1 -1
  36. package/fs/index.cjs +71 -37
  37. package/fs/index.d.ts +206 -2
  38. package/fs/index.mjs +65 -35
  39. package/http-status-codes/index.cjs +1 -1
  40. package/http-status-codes/index.d.ts +268 -2
  41. package/http-status-codes/index.mjs +1 -1
  42. package/id/index.cjs +1 -1
  43. package/id/index.d.ts +38 -2
  44. package/id/index.mjs +1 -1
  45. package/index.cjs +13 -13
  46. package/index.d.ts +5 -5
  47. package/index.mjs +5 -5
  48. package/logger/index.cjs +13 -15
  49. package/logger/index.d.ts +190 -2
  50. package/logger/index.mjs +14 -16
  51. package/middleware/index.cjs +1 -1
  52. package/middleware/index.d.ts +104 -2
  53. package/middleware/index.mjs +1 -1
  54. package/object/index.cjs +379 -0
  55. package/{obj/obj.utils.d.ts → object/index.d.ts} +73 -33
  56. package/object/index.mjs +360 -0
  57. package/package.json +41 -23
  58. package/performance/index.cjs +4 -4
  59. package/performance/index.d.ts +139 -2
  60. package/performance/index.mjs +4 -4
  61. package/request/index.cjs +37 -25
  62. package/request/index.d.ts +242 -3
  63. package/request/index.mjs +37 -25
  64. package/response/index.cjs +1 -1
  65. package/response/index.d.ts +319 -3
  66. package/response/index.mjs +1 -1
  67. package/server/index.cjs +249 -146
  68. package/server/index.d.ts +866 -5
  69. package/server/index.mjs +248 -144
  70. package/stream/index.cjs +1 -1
  71. package/stream/index.d.ts +91 -2
  72. package/stream/index.mjs +1 -1
  73. package/string/index.cjs +34 -1
  74. package/string/index.d.ts +146 -2
  75. package/string/index.mjs +31 -2
  76. package/type/index.cjs +19 -2
  77. package/type/index.d.ts +144 -2
  78. package/type/index.mjs +17 -3
  79. package/types/index.cjs +1 -1
  80. package/types/index.d.ts +775 -5
  81. package/types/index.mjs +1 -1
  82. package/url/index.cjs +63 -5
  83. package/url/index.d.ts +200 -2
  84. package/url/index.mjs +59 -6
  85. package/{validate → validation}/index.cjs +91 -44
  86. package/{validate/validate.utils.d.ts → validation/index.d.ts} +33 -24
  87. package/{validate → validation}/index.mjs +87 -44
  88. package/array/array.utils.d.ts +0 -191
  89. package/async/async.utils.d.ts +0 -296
  90. package/cache/cache.utils.d.ts +0 -176
  91. package/config/config.d.ts +0 -57
  92. package/context-store/context-store.utils.d.ts +0 -212
  93. package/crypto/crypto.utils.d.ts +0 -183
  94. package/date/date.utils.d.ts +0 -190
  95. package/decorators/index.cjs +0 -913
  96. package/decorators/index.d.ts +0 -25
  97. package/decorators/index.mjs +0 -872
  98. package/dir/index.d.ts +0 -25
  99. package/env/env.utils.d.ts +0 -400
  100. package/exception/exception.utils.d.ts +0 -253
  101. package/fs/fs.utils.d.ts +0 -196
  102. package/http-status-codes/http-status-codes.d.ts +0 -289
  103. package/id/id.utils.d.ts +0 -59
  104. package/logger/logger.utils.d.ts +0 -210
  105. package/middleware/middleware.utils.d.ts +0 -123
  106. package/obj/index.cjs +0 -317
  107. package/obj/index.d.ts +0 -25
  108. package/obj/index.mjs +0 -301
  109. package/performance/performance.utils.d.ts +0 -159
  110. package/request/request.utils.d.ts +0 -109
  111. package/response/response.utils.d.ts +0 -186
  112. package/server/server.builder.d.ts +0 -531
  113. package/server/server.d.ts +0 -303
  114. package/stream/stream.utils.d.ts +0 -111
  115. package/string/string.utils.d.ts +0 -124
  116. package/type/type.utils.d.ts +0 -129
  117. package/types/api-response.d.ts +0 -175
  118. package/types/common.d.ts +0 -148
  119. package/types/config.d.ts +0 -88
  120. package/types/server.d.ts +0 -291
  121. package/url/url.utils.d.ts +0 -164
  122. package/validate/index.d.ts +0 -25
@@ -0,0 +1,360 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2026 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/object/object.utils.ts
29
+ function isObject(value) {
30
+ return value !== null && typeof value === "object" && !Array.isArray(value);
31
+ }
32
+ __name(isObject, "isObject");
33
+ function isObjEmpty(obj) {
34
+ return isObject(obj) && Object.keys(obj).length === 0;
35
+ }
36
+ __name(isObjEmpty, "isObjEmpty");
37
+ function pick(obj, keys) {
38
+ return Object.fromEntries(keys.map((key) => [
39
+ key,
40
+ obj[key]
41
+ ]));
42
+ }
43
+ __name(pick, "pick");
44
+ function omit(obj, keys) {
45
+ return Object.fromEntries(Object.entries(obj).filter(([key]) => !keys.includes(key)));
46
+ }
47
+ __name(omit, "omit");
48
+ function deepObjMerge(target, ...sources) {
49
+ const seen = /* @__PURE__ */ new WeakMap();
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)) {
67
+ const cloned = deepClone(s);
68
+ seen.set(s, cloned);
69
+ return cloned;
70
+ }
71
+ if (!t || typeof t !== "object") {
72
+ t = Object.create(Object.getPrototypeOf(s));
73
+ }
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;
82
+ }
83
+ return s;
84
+ }
85
+ __name(mergeInto, "mergeInto");
86
+ function isPlainObject(value) {
87
+ if (typeof value !== "object" || value === null) return false;
88
+ if (Array.isArray(value)) return false;
89
+ const proto = Object.getPrototypeOf(value);
90
+ return proto === Object.prototype || proto === null;
91
+ }
92
+ __name(isPlainObject, "isPlainObject");
93
+ function flattenObject(obj, prefix = "") {
94
+ return Object.entries(obj).reduce((acc, [key, value]) => {
95
+ const newKey = prefix ? `${prefix}.${key}` : key;
96
+ if (key === "__proto__") return acc;
97
+ if (value && typeof value === "object" && !Array.isArray(value)) {
98
+ Object.assign(acc, flattenObject(value, newKey));
99
+ } else {
100
+ acc[newKey] = value;
101
+ }
102
+ return acc;
103
+ }, {});
104
+ }
105
+ __name(flattenObject, "flattenObject");
106
+ function getValueByPath(obj, path) {
107
+ if (!obj || typeof obj !== "object") return void 0;
108
+ const parts = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
109
+ return parts.reduce((acc, key) => acc?.[key], obj);
110
+ }
111
+ __name(getValueByPath, "getValueByPath");
112
+ function ensureNextContainer(curr, nextIsIndex) {
113
+ if (curr === void 0 || typeof curr !== "object" || curr === null) {
114
+ return nextIsIndex ? [] : /* @__PURE__ */ Object.create(null);
115
+ }
116
+ return curr;
117
+ }
118
+ __name(ensureNextContainer, "ensureNextContainer");
119
+ function setValueByPath(obj, path, value) {
120
+ if (!obj || typeof obj !== "object") return obj;
121
+ const clone = deepClone(obj);
122
+ const parts = path.replace(/\[(\d+)\]/g, ".$1").split(".").filter(Boolean);
123
+ if (parts.length === 0) return clone;
124
+ const forbiddenKeys = /* @__PURE__ */ new Set([
125
+ "__proto__",
126
+ "prototype",
127
+ "constructor"
128
+ ]);
129
+ let current = clone;
130
+ for (let i = 0; i < parts.length - 1; i++) {
131
+ const key = parts[i];
132
+ if (forbiddenKeys.has(key)) return clone;
133
+ const nextKey = parts[i + 1];
134
+ const nextIsIndex = !Number.isNaN(Number(nextKey));
135
+ current[key] = ensureNextContainer(current[key], nextIsIndex);
136
+ current = current[key];
137
+ }
138
+ const finalKey = parts.at(-1);
139
+ if (forbiddenKeys.has(finalKey)) return clone;
140
+ current[finalKey] = value;
141
+ return clone;
142
+ }
143
+ __name(setValueByPath, "setValueByPath");
144
+ function isEqual(a, b) {
145
+ if (a === b) return true;
146
+ if (a == null || b == null || typeof a !== "object" || typeof b !== "object") return false;
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);
154
+ }
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");
200
+ function filterObject(obj, predicate) {
201
+ return Object.fromEntries(Object.entries(obj).filter(([key, value]) => predicate(value, key, obj)));
202
+ }
203
+ __name(filterObject, "filterObject");
204
+ function mapObject(obj, mapFn) {
205
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [
206
+ key,
207
+ mapFn(value, key, obj)
208
+ ]));
209
+ }
210
+ __name(mapObject, "mapObject");
211
+ function _deepClone(value, seen) {
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;
262
+ }
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);
281
+ if (desc?.get || desc?.set) {
282
+ Object.defineProperty(result, key, {
283
+ get: desc.get,
284
+ set: desc.set,
285
+ enumerable: desc.enumerable,
286
+ configurable: desc.configurable
287
+ });
288
+ } else {
289
+ Object.defineProperty(result, key, {
290
+ value: _deepClone(obj[key], seen),
291
+ writable: desc?.writable ?? true,
292
+ enumerable: desc?.enumerable ?? true,
293
+ configurable: desc?.configurable ?? true
294
+ });
295
+ }
296
+ }
297
+ return result;
298
+ }
299
+ __name(cloneObject, "cloneObject");
300
+ function deepClone(value) {
301
+ const seen = /* @__PURE__ */ new WeakMap();
302
+ return _deepClone(value, seen);
303
+ }
304
+ __name(deepClone, "deepClone");
305
+ function deepFreeze(obj) {
306
+ Object.freeze(obj);
307
+ for (const key of Reflect.ownKeys(obj)) {
308
+ const val = obj[key];
309
+ if (isObject(val) && !Object.isFrozen(val)) {
310
+ deepFreeze(val);
311
+ }
312
+ }
313
+ return obj;
314
+ }
315
+ __name(deepFreeze, "deepFreeze");
316
+ function getAllPaths(obj, parentPath = "") {
317
+ if (!isObject(obj)) return [];
318
+ return Object.entries(obj).flatMap(([key, value]) => {
319
+ const currentPath = parentPath ? `${parentPath}.${key}` : key;
320
+ if (isObject(value)) {
321
+ return [
322
+ currentPath,
323
+ ...getAllPaths(value, currentPath)
324
+ ];
325
+ }
326
+ return [
327
+ currentPath
328
+ ];
329
+ });
330
+ }
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");
359
+
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,13 +1,10 @@
1
1
  {
2
2
  "name": "@catbee/utils",
3
- "version": "2.0.0-next.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"
7
7
  },
8
- "main": "index.cjs",
9
- "module": "index.mjs",
10
- "types": "index.d.ts",
11
8
  "author": "Hari G <harig@catbee.in>",
12
9
  "maintainers": [
13
10
  "Hari G <harig@catbee.in>",
@@ -23,8 +20,7 @@
23
20
  },
24
21
  "license": "MIT",
25
22
  "dependencies": {
26
- "pino": "^10.1.0",
27
- "reflect-metadata": "^0.2.2"
23
+ "pino": "^10.1.0"
28
24
  },
29
25
  "optionalDependencies": {
30
26
  "@scalar/express-api-reference": "^0.8.30",
@@ -36,7 +32,8 @@
36
32
  "express-rate-limit": "^8.2.1",
37
33
  "helmet": "^8.1.0",
38
34
  "pino-pretty": "^13.1.3",
39
- "prom-client": "^15.1.3"
35
+ "prom-client": "^15.1.3",
36
+ "reflect-metadata": "^0.2.2"
40
37
  },
41
38
  "peerDependencies": {
42
39
  "express": "^5.1.0"
@@ -49,6 +46,9 @@
49
46
  "engines": {
50
47
  "node": ">=18.4"
51
48
  },
49
+ "main": "index.cjs",
50
+ "module": "index.mjs",
51
+ "types": "index.d.ts",
52
52
  "files": [
53
53
  "**/*.mjs",
54
54
  "**/*.cjs",
@@ -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
- "./decorators": {
102
- "import": "./decorators/index.mjs",
103
- "require": "./decorators/index.cjs",
104
- "types": "./decorators/index.d.ts"
119
+ "./decorator": {
120
+ "import": "./decorator/index.mjs",
121
+ "require": "./decorator/index.cjs",
122
+ "types": "./decorator/index.d.ts"
105
123
  },
106
- "./dir": {
107
- "import": "./dir/index.mjs",
108
- "require": "./dir/index.cjs",
109
- "types": "./dir/index.d.ts"
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
- "./obj": {
147
- "import": "./obj/index.mjs",
148
- "require": "./obj/index.cjs",
149
- "types": "./obj/index.d.ts"
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",
@@ -193,10 +211,10 @@
193
211
  "require": "./url/index.cjs",
194
212
  "types": "./url/index.d.ts"
195
213
  },
196
- "./validate": {
197
- "import": "./validate/index.mjs",
198
- "require": "./validate/index.cjs",
199
- "types": "./validate/index.d.ts"
214
+ "./validation": {
215
+ "import": "./validation/index.mjs",
216
+ "require": "./validation/index.cjs",
217
+ "types": "./validation/index.d.ts"
200
218
  }
201
219
  }
202
220
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
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
@@ -193,15 +193,15 @@ function memoize(fn, options = {}) {
193
193
  __name(memoize, "memoize");
194
194
  function trackMemoryUsage(fn, options = {}) {
195
195
  const { log = false, label = fn.name || "anonymous function" } = options;
196
- if (global.gc) {
197
- global.gc();
196
+ if (globalThis.gc) {
197
+ globalThis.gc();
198
198
  }
199
199
  const beforeMemory = process.memoryUsage();
200
200
  const result = fn();
201
201
  const afterMemory = process.memoryUsage();
202
202
  const diff = {};
203
203
  for (const key in afterMemory) {
204
- if (Object.prototype.hasOwnProperty.call(afterMemory, key)) {
204
+ if (Object.hasOwn(afterMemory, key)) {
205
205
  diff[key] = afterMemory[key] - beforeMemory[key];
206
206
  }
207
207
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
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
@@ -22,4 +22,141 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export * from './performance.utils';
25
+ /**
26
+ * Options for timing function execution.
27
+ */
28
+ interface TimingOptions {
29
+ /** Optional label for the timing (defaults to function name) */
30
+ label?: string;
31
+ /** Whether to log the timing (default: false) */
32
+ log?: boolean;
33
+ /** Log level to use if logging is enabled (default: 'debug') */
34
+ logLevel?: 'trace' | 'debug' | 'info' | 'warn' | 'error';
35
+ }
36
+ /**
37
+ * Result of a timing operation.
38
+ */
39
+ interface TimingResult {
40
+ /** Duration in milliseconds */
41
+ durationMs: number;
42
+ /** Duration in seconds */
43
+ durationSec: number;
44
+ /** Start timestamp */
45
+ startTime: number;
46
+ /** End timestamp */
47
+ endTime: number;
48
+ /** Label used for the timing */
49
+ label: string;
50
+ }
51
+ /**
52
+ * Measure the execution time of a synchronous function.
53
+ *
54
+ * @param fn - Function to measure
55
+ * @param options - Timing options
56
+ * @returns Result containing the return value and timing information
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const { result, timing } = timeSync(() => {
61
+ * // Some expensive operation
62
+ * return computeResult();
63
+ * }, { label: 'Computation', log: true });
64
+ *
65
+ * console.log(`Result: ${result}, took ${timing.durationMs}ms`);
66
+ * ```
67
+ */
68
+ declare function timeSync<T>(fn: () => T, options?: TimingOptions): {
69
+ result: T;
70
+ timing: TimingResult;
71
+ };
72
+ /**
73
+ * Measure the execution time of an asynchronous function.
74
+ *
75
+ * @param fn - Async function to measure
76
+ * @param options - Timing options
77
+ * @returns Promise resolving to result and timing information
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const { result, timing } = await timeAsync(async () => {
82
+ * // Some expensive async operation
83
+ * const data = await fetchData();
84
+ * return processData(data);
85
+ * }, { label: 'API Request', log: true });
86
+ *
87
+ * console.log(`Fetched ${result.length} items in ${timing.durationSec.toFixed(2)}s`);
88
+ * ```
89
+ */
90
+ declare function timeAsync<T>(fn: () => Promise<T>, options?: TimingOptions): Promise<{
91
+ result: T;
92
+ timing: TimingResult;
93
+ }>;
94
+ /**
95
+ * Create a timing decorator for class methods.
96
+ *
97
+ * @param options - Timing options
98
+ * @returns Method decorator
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * class DataService {
103
+ * @timed({ log: true, logLevel: 'info' })
104
+ * async fetchData() {
105
+ * // ...implementation
106
+ * }
107
+ * }
108
+ * ```
109
+ */
110
+ declare function timed(options?: TimingOptions): (target: any, propertyKeyOrContext: string | symbol | any, descriptor?: PropertyDescriptor) => void;
111
+ /**
112
+ * Memoize function results with optional TTL and max cache size.
113
+ *
114
+ * @param fn - Function to memoize
115
+ * @param options - Memoization options
116
+ * @returns Memoized function
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Cache results for 30 seconds, with a maximum of 100 entries
121
+ * const cachedFetch = memoize(
122
+ * async (url) => {
123
+ * const response = await fetch(url);
124
+ * return response.json();
125
+ * },
126
+ * { ttl: 30000, maxSize: 100, cacheKey: (url) => url }
127
+ * );
128
+ * ```
129
+ */
130
+ declare function memoize<T, Args extends any[]>(fn: (...args: Args) => T, options?: {
131
+ /** Time-to-live in milliseconds (default: indefinite) */
132
+ ttl?: number;
133
+ /** Maximum cache size (default: unlimited) */
134
+ maxSize?: number;
135
+ /** Function to generate a cache key from arguments */
136
+ cacheKey?: (...args: Args) => string;
137
+ /** Auto-cleanup interval in milliseconds (default: disabled) */
138
+ autoCleanupMs?: number;
139
+ }): (...args: Args) => T;
140
+ /**
141
+ * Track memory usage for a function execution.
142
+ *
143
+ * @param fn - Function to track
144
+ * @param options - Memory tracking options
145
+ * @returns Result and memory usage information
146
+ */
147
+ declare function trackMemoryUsage<T>(fn: () => T, options?: {
148
+ /** Whether to log the memory usage (default: false) */
149
+ log?: boolean;
150
+ /** Label for the memory tracking (default: function name) */
151
+ label?: string;
152
+ }): {
153
+ result: T;
154
+ memoryUsage: {
155
+ before: NodeJS.MemoryUsage;
156
+ after: NodeJS.MemoryUsage;
157
+ diff: Record<string, number>;
158
+ };
159
+ };
160
+
161
+ export { memoize, timeAsync, timeSync, timed, trackMemoryUsage };
162
+ export type { TimingOptions, TimingResult };
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
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
@@ -191,15 +191,15 @@ function memoize(fn, options = {}) {
191
191
  __name(memoize, "memoize");
192
192
  function trackMemoryUsage(fn, options = {}) {
193
193
  const { log = false, label = fn.name || "anonymous function" } = options;
194
- if (global.gc) {
195
- global.gc();
194
+ if (globalThis.gc) {
195
+ globalThis.gc();
196
196
  }
197
197
  const beforeMemory = process.memoryUsage();
198
198
  const result = fn();
199
199
  const afterMemory = process.memoryUsage();
200
200
  const diff = {};
201
201
  for (const key in afterMemory) {
202
- if (Object.prototype.hasOwnProperty.call(afterMemory, key)) {
202
+ if (Object.hasOwn(afterMemory, key)) {
203
203
  diff[key] = afterMemory[key] - beforeMemory[key];
204
204
  }
205
205
  }