@catbee/utils 2.0.0-next.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +55 -38
- 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 +233 -131
- package/server/index.d.ts +81 -1
- package/server/index.mjs +229 -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 +10 -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/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
|
|
@@ -31,8 +31,8 @@ export * from './cache';
|
|
|
31
31
|
export * from './context-store';
|
|
32
32
|
export * from './crypto';
|
|
33
33
|
export * from './date';
|
|
34
|
-
export * from './
|
|
35
|
-
export * from './
|
|
34
|
+
export * from './decorator';
|
|
35
|
+
export * from './directory';
|
|
36
36
|
export * from './env';
|
|
37
37
|
export * from './exception';
|
|
38
38
|
export * from './fs';
|
|
@@ -40,7 +40,7 @@ export * from './http-status-codes';
|
|
|
40
40
|
export * from './id';
|
|
41
41
|
export * from './logger';
|
|
42
42
|
export * from './middleware';
|
|
43
|
-
export * from './
|
|
43
|
+
export * from './object';
|
|
44
44
|
export * from './performance';
|
|
45
45
|
export * from './request';
|
|
46
46
|
export * from './response';
|
package/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
|
|
@@ -31,8 +31,8 @@ export * from "./cache/index.mjs";
|
|
|
31
31
|
export * from "./context-store/index.mjs";
|
|
32
32
|
export * from "./crypto/index.mjs";
|
|
33
33
|
export * from "./date/index.mjs";
|
|
34
|
-
export * from "./
|
|
35
|
-
export * from "./
|
|
34
|
+
export * from "./decorator/index.mjs";
|
|
35
|
+
export * from "./directory/index.mjs";
|
|
36
36
|
export * from "./env/index.mjs";
|
|
37
37
|
export * from "./exception/index.mjs";
|
|
38
38
|
export * from "./fs/index.mjs";
|
|
@@ -40,7 +40,7 @@ export * from "./http-status-codes/index.mjs";
|
|
|
40
40
|
export * from "./id/index.mjs";
|
|
41
41
|
export * from "./logger/index.mjs";
|
|
42
42
|
export * from "./middleware/index.mjs";
|
|
43
|
-
export * from "./
|
|
43
|
+
export * from "./object/index.mjs";
|
|
44
44
|
export * from "./performance/index.mjs";
|
|
45
45
|
export * from "./request/index.mjs";
|
|
46
46
|
export * from "./response/index.mjs";
|
package/logger/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
|
|
@@ -133,9 +133,7 @@ function addRedactFields(fields) {
|
|
|
133
133
|
__name(addRedactFields, "addRedactFields");
|
|
134
134
|
var cachedExpandedFields = null;
|
|
135
135
|
function getExpandedSensitiveFields() {
|
|
136
|
-
|
|
137
|
-
cachedExpandedFields = expandSensitiveFields(defaultSensitiveFields);
|
|
138
|
-
}
|
|
136
|
+
cachedExpandedFields ??= expandSensitiveFields(defaultSensitiveFields);
|
|
139
137
|
return cachedExpandedFields;
|
|
140
138
|
}
|
|
141
139
|
__name(getExpandedSensitiveFields, "getExpandedSensitiveFields");
|
package/logger/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
|
|
@@ -188,7 +188,7 @@ declare function createRequestLogger(requestId: string, additionalContext?: Reco
|
|
|
188
188
|
* @param {string} [message] - Optional message to include
|
|
189
189
|
* @param {Record<string, any>} [context] - Additional context properties
|
|
190
190
|
*/
|
|
191
|
-
declare function logError(error: Error |
|
|
191
|
+
declare function logError(error: Error | string, message?: string, context?: Record<string, any>): void;
|
|
192
192
|
/**
|
|
193
193
|
* Expands multiple sensitive field names into their variants.
|
|
194
194
|
* Useful to match fields like `api_key`, `apiKey`, `apikey`, `APIKEY`, etc.
|
package/logger/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
|
|
@@ -127,9 +127,7 @@ function addRedactFields(fields) {
|
|
|
127
127
|
__name(addRedactFields, "addRedactFields");
|
|
128
128
|
var cachedExpandedFields = null;
|
|
129
129
|
function getExpandedSensitiveFields() {
|
|
130
|
-
|
|
131
|
-
cachedExpandedFields = expandSensitiveFields(defaultSensitiveFields);
|
|
132
|
-
}
|
|
130
|
+
cachedExpandedFields ??= expandSensitiveFields(defaultSensitiveFields);
|
|
133
131
|
return cachedExpandedFields;
|
|
134
132
|
}
|
|
135
133
|
__name(getExpandedSensitiveFields, "getExpandedSensitiveFields");
|
package/middleware/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/middleware/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/middleware/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
|
package/{obj → object}/index.cjs
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
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
var __defProp = Object.defineProperty;
|
|
28
28
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
29
29
|
|
|
30
|
-
// src/
|
|
30
|
+
// src/object/object.utils.ts
|
|
31
31
|
function isObject(value) {
|
|
32
32
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33
33
|
}
|
|
@@ -49,41 +49,42 @@ function omit(obj, keys) {
|
|
|
49
49
|
__name(omit, "omit");
|
|
50
50
|
function deepObjMerge(target, ...sources) {
|
|
51
51
|
const seen = /* @__PURE__ */ new WeakMap();
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
for (const s of sources) {
|
|
53
|
+
target = mergeInto(target, s, seen);
|
|
54
|
+
}
|
|
55
|
+
return target;
|
|
56
|
+
}
|
|
57
|
+
__name(deepObjMerge, "deepObjMerge");
|
|
58
|
+
function mergeInto(t, s, seen) {
|
|
59
|
+
if (s === void 0) return t;
|
|
60
|
+
if (typeof s === "function" || typeof s === "symbol") return s;
|
|
61
|
+
if (Array.isArray(s)) {
|
|
62
|
+
const cloned = deepClone(s);
|
|
63
|
+
seen.set(s, cloned);
|
|
64
|
+
return cloned;
|
|
65
|
+
}
|
|
66
|
+
if (s && typeof s === "object") {
|
|
67
|
+
if (seen.has(s)) return seen.get(s);
|
|
68
|
+
if (s instanceof Date || s instanceof Map || s instanceof Set || s instanceof RegExp || s instanceof ArrayBuffer || ArrayBuffer.isView(s)) {
|
|
56
69
|
const cloned = deepClone(s);
|
|
57
70
|
seen.set(s, cloned);
|
|
58
71
|
return cloned;
|
|
59
72
|
}
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
if (s instanceof Date || s instanceof Map || s instanceof Set || s instanceof RegExp || s instanceof ArrayBuffer || ArrayBuffer.isView(s)) {
|
|
63
|
-
const cloned = deepClone(s);
|
|
64
|
-
seen.set(s, cloned);
|
|
65
|
-
return cloned;
|
|
66
|
-
}
|
|
67
|
-
if (!t || typeof t !== "object") {
|
|
68
|
-
t = Object.create(Object.getPrototypeOf(s));
|
|
69
|
-
}
|
|
70
|
-
seen.set(s, t);
|
|
71
|
-
for (const key of Reflect.ownKeys(s)) {
|
|
72
|
-
if (key === "__proto__") continue;
|
|
73
|
-
const sv = s[key];
|
|
74
|
-
if (sv === void 0) continue;
|
|
75
|
-
t[key] = mergeInto(t[key], sv);
|
|
76
|
-
}
|
|
77
|
-
return t;
|
|
73
|
+
if (!t || typeof t !== "object") {
|
|
74
|
+
t = Object.create(Object.getPrototypeOf(s));
|
|
78
75
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
seen.set(s, t);
|
|
77
|
+
for (const key of Reflect.ownKeys(s)) {
|
|
78
|
+
if (key === "__proto__") continue;
|
|
79
|
+
const sv = s[key];
|
|
80
|
+
if (sv === void 0) continue;
|
|
81
|
+
t[key] = mergeInto(t[key], sv, seen);
|
|
82
|
+
}
|
|
83
|
+
return t;
|
|
83
84
|
}
|
|
84
|
-
return
|
|
85
|
+
return s;
|
|
85
86
|
}
|
|
86
|
-
__name(
|
|
87
|
+
__name(mergeInto, "mergeInto");
|
|
87
88
|
function isPlainObject(value) {
|
|
88
89
|
if (typeof value !== "object" || value === null) return false;
|
|
89
90
|
if (Array.isArray(value)) return false;
|
|
@@ -145,19 +146,59 @@ __name(setValueByPath, "setValueByPath");
|
|
|
145
146
|
function isEqual(a, b) {
|
|
146
147
|
if (a === b) return true;
|
|
147
148
|
if (a == null || b == null || typeof a !== "object" || typeof b !== "object") return false;
|
|
148
|
-
if (a instanceof Date && b instanceof Date) return a
|
|
149
|
-
if (a instanceof RegExp && b instanceof RegExp) return a
|
|
150
|
-
if (a instanceof Set && b instanceof Set) return a
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (a
|
|
154
|
-
|
|
155
|
-
].every(([k, v]) => isEqual(v, b.get(k)));
|
|
156
|
-
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) return isEqual(new Uint8Array(a), new Uint8Array(b));
|
|
157
|
-
if (Array.isArray(a) && Array.isArray(b)) return a.length === b.length && a.every((v, i) => isEqual(v, b[i]));
|
|
158
|
-
return Object.keys(a).length === Object.keys(b).length && Object.keys(a).every((key) => isEqual(a[key], b[key]));
|
|
149
|
+
if (a instanceof Date && b instanceof Date) return equalDates(a, b);
|
|
150
|
+
if (a instanceof RegExp && b instanceof RegExp) return equalRegExp(a, b);
|
|
151
|
+
if (a instanceof Set && b instanceof Set) return equalSet(a, b);
|
|
152
|
+
if (a instanceof Map && b instanceof Map) return equalMap(a, b);
|
|
153
|
+
if (a instanceof ArrayBuffer && b instanceof ArrayBuffer) return equalArrayBuffer(a, b);
|
|
154
|
+
if (Array.isArray(a) && Array.isArray(b)) return equalArray(a, b);
|
|
155
|
+
return equalPlainObjects(a, b);
|
|
159
156
|
}
|
|
160
157
|
__name(isEqual, "isEqual");
|
|
158
|
+
function equalDates(a, b) {
|
|
159
|
+
return a.getTime() === b.getTime();
|
|
160
|
+
}
|
|
161
|
+
__name(equalDates, "equalDates");
|
|
162
|
+
function equalRegExp(a, b) {
|
|
163
|
+
return a.source === b.source && a.flags === b.flags;
|
|
164
|
+
}
|
|
165
|
+
__name(equalRegExp, "equalRegExp");
|
|
166
|
+
function equalSet(a, b) {
|
|
167
|
+
if (a.size !== b.size) return false;
|
|
168
|
+
for (const v of a) if (!b.has(v)) return false;
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
__name(equalSet, "equalSet");
|
|
172
|
+
function equalMap(a, b) {
|
|
173
|
+
if (a.size !== b.size) return false;
|
|
174
|
+
for (const [k, v] of a) {
|
|
175
|
+
if (!b.has(k)) return false;
|
|
176
|
+
if (!isEqual(v, b.get(k))) return false;
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
__name(equalMap, "equalMap");
|
|
181
|
+
function equalArrayBuffer(a, b) {
|
|
182
|
+
return isEqual(new Uint8Array(a), new Uint8Array(b));
|
|
183
|
+
}
|
|
184
|
+
__name(equalArrayBuffer, "equalArrayBuffer");
|
|
185
|
+
function equalArray(a, b) {
|
|
186
|
+
if (a.length !== b.length) return false;
|
|
187
|
+
for (let i = 0; i < a.length; i++) if (!isEqual(a[i], b[i])) return false;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
__name(equalArray, "equalArray");
|
|
191
|
+
function equalPlainObjects(a, b) {
|
|
192
|
+
const aKeys = Object.keys(a);
|
|
193
|
+
const bKeys = Object.keys(b);
|
|
194
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
195
|
+
for (const key of aKeys) {
|
|
196
|
+
if (!Object.hasOwn(b, key)) return false;
|
|
197
|
+
if (!isEqual(a[key], b[key])) return false;
|
|
198
|
+
}
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
__name(equalPlainObjects, "equalPlainObjects");
|
|
161
202
|
function filterObject(obj, predicate) {
|
|
162
203
|
return Object.fromEntries(Object.entries(obj).filter(([key, value]) => predicate(value, key, obj)));
|
|
163
204
|
}
|
|
@@ -170,72 +211,75 @@ function mapObject(obj, mapFn) {
|
|
|
170
211
|
}
|
|
171
212
|
__name(mapObject, "mapObject");
|
|
172
213
|
function _deepClone(value, seen) {
|
|
173
|
-
if (typeof value === "function" || typeof value === "symbol")
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (value
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
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
|
-
|
|
223
|
-
}
|
|
224
|
-
const typed = value;
|
|
225
|
-
const buf = _deepClone(typed.buffer, seen);
|
|
226
|
-
const clone = new typed.constructor(buf, typed.byteOffset, typed.length);
|
|
227
|
-
seen.set(value, clone);
|
|
228
|
-
return clone;
|
|
229
|
-
}
|
|
230
|
-
if (value instanceof ArrayBuffer) {
|
|
231
|
-
result = value.slice(0);
|
|
232
|
-
seen.set(value, result);
|
|
233
|
-
return result;
|
|
214
|
+
if (typeof value === "function" || typeof value === "symbol") return value;
|
|
215
|
+
if (value === null || typeof value !== "object") return value;
|
|
216
|
+
if (seen.has(value)) return seen.get(value);
|
|
217
|
+
if (Array.isArray(value)) return cloneArray(value, seen);
|
|
218
|
+
if (value instanceof Date) return cloneDate(value);
|
|
219
|
+
if (value instanceof Map) return cloneMap(value, seen);
|
|
220
|
+
if (value instanceof Set) return cloneSet(value, seen);
|
|
221
|
+
if (value instanceof RegExp) return cloneRegExp(value);
|
|
222
|
+
if (ArrayBuffer.isView(value)) return cloneArrayBufferView(value, seen);
|
|
223
|
+
if (value instanceof ArrayBuffer) return cloneArrayBuffer(value, seen);
|
|
224
|
+
return cloneObject(value, seen);
|
|
225
|
+
}
|
|
226
|
+
__name(_deepClone, "_deepClone");
|
|
227
|
+
function cloneArray(arr, seen) {
|
|
228
|
+
const result = [];
|
|
229
|
+
seen.set(arr, result);
|
|
230
|
+
for (const item of arr) result.push(_deepClone(item, seen));
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
__name(cloneArray, "cloneArray");
|
|
234
|
+
function cloneDate(d) {
|
|
235
|
+
const r = new Date(d.getTime());
|
|
236
|
+
return r;
|
|
237
|
+
}
|
|
238
|
+
__name(cloneDate, "cloneDate");
|
|
239
|
+
function cloneMap(m, seen) {
|
|
240
|
+
const result = /* @__PURE__ */ new Map();
|
|
241
|
+
seen.set(m, result);
|
|
242
|
+
for (const [k, v] of m) result.set(_deepClone(k, seen), _deepClone(v, seen));
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
__name(cloneMap, "cloneMap");
|
|
246
|
+
function cloneSet(s, seen) {
|
|
247
|
+
const result = /* @__PURE__ */ new Set();
|
|
248
|
+
seen.set(s, result);
|
|
249
|
+
for (const v of s) result.add(_deepClone(v, seen));
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
__name(cloneSet, "cloneSet");
|
|
253
|
+
function cloneRegExp(r) {
|
|
254
|
+
const result = new RegExp(r.source, r.flags);
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
__name(cloneRegExp, "cloneRegExp");
|
|
258
|
+
function cloneArrayBufferView(view, seen) {
|
|
259
|
+
if (view instanceof DataView) {
|
|
260
|
+
const buf2 = _deepClone(view.buffer, seen);
|
|
261
|
+
const clone2 = new DataView(buf2, view.byteOffset, view.byteLength);
|
|
262
|
+
seen.set(view, clone2);
|
|
263
|
+
return clone2;
|
|
234
264
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
265
|
+
const typed = view;
|
|
266
|
+
const buf = _deepClone(typed.buffer, seen);
|
|
267
|
+
const clone = new typed.constructor(buf, typed.byteOffset, typed.length);
|
|
268
|
+
seen.set(view, clone);
|
|
269
|
+
return clone;
|
|
270
|
+
}
|
|
271
|
+
__name(cloneArrayBufferView, "cloneArrayBufferView");
|
|
272
|
+
function cloneArrayBuffer(buf, seen) {
|
|
273
|
+
const result = buf.slice(0);
|
|
274
|
+
seen.set(buf, result);
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
__name(cloneArrayBuffer, "cloneArrayBuffer");
|
|
278
|
+
function cloneObject(obj, seen) {
|
|
279
|
+
const result = Object.create(Object.getPrototypeOf(obj));
|
|
280
|
+
seen.set(obj, result);
|
|
281
|
+
for (const key of Reflect.ownKeys(obj)) {
|
|
282
|
+
const desc = Object.getOwnPropertyDescriptor(obj, key);
|
|
239
283
|
if (desc?.get || desc?.set) {
|
|
240
284
|
Object.defineProperty(result, key, {
|
|
241
285
|
get: desc.get,
|
|
@@ -245,7 +289,7 @@ function _deepClone(value, seen) {
|
|
|
245
289
|
});
|
|
246
290
|
} else {
|
|
247
291
|
Object.defineProperty(result, key, {
|
|
248
|
-
value: _deepClone(
|
|
292
|
+
value: _deepClone(obj[key], seen),
|
|
249
293
|
writable: desc?.writable ?? true,
|
|
250
294
|
enumerable: desc?.enumerable ?? true,
|
|
251
295
|
configurable: desc?.configurable ?? true
|
|
@@ -254,7 +298,7 @@ function _deepClone(value, seen) {
|
|
|
254
298
|
}
|
|
255
299
|
return result;
|
|
256
300
|
}
|
|
257
|
-
__name(
|
|
301
|
+
__name(cloneObject, "cloneObject");
|
|
258
302
|
function deepClone(value) {
|
|
259
303
|
const seen = /* @__PURE__ */ new WeakMap();
|
|
260
304
|
return _deepClone(value, seen);
|
|
@@ -287,6 +331,33 @@ function getAllPaths(obj, parentPath = "") {
|
|
|
287
331
|
});
|
|
288
332
|
}
|
|
289
333
|
__name(getAllPaths, "getAllPaths");
|
|
334
|
+
function invert(obj) {
|
|
335
|
+
if (!isObject(obj)) return {};
|
|
336
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
|
|
337
|
+
String(v),
|
|
338
|
+
k
|
|
339
|
+
]));
|
|
340
|
+
}
|
|
341
|
+
__name(invert, "invert");
|
|
342
|
+
function invertBy(obj, keyFn) {
|
|
343
|
+
if (!isObject(obj)) return {};
|
|
344
|
+
const result = {};
|
|
345
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
346
|
+
const newKey = keyFn(value);
|
|
347
|
+
if (!result[newKey]) result[newKey] = [];
|
|
348
|
+
result[newKey].push(key);
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
__name(invertBy, "invertBy");
|
|
353
|
+
function transform(obj, fn) {
|
|
354
|
+
if (!isObject(obj)) return {};
|
|
355
|
+
return Object.fromEntries(Object.entries(obj).map(([k, v]) => [
|
|
356
|
+
k,
|
|
357
|
+
fn(v, k)
|
|
358
|
+
]));
|
|
359
|
+
}
|
|
360
|
+
__name(transform, "transform");
|
|
290
361
|
|
|
291
362
|
exports.deepClone = deepClone;
|
|
292
363
|
exports.deepFreeze = deepFreeze;
|
|
@@ -295,6 +366,8 @@ exports.filterObject = filterObject;
|
|
|
295
366
|
exports.flattenObject = flattenObject;
|
|
296
367
|
exports.getAllPaths = getAllPaths;
|
|
297
368
|
exports.getValueByPath = getValueByPath;
|
|
369
|
+
exports.invert = invert;
|
|
370
|
+
exports.invertBy = invertBy;
|
|
298
371
|
exports.isEqual = isEqual;
|
|
299
372
|
exports.isObjEmpty = isObjEmpty;
|
|
300
373
|
exports.isObject = isObject;
|
|
@@ -303,3 +376,4 @@ exports.mapObject = mapObject;
|
|
|
303
376
|
exports.omit = omit;
|
|
304
377
|
exports.pick = pick;
|
|
305
378
|
exports.setValueByPath = setValueByPath;
|
|
379
|
+
exports.transform = transform;
|
|
@@ -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
|
|
@@ -156,5 +156,41 @@ declare function deepFreeze<T extends object>(obj: T): Readonly<T>;
|
|
|
156
156
|
* @returns {string[]} Array of all paths in dot notation.
|
|
157
157
|
*/
|
|
158
158
|
declare function getAllPaths(obj: Record<string, any>, parentPath?: string): string[];
|
|
159
|
+
/**
|
|
160
|
+
* Inverts an object's keys and values.
|
|
161
|
+
*
|
|
162
|
+
* @template T
|
|
163
|
+
* @param {T} obj - The object to invert.
|
|
164
|
+
* @returns {Record<string, string>} Inverted object.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* invert({ a: 'x', b: 'y' }); // { x: 'a', y: 'b' }
|
|
168
|
+
*/
|
|
169
|
+
declare function invert<T extends Record<string, any>>(obj: T): Record<string, string>;
|
|
170
|
+
/**
|
|
171
|
+
* Inverts an object using a function to generate keys from values.
|
|
172
|
+
*
|
|
173
|
+
* @template T
|
|
174
|
+
* @param {T} obj - The object to invert.
|
|
175
|
+
* @param {(value: any) => string} keyFn - Function to generate new keys.
|
|
176
|
+
* @returns {Record<string, string[]>} Inverted object with arrays of keys.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* invertBy({ a: 1, b: 2, c: 1 }, v => String(v)); // { '1': ['a', 'c'], '2': ['b'] }
|
|
180
|
+
*/
|
|
181
|
+
declare function invertBy<T extends Record<string, any>>(obj: T, keyFn: (value: any) => string): Record<string, string[]>;
|
|
182
|
+
/**
|
|
183
|
+
* Transforms object values using a mapping function.
|
|
184
|
+
*
|
|
185
|
+
* @template T
|
|
186
|
+
* @template U
|
|
187
|
+
* @param {T} obj - The source object.
|
|
188
|
+
* @param {(value: any, key: string) => U} fn - Transformation function.
|
|
189
|
+
* @returns {Record<string, U>} Object with transformed values.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* transform({ a: 1, b: 2 }, v => v * 2); // { a: 2, b: 4 }
|
|
193
|
+
*/
|
|
194
|
+
declare function transform<T extends Record<string, any>, U>(obj: T, fn: (value: any, key: string) => U): Record<string, U>;
|
|
159
195
|
|
|
160
|
-
export { deepClone, deepFreeze, deepObjMerge, filterObject, flattenObject, getAllPaths, getValueByPath, isEqual, isObjEmpty, isObject, isPlainObject, mapObject, omit, pick, setValueByPath };
|
|
196
|
+
export { deepClone, deepFreeze, deepObjMerge, filterObject, flattenObject, getAllPaths, getValueByPath, invert, invertBy, isEqual, isObjEmpty, isObject, isPlainObject, mapObject, omit, pick, setValueByPath, transform };
|