@cyberskill/shared 3.2.0 → 3.3.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/dist/config/commitlint/index.js +8 -9
- package/dist/config/commitlint/index.js.map +1 -1
- package/dist/config/config.type.js +8 -5
- package/dist/config/config.type.js.map +1 -1
- package/dist/config/config.util.js +33 -42
- package/dist/config/config.util.js.map +1 -1
- package/dist/config/env/env.constant.js +6 -5
- package/dist/config/env/env.constant.js.map +1 -1
- package/dist/config/env/env.util.js +26 -27
- package/dist/config/env/env.util.js.map +1 -1
- package/dist/config/env/index.js +2 -7
- package/dist/config/eslint/index.js +23 -19
- package/dist/config/eslint/index.js.map +1 -1
- package/dist/config/graphql-codegen/graphql-codegen.util.js +30 -38
- package/dist/config/graphql-codegen/graphql-codegen.util.js.map +1 -1
- package/dist/config/graphql-codegen/index.js +2 -5
- package/dist/config/index.js +3 -7
- package/dist/config/lint-staged/index.js +8 -7
- package/dist/config/lint-staged/index.js.map +1 -1
- package/dist/config/storybook/index.js +2 -6
- package/dist/config/storybook/storybook.main.js +19 -18
- package/dist/config/storybook/storybook.main.js.map +1 -1
- package/dist/config/storybook/storybook.preview.js +31 -37
- package/dist/config/storybook/storybook.preview.js.map +1 -1
- package/dist/config/vitest/index.js +3 -7
- package/dist/config/vitest/vitest.e2e.js +14 -17
- package/dist/config/vitest/vitest.e2e.js.map +1 -1
- package/dist/config/vitest/vitest.unit.js +31 -32
- package/dist/config/vitest/vitest.unit.js.map +1 -1
- package/dist/constant/common.js +6 -5
- package/dist/constant/common.js.map +1 -1
- package/dist/constant/index.js +3 -7
- package/dist/constant/response-status.d.ts +186 -186
- package/dist/constant/response-status.js +254 -253
- package/dist/constant/response-status.js.map +1 -1
- package/dist/node/apollo-server/apollo-server.util.js +27 -29
- package/dist/node/apollo-server/apollo-server.util.js.map +1 -1
- package/dist/node/apollo-server/index.js +2 -7
- package/dist/node/cli/index.js +112 -113
- package/dist/node/cli/index.js.map +1 -1
- package/dist/node/command/command.type.js +8 -5
- package/dist/node/command/command.type.js.map +1 -1
- package/dist/node/command/command.util.js +136 -149
- package/dist/node/command/command.util.js.map +1 -1
- package/dist/node/command/index.js +3 -12
- package/dist/node/express/express.type.d.ts +11 -0
- package/dist/node/express/express.type.js +2 -0
- package/dist/node/express/express.util.js +74 -65
- package/dist/node/express/express.util.js.map +1 -1
- package/dist/node/express/index.js +3 -14
- package/dist/node/fs/fs.util.js +27 -51
- package/dist/node/fs/fs.util.js.map +1 -1
- package/dist/node/fs/index.js +2 -19
- package/dist/node/log/index.js +2 -8
- package/dist/node/log/log.type.js +8 -5
- package/dist/node/log/log.type.js.map +1 -1
- package/dist/node/log/log.util.js +51 -68
- package/dist/node/log/log.util.js.map +1 -1
- package/dist/node/mongo/index.js +8 -26
- package/dist/node/mongo/mongo.constant.js +6 -6
- package/dist/node/mongo/mongo.constant.js.map +1 -1
- package/dist/node/mongo/mongo.controller.mongoose.d.ts +6 -1
- package/dist/node/mongo/mongo.controller.mongoose.js +333 -467
- package/dist/node/mongo/mongo.controller.mongoose.js.map +1 -1
- package/dist/node/mongo/mongo.controller.native.js +153 -212
- package/dist/node/mongo/mongo.controller.native.js.map +1 -1
- package/dist/node/mongo/mongo.dynamic-populate.js +164 -192
- package/dist/node/mongo/mongo.dynamic-populate.js.map +1 -1
- package/dist/node/mongo/mongo.populate.js +229 -262
- package/dist/node/mongo/mongo.populate.js.map +1 -1
- package/dist/node/mongo/mongo.type.js +8 -17
- package/dist/node/mongo/mongo.type.js.map +1 -1
- package/dist/node/mongo/mongo.util.js +134 -293
- package/dist/node/mongo/mongo.util.js.map +1 -1
- package/dist/node/package/index.js +3 -11
- package/dist/node/package/package.type.js +8 -5
- package/dist/node/package/package.type.js.map +1 -1
- package/dist/node/package/package.util.js +216 -225
- package/dist/node/package/package.util.js.map +1 -1
- package/dist/node/path/index.js +3 -58
- package/dist/node/path/path.constant.js +211 -298
- package/dist/node/path/path.constant.js.map +1 -1
- package/dist/node/path/path.util.js +13 -16
- package/dist/node/path/path.util.js.map +1 -1
- package/dist/node/storage/index.js +3 -10
- package/dist/node/storage/storage.constant.js +6 -8
- package/dist/node/storage/storage.constant.js.map +1 -1
- package/dist/node/storage/storage.util.js +127 -178
- package/dist/node/storage/storage.util.js.map +1 -1
- package/dist/node/upload/index.js +4 -16
- package/dist/node/upload/upload.constant.js +58 -32
- package/dist/node/upload/upload.constant.js.map +1 -1
- package/dist/node/upload/upload.type.js +8 -5
- package/dist/node/upload/upload.type.js.map +1 -1
- package/dist/node/upload/upload.util.js +125 -137
- package/dist/node/upload/upload.util.js.map +1 -1
- package/dist/node/ws/index.js +2 -6
- package/dist/node/ws/ws.type.d.ts +7 -8
- package/dist/node/ws/ws.util.js +46 -44
- package/dist/node/ws/ws.util.js.map +1 -1
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js +8 -0
- package/dist/node_modules/.pnpm/vitest@4.1.0_@types_node@25.5.0_jsdom@29.0.0_@noble_hashes@1.8.0__vite@8.0.0_@types_nod_53aa4254f295b3c40bb8f17b6ab226b5/node_modules/vitest/dist/config.js.map +1 -0
- package/dist/react/apollo-client/apollo-client.component.js +16 -18
- package/dist/react/apollo-client/apollo-client.component.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.constant.js +6 -5
- package/dist/react/apollo-client/apollo-client.constant.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.context.js +10 -13
- package/dist/react/apollo-client/apollo-client.context.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.module.scss.js +8 -7
- package/dist/react/apollo-client/apollo-client.module.scss.js.map +1 -1
- package/dist/react/apollo-client/apollo-client.util.js +57 -75
- package/dist/react/apollo-client/apollo-client.util.js.map +1 -1
- package/dist/react/apollo-client/index.js +7 -30
- package/dist/react/apollo-client/links/index.js +2 -5
- package/dist/react/apollo-client/links/upload.js +63 -107
- package/dist/react/apollo-client/links/upload.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +14 -16
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js +8 -7
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.js.map +1 -1
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js +14 -14
- package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.js.map +1 -1
- package/dist/react/apollo-client-nextjs/index.js +3 -7
- package/dist/react/apollo-error/apollo-error.component.js +57 -69
- package/dist/react/apollo-error/apollo-error.component.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.context.js +7 -6
- package/dist/react/apollo-error/apollo-error.context.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.hook.js +10 -10
- package/dist/react/apollo-error/apollo-error.hook.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.module.scss.js +15 -11
- package/dist/react/apollo-error/apollo-error.module.scss.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.provider.js +31 -25
- package/dist/react/apollo-error/apollo-error.provider.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.util.js +14 -16
- package/dist/react/apollo-error/apollo-error.util.js.map +1 -1
- package/dist/react/apollo-error/index.js +5 -15
- package/dist/react/i18next/i18next.hook.js +7 -6
- package/dist/react/i18next/i18next.hook.js.map +1 -1
- package/dist/react/i18next/i18next.util.js +9 -8
- package/dist/react/i18next/i18next.util.js.map +1 -1
- package/dist/react/i18next/index.js +3 -7
- package/dist/react/loading/index.js +3 -9
- package/dist/react/loading/loading.component.js +47 -48
- package/dist/react/loading/loading.component.js.map +1 -1
- package/dist/react/loading/loading.context.js +7 -6
- package/dist/react/loading/loading.context.js.map +1 -1
- package/dist/react/loading/loading.hook.js +11 -11
- package/dist/react/loading/loading.hook.js.map +1 -1
- package/dist/react/loading/loading.module.scss.js +18 -15
- package/dist/react/loading/loading.module.scss.js.map +1 -1
- package/dist/react/loading/loading.provider.js +26 -18
- package/dist/react/loading/loading.provider.js.map +1 -1
- package/dist/react/log/index.js +2 -6
- package/dist/react/log/log.util.d.ts +8 -0
- package/dist/react/log/log.util.js +33 -29
- package/dist/react/log/log.util.js.map +1 -1
- package/dist/react/next-intl/index.js +6 -14
- package/dist/react/next-intl/next-intl.constant.js +16 -15
- package/dist/react/next-intl/next-intl.constant.js.map +1 -1
- package/dist/react/next-intl/next-intl.context.js +7 -6
- package/dist/react/next-intl/next-intl.context.js.map +1 -1
- package/dist/react/next-intl/next-intl.hoc.js +20 -23
- package/dist/react/next-intl/next-intl.hoc.js.map +1 -1
- package/dist/react/next-intl/next-intl.hook.js +13 -14
- package/dist/react/next-intl/next-intl.hook.js.map +1 -1
- package/dist/react/next-intl/next-intl.provider.js +28 -23
- package/dist/react/next-intl/next-intl.provider.js.map +1 -1
- package/dist/react/storage/index.js +3 -7
- package/dist/react/storage/storage.hook.js +61 -58
- package/dist/react/storage/storage.hook.js.map +1 -1
- package/dist/react/storage/storage.util.js +36 -68
- package/dist/react/storage/storage.util.js.map +1 -1
- package/dist/react/toast/index.js +2 -6
- package/dist/react/userback/index.js +2 -5
- package/dist/react/userback/userback.component.js +27 -27
- package/dist/react/userback/userback.component.js.map +1 -1
- package/dist/style.css +2 -1
- package/dist/typescript/common.type.js +8 -5
- package/dist/typescript/common.type.js.map +1 -1
- package/dist/typescript/index.js +2 -5
- package/dist/util/common/common.util.js +119 -48
- package/dist/util/common/common.util.js.map +1 -1
- package/dist/util/common/index.js +2 -9
- package/dist/util/index.js +6 -27
- package/dist/util/object/index.d.ts +3 -0
- package/dist/util/object/index.js +2 -10
- package/dist/util/object/object.util.js +94 -128
- package/dist/util/object/object.util.js.map +1 -1
- package/dist/util/serializer/index.js +2 -5
- package/dist/util/serializer/serializer.util.js +73 -78
- package/dist/util/serializer/serializer.util.js.map +1 -1
- package/dist/util/string/index.d.ts +3 -0
- package/dist/util/string/index.js +2 -10
- package/dist/util/string/string.util.js +59 -71
- package/dist/util/string/string.util.js.map +1 -1
- package/dist/util/validate/index.d.ts +3 -0
- package/dist/util/validate/index.js +2 -5
- package/dist/util/validate/validate.util.js +13 -39
- package/dist/util/validate/validate.util.js.map +1 -1
- package/package.json +29 -27
- package/dist/config/env/index.js.map +0 -1
- package/dist/config/graphql-codegen/index.js.map +0 -1
- package/dist/config/index.js.map +0 -1
- package/dist/config/storybook/index.js.map +0 -1
- package/dist/config/vitest/index.js.map +0 -1
- package/dist/constant/index.js.map +0 -1
- package/dist/node/apollo-server/index.js.map +0 -1
- package/dist/node/command/index.js.map +0 -1
- package/dist/node/express/index.js.map +0 -1
- package/dist/node/fs/index.js.map +0 -1
- package/dist/node/log/index.js.map +0 -1
- package/dist/node/mongo/index.js.map +0 -1
- package/dist/node/package/index.js.map +0 -1
- package/dist/node/path/index.js.map +0 -1
- package/dist/node/storage/index.js.map +0 -1
- package/dist/node/upload/index.js.map +0 -1
- package/dist/node/ws/index.js.map +0 -1
- package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js +0 -7
- package/dist/node_modules/.pnpm/vitest@4.0.18_@types_node@25.3.5_jiti@2.6.1_jsdom@28.1.0_@noble_hashes@1.8.0__sass@1.97.3_tsx@4.21.0_yaml@2.8.2/node_modules/vitest/dist/config.js.map +0 -1
- package/dist/react/apollo-client/index.js.map +0 -1
- package/dist/react/apollo-client/links/index.js.map +0 -1
- package/dist/react/apollo-client-nextjs/index.js.map +0 -1
- package/dist/react/apollo-error/index.js.map +0 -1
- package/dist/react/i18next/index.js.map +0 -1
- package/dist/react/loading/index.js.map +0 -1
- package/dist/react/log/index.js.map +0 -1
- package/dist/react/next-intl/index.js.map +0 -1
- package/dist/react/storage/index.js.map +0 -1
- package/dist/react/toast/index.js.map +0 -1
- package/dist/react/userback/index.js.map +0 -1
- package/dist/typescript/index.js.map +0 -1
- package/dist/util/common/index.js.map +0 -1
- package/dist/util/index.js.map +0 -1
- package/dist/util/object/index.js.map +0 -1
- package/dist/util/serializer/index.js.map +0 -1
- package/dist/util/string/index.js.map +0 -1
- package/dist/util/validate/index.js.map +0 -1
|
@@ -1,54 +1,125 @@
|
|
|
1
|
-
import { E_Environment as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { E_Environment as e } from "../../typescript/common.type.js";
|
|
2
|
+
//#region src/util/common/common.util.ts
|
|
3
|
+
var t = {
|
|
4
|
+
a: [
|
|
5
|
+
"à",
|
|
6
|
+
"á",
|
|
7
|
+
"ạ",
|
|
8
|
+
"ả",
|
|
9
|
+
"ã",
|
|
10
|
+
"â",
|
|
11
|
+
"ầ",
|
|
12
|
+
"ấ",
|
|
13
|
+
"ậ",
|
|
14
|
+
"ẩ",
|
|
15
|
+
"ẫ",
|
|
16
|
+
"ă",
|
|
17
|
+
"ằ",
|
|
18
|
+
"ắ",
|
|
19
|
+
"ặ",
|
|
20
|
+
"ẳ",
|
|
21
|
+
"ẵ"
|
|
22
|
+
],
|
|
23
|
+
e: [
|
|
24
|
+
"è",
|
|
25
|
+
"é",
|
|
26
|
+
"ẹ",
|
|
27
|
+
"ẻ",
|
|
28
|
+
"ẽ",
|
|
29
|
+
"ê",
|
|
30
|
+
"ề",
|
|
31
|
+
"ế",
|
|
32
|
+
"ệ",
|
|
33
|
+
"ể",
|
|
34
|
+
"ễ"
|
|
35
|
+
],
|
|
36
|
+
i: [
|
|
37
|
+
"ì",
|
|
38
|
+
"í",
|
|
39
|
+
"ị",
|
|
40
|
+
"ỉ",
|
|
41
|
+
"ĩ"
|
|
42
|
+
],
|
|
43
|
+
o: [
|
|
44
|
+
"ò",
|
|
45
|
+
"ó",
|
|
46
|
+
"ọ",
|
|
47
|
+
"ỏ",
|
|
48
|
+
"õ",
|
|
49
|
+
"ô",
|
|
50
|
+
"ồ",
|
|
51
|
+
"ố",
|
|
52
|
+
"ộ",
|
|
53
|
+
"ổ",
|
|
54
|
+
"ỗ",
|
|
55
|
+
"ơ",
|
|
56
|
+
"ờ",
|
|
57
|
+
"ớ",
|
|
58
|
+
"ợ",
|
|
59
|
+
"ở",
|
|
60
|
+
"ỡ"
|
|
61
|
+
],
|
|
62
|
+
u: [
|
|
63
|
+
"ù",
|
|
64
|
+
"ú",
|
|
65
|
+
"ụ",
|
|
66
|
+
"ủ",
|
|
67
|
+
"ũ",
|
|
68
|
+
"ư",
|
|
69
|
+
"ừ",
|
|
70
|
+
"ứ",
|
|
71
|
+
"ự",
|
|
72
|
+
"ử",
|
|
73
|
+
"ữ"
|
|
74
|
+
],
|
|
75
|
+
y: [
|
|
76
|
+
"ỳ",
|
|
77
|
+
"ý",
|
|
78
|
+
"ỵ",
|
|
79
|
+
"ỷ",
|
|
80
|
+
"ỹ"
|
|
81
|
+
],
|
|
82
|
+
d: ["đ"]
|
|
83
|
+
}, n = Object.entries(t).reduce((e, [t, n]) => (e[t.toUpperCase()] = n.map((e) => e.toUpperCase()), e), {}), r = {
|
|
84
|
+
...t,
|
|
85
|
+
...n
|
|
86
|
+
}, i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Set();
|
|
87
|
+
Object.entries(r).forEach(([e, t]) => {
|
|
88
|
+
let n = `(${[e, ...t].join("|")})`;
|
|
89
|
+
[e, ...t].forEach((e) => {
|
|
90
|
+
i.set(e, n), a.add(e);
|
|
91
|
+
});
|
|
19
92
|
});
|
|
20
|
-
|
|
21
|
-
function
|
|
22
|
-
|
|
93
|
+
var o = [...a].join(""), s = RegExp(`[${o}]`, "g"), c = /[.*+?^${}()|[\]\\]/g;
|
|
94
|
+
function l(e) {
|
|
95
|
+
return e.replace(c, "\\$&");
|
|
23
96
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
97
|
+
function u(e) {
|
|
98
|
+
return e = l(e), e.replace(s, (e) => i.get(e) || e);
|
|
26
99
|
}
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
100
|
+
var d = /\p{Diacritic}/gu;
|
|
101
|
+
function f(e) {
|
|
102
|
+
return e.normalize("NFD").replace(d, "");
|
|
30
103
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return r;
|
|
104
|
+
function p(e, t) {
|
|
105
|
+
if (!t) return [...new Set(e)];
|
|
106
|
+
let n = /* @__PURE__ */ new Set(), r = [];
|
|
107
|
+
for (let i of e) {
|
|
108
|
+
let e = t(i);
|
|
109
|
+
n.has(e) || (n.add(e), r.push(i));
|
|
110
|
+
}
|
|
111
|
+
return r;
|
|
40
112
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
113
|
+
function m(t) {
|
|
114
|
+
let { NODE_ENV: n = e.DEVELOPMENT, NODE_ENV_MODE: r = e.DEVELOPMENT } = t, i = n === e.DEVELOPMENT && r === e.DEVELOPMENT, a = n === e.PRODUCTION && r === e.STAGING, o = n === e.PRODUCTION && r === e.PRODUCTION;
|
|
115
|
+
if (n === e.PRODUCTION && r === e.DEVELOPMENT) throw Error("NODE_ENV_MODE must be set to staging or production in production environment");
|
|
116
|
+
return {
|
|
117
|
+
IS_DEV: i,
|
|
118
|
+
IS_STAG: a,
|
|
119
|
+
IS_PROD: o
|
|
120
|
+
};
|
|
46
121
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
P as removeAccent,
|
|
52
|
-
R as uniqueArray
|
|
53
|
-
};
|
|
54
|
-
//# sourceMappingURL=common.util.js.map
|
|
122
|
+
//#endregion
|
|
123
|
+
export { l as escapeRegExp, m as mapEnvironment, u as regexSearchMapper, f as removeAccent, p as uniqueArray };
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=common.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.util.js","sources":["../../../src/util/common/common.util.ts"],"sourcesContent":["import { E_Environment } from '#typescript/index.js';\n\nimport type { I_EnvFlags, I_NodeEnvInput } from './common.type.js';\n\nconst charMap: Record<string, string[]> = {\n a: ['à', 'á', 'ạ', 'ả', 'ã', 'â', 'ầ', 'ấ', 'ậ', 'ẩ', 'ẫ', 'ă', 'ằ', 'ắ', 'ặ', 'ẳ', 'ẵ'],\n e: ['è', 'é', 'ẹ', 'ẻ', 'ẽ', 'ê', 'ề', 'ế', 'ệ', 'ể', 'ễ'],\n i: ['ì', 'í', 'ị', 'ỉ', 'ĩ'],\n o: ['ò', 'ó', 'ọ', 'ỏ', 'õ', 'ô', 'ồ', 'ố', 'ộ', 'ổ', 'ỗ', 'ơ', 'ờ', 'ớ', 'ợ', 'ở', 'ỡ'],\n u: ['ù', 'ú', 'ụ', 'ủ', 'ũ', 'ư', 'ừ', 'ứ', 'ự', 'ử', 'ữ'],\n y: ['ỳ', 'ý', 'ỵ', 'ỷ', 'ỹ'],\n d: ['đ'],\n};\n\nconst upperCharMap: Record<string, string[]> = Object.entries(charMap).reduce(\n (map, [key, value]) => {\n map[key.toUpperCase()] = value.map(char => char.toUpperCase());\n return map;\n },\n {} as Record<string, string[]>,\n);\n\nconst combinedMap = { ...charMap, ...upperCharMap };\n\n// Pre-compute replacement map and search regex for better performance\n// This avoids rebuilding regexes and maps on every function call\nconst replacementMap = new Map<string, string>();\nconst charsToMatch = new Set<string>();\n\nObject.entries(combinedMap).forEach(([baseChar, variations]) => {\n // The replacement pattern is the same for the base char and all its variations\n // Example: 'a', 'à', 'á'... all map to '(a|à|á...)'\n const replacement = `(${[baseChar, ...variations].join('|')})`;\n\n [baseChar, ...variations].forEach((char) => {\n replacementMap.set(char, replacement);\n charsToMatch.add(char);\n });\n});\n\n// Construct a single regex that matches any character in our map\nconst patternString = [...charsToMatch].join('');\n// We use a character class regex: [abc...]\n// eslint-disable-next-line regexp/no-empty-character-class -- regex is built dynamically from precomputed charMap\nconst searchRegex = new RegExp(`[${patternString}]`, 'g');\n\nconst RE_ESCAPE_REGEXP = /[.*+?^${}()|[\\]\\\\]/g;\n\n/**\n * Escapes special characters in a string for use in a regular expression.\n * This function escapes characters that have special meaning in regex (e.g., ., *, +, ?, etc.)\n * so they are treated as literal characters.\n *\n * @param str - The string to escape.\n * @returns The escaped string safe for use in a RegExp.\n */\nexport function escapeRegExp(str: string): string {\n return str.replace(RE_ESCAPE_REGEXP, '\\\\$&');\n}\n\n/**\n * Convert a string to a regex pattern that matches the string and its accented variations.\n * This function normalizes the input string and creates a regex pattern that can match\n * both the original characters and their accented equivalents.\n *\n * Optimization: Uses pre-computed regex and map to perform replacement in a single pass (O(N)),\n * instead of iterating through all character groups (O(K*N)).\n * Removed unnecessary NFD normalization which improves performance and fixes\n * matching against NFC target strings.\n *\n * @param str - The string to convert to a regex pattern.\n * @returns The regex pattern as a string that matches the original string and its accented variations.\n */\nexport function regexSearchMapper(str: string) {\n str = escapeRegExp(str);\n return str.replace(searchRegex, match => replacementMap.get(match) || match);\n}\n\nconst RE_DIACRITIC = /\\p{Diacritic}/gu;\n\n/**\n * Remove accents from a string.\n * This function normalizes the string using NFD normalization and removes all diacritical marks.\n *\n * @param str - The string to remove accents from.\n * @returns The string without any accents or diacritical marks.\n */\nexport function removeAccent(str: string) {\n return str.normalize('NFD').replace(RE_DIACRITIC, '');\n}\n\n/**\n * Remove duplicates from an array based on a key function.\n * This function can remove duplicates either by comparing values directly (when no keyFn is provided)\n * or by using a custom key function to determine uniqueness.\n *\n * @param arr - The array to remove duplicates from.\n * @param keyFn - Optional function that returns a unique key for each item in the array.\n * @returns A new array with duplicates removed, maintaining the original order.\n */\nexport function uniqueArray<T>(\n arr: T[],\n keyFn?: (item: T) => string | number,\n): T[] {\n if (!keyFn) {\n return [...new Set(arr)];\n }\n\n const seen = new Set<string | number>();\n const result: T[] = [];\n\n for (const item of arr) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(item);\n }\n }\n\n return result;\n}\n\n/**\n * Map environment variables to boolean flags indicating the current environment.\n * This function takes NODE_ENV and NODE_ENV_MODE variables and returns flags\n * indicating whether the current environment is development, staging, or production.\n *\n * @param env - The environment variables object containing NODE_ENV and NODE_ENV_MODE.\n * @returns An object containing boolean flags for the environment (IS_DEV, IS_STAG, IS_PROD).\n * @throws {Error} When NODE_ENV is production but NODE_ENV_MODE is development.\n */\nexport function mapEnvironment(env: I_NodeEnvInput): I_EnvFlags {\n const { NODE_ENV = E_Environment.DEVELOPMENT, NODE_ENV_MODE = E_Environment.DEVELOPMENT } = env;\n\n const IS_DEV = NODE_ENV === E_Environment.DEVELOPMENT && NODE_ENV_MODE === E_Environment.DEVELOPMENT;\n const IS_STAG = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.STAGING;\n const IS_PROD = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.PRODUCTION;\n\n if (NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.DEVELOPMENT) {\n throw new Error('NODE_ENV_MODE must be set to staging or production in production environment');\n }\n\n return { IS_DEV, IS_STAG, IS_PROD };\n}\n"],"
|
|
1
|
+
{"version":3,"file":"common.util.js","names":[],"sources":["../../../src/util/common/common.util.ts"],"sourcesContent":["import { E_Environment } from '#typescript/index.js';\n\nimport type { I_EnvFlags, I_NodeEnvInput } from './common.type.js';\n\nconst charMap: Record<string, string[]> = {\n a: ['à', 'á', 'ạ', 'ả', 'ã', 'â', 'ầ', 'ấ', 'ậ', 'ẩ', 'ẫ', 'ă', 'ằ', 'ắ', 'ặ', 'ẳ', 'ẵ'],\n e: ['è', 'é', 'ẹ', 'ẻ', 'ẽ', 'ê', 'ề', 'ế', 'ệ', 'ể', 'ễ'],\n i: ['ì', 'í', 'ị', 'ỉ', 'ĩ'],\n o: ['ò', 'ó', 'ọ', 'ỏ', 'õ', 'ô', 'ồ', 'ố', 'ộ', 'ổ', 'ỗ', 'ơ', 'ờ', 'ớ', 'ợ', 'ở', 'ỡ'],\n u: ['ù', 'ú', 'ụ', 'ủ', 'ũ', 'ư', 'ừ', 'ứ', 'ự', 'ử', 'ữ'],\n y: ['ỳ', 'ý', 'ỵ', 'ỷ', 'ỹ'],\n d: ['đ'],\n};\n\nconst upperCharMap: Record<string, string[]> = Object.entries(charMap).reduce(\n (map, [key, value]) => {\n map[key.toUpperCase()] = value.map(char => char.toUpperCase());\n return map;\n },\n {} as Record<string, string[]>,\n);\n\nconst combinedMap = { ...charMap, ...upperCharMap };\n\n// Pre-compute replacement map and search regex for better performance\n// This avoids rebuilding regexes and maps on every function call\nconst replacementMap = new Map<string, string>();\nconst charsToMatch = new Set<string>();\n\nObject.entries(combinedMap).forEach(([baseChar, variations]) => {\n // The replacement pattern is the same for the base char and all its variations\n // Example: 'a', 'à', 'á'... all map to '(a|à|á...)'\n const replacement = `(${[baseChar, ...variations].join('|')})`;\n\n [baseChar, ...variations].forEach((char) => {\n replacementMap.set(char, replacement);\n charsToMatch.add(char);\n });\n});\n\n// Construct a single regex that matches any character in our map\nconst patternString = [...charsToMatch].join('');\n// We use a character class regex: [abc...]\n// eslint-disable-next-line regexp/no-empty-character-class -- regex is built dynamically from precomputed charMap\nconst searchRegex = new RegExp(`[${patternString}]`, 'g');\n\nconst RE_ESCAPE_REGEXP = /[.*+?^${}()|[\\]\\\\]/g;\n\n/**\n * Escapes special characters in a string for use in a regular expression.\n * This function escapes characters that have special meaning in regex (e.g., ., *, +, ?, etc.)\n * so they are treated as literal characters.\n *\n * @param str - The string to escape.\n * @returns The escaped string safe for use in a RegExp.\n */\nexport function escapeRegExp(str: string): string {\n return str.replace(RE_ESCAPE_REGEXP, '\\\\$&');\n}\n\n/**\n * Convert a string to a regex pattern that matches the string and its accented variations.\n * This function normalizes the input string and creates a regex pattern that can match\n * both the original characters and their accented equivalents.\n *\n * Optimization: Uses pre-computed regex and map to perform replacement in a single pass (O(N)),\n * instead of iterating through all character groups (O(K*N)).\n * Removed unnecessary NFD normalization which improves performance and fixes\n * matching against NFC target strings.\n *\n * @param str - The string to convert to a regex pattern.\n * @returns The regex pattern as a string that matches the original string and its accented variations.\n */\nexport function regexSearchMapper(str: string) {\n str = escapeRegExp(str);\n return str.replace(searchRegex, match => replacementMap.get(match) || match);\n}\n\nconst RE_DIACRITIC = /\\p{Diacritic}/gu;\n\n/**\n * Remove accents from a string.\n * This function normalizes the string using NFD normalization and removes all diacritical marks.\n *\n * @param str - The string to remove accents from.\n * @returns The string without any accents or diacritical marks.\n */\nexport function removeAccent(str: string) {\n return str.normalize('NFD').replace(RE_DIACRITIC, '');\n}\n\n/**\n * Remove duplicates from an array based on a key function.\n * This function can remove duplicates either by comparing values directly (when no keyFn is provided)\n * or by using a custom key function to determine uniqueness.\n *\n * @param arr - The array to remove duplicates from.\n * @param keyFn - Optional function that returns a unique key for each item in the array.\n * @returns A new array with duplicates removed, maintaining the original order.\n */\nexport function uniqueArray<T>(\n arr: T[],\n keyFn?: (item: T) => string | number,\n): T[] {\n if (!keyFn) {\n return [...new Set(arr)];\n }\n\n const seen = new Set<string | number>();\n const result: T[] = [];\n\n for (const item of arr) {\n const key = keyFn(item);\n if (!seen.has(key)) {\n seen.add(key);\n result.push(item);\n }\n }\n\n return result;\n}\n\n/**\n * Map environment variables to boolean flags indicating the current environment.\n * This function takes NODE_ENV and NODE_ENV_MODE variables and returns flags\n * indicating whether the current environment is development, staging, or production.\n *\n * @param env - The environment variables object containing NODE_ENV and NODE_ENV_MODE.\n * @returns An object containing boolean flags for the environment (IS_DEV, IS_STAG, IS_PROD).\n * @throws {Error} When NODE_ENV is production but NODE_ENV_MODE is development.\n */\nexport function mapEnvironment(env: I_NodeEnvInput): I_EnvFlags {\n const { NODE_ENV = E_Environment.DEVELOPMENT, NODE_ENV_MODE = E_Environment.DEVELOPMENT } = env;\n\n const IS_DEV = NODE_ENV === E_Environment.DEVELOPMENT && NODE_ENV_MODE === E_Environment.DEVELOPMENT;\n const IS_STAG = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.STAGING;\n const IS_PROD = NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.PRODUCTION;\n\n if (NODE_ENV === E_Environment.PRODUCTION && NODE_ENV_MODE === E_Environment.DEVELOPMENT) {\n throw new Error('NODE_ENV_MODE must be set to staging or production in production environment');\n }\n\n return { IS_DEV, IS_STAG, IS_PROD };\n}\n"],"mappings":";;AAIA,IAAM,IAAoC;CACtC,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CACxF,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CAC1D,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAI;CAC5B,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CACxF,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAK;EAAI;CAC1D,GAAG;EAAC;EAAK;EAAK;EAAK;EAAK;EAAI;CAC5B,GAAG,CAAC,IAAI;CACX,EAEK,IAAyC,OAAO,QAAQ,EAAQ,CAAC,QAClE,GAAK,CAAC,GAAK,QACR,EAAI,EAAI,aAAa,IAAI,EAAM,KAAI,MAAQ,EAAK,aAAa,CAAC,EACvD,IAEX,EAAE,CACL,EAEK,IAAc;CA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EAAc,cAAc,MAAkB,EAAc;AAEzF,KAAI,MAAa,EAAc,cAAc,MAAkB,EAAc,YACzE,OAAU,MAAM,+EAA+E;AAGnG,QAAO;EAAE;EAAQ;EAAS;EAAS"}
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import { escapeRegExp as
|
|
2
|
-
export {
|
|
3
|
-
p as escapeRegExp,
|
|
4
|
-
a as mapEnvironment,
|
|
5
|
-
n as regexSearchMapper,
|
|
6
|
-
c as removeAccent,
|
|
7
|
-
m as uniqueArray
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { escapeRegExp as e, mapEnvironment as t, regexSearchMapper as n, removeAccent as r, uniqueArray as i } from "./common.util.js";
|
|
2
|
+
export { e as escapeRegExp, t as mapEnvironment, n as regexSearchMapper, r as removeAccent, i as uniqueArray };
|
package/dist/util/index.js
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { validate as
|
|
6
|
-
export {
|
|
7
|
-
t as deepClone,
|
|
8
|
-
o as deepMerge,
|
|
9
|
-
i as escapeRegExp,
|
|
10
|
-
f as generateRandomPassword,
|
|
11
|
-
S as generateRandomString,
|
|
12
|
-
c as generateShortId,
|
|
13
|
-
N as generateSlug,
|
|
14
|
-
v as getFileName,
|
|
15
|
-
a as getNestedValue,
|
|
16
|
-
n as isJSON,
|
|
17
|
-
s as mapEnvironment,
|
|
18
|
-
g as normalizeMongoFilter,
|
|
19
|
-
d as regexSearchMapper,
|
|
20
|
-
l as removeAccent,
|
|
21
|
-
h as serializer,
|
|
22
|
-
m as setNestedValue,
|
|
23
|
-
M as substringBetween,
|
|
24
|
-
x as uniqueArray,
|
|
25
|
-
z as validate
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { escapeRegExp as e, mapEnvironment as t, regexSearchMapper as n, removeAccent as r, uniqueArray as i } from "./common/common.util.js";
|
|
2
|
+
import { deepClone as a, deepMerge as o, getNestedValue as s, isJSON as c, normalizeMongoFilter as l, setNestedValue as u } from "./object/object.util.js";
|
|
3
|
+
import { serializer as d } from "./serializer/serializer.util.js";
|
|
4
|
+
import { generateRandomPassword as f, generateRandomString as p, generateShortId as m, generateSlug as h, getFileName as g, substringBetween as _ } from "./string/string.util.js";
|
|
5
|
+
import { validate as v } from "./validate/validate.util.js";
|
|
6
|
+
export { a as deepClone, o as deepMerge, e as escapeRegExp, f as generateRandomPassword, p as generateRandomString, m as generateShortId, h as generateSlug, g as getFileName, s as getNestedValue, c as isJSON, t as mapEnvironment, l as normalizeMongoFilter, n as regexSearchMapper, r as removeAccent, d as serializer, u as setNestedValue, _ as substringBetween, i as uniqueArray, v as validate };
|
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
import { deepClone as
|
|
2
|
-
export {
|
|
3
|
-
t as deepClone,
|
|
4
|
-
l as deepMerge,
|
|
5
|
-
r as getNestedValue,
|
|
6
|
-
d as isJSON,
|
|
7
|
-
s as normalizeMongoFilter,
|
|
8
|
-
a as setNestedValue
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { deepClone as e, deepMerge as t, getNestedValue as n, isJSON as r, normalizeMongoFilter as i, setNestedValue as a } from "./object.util.js";
|
|
2
|
+
export { e as deepClone, t as deepMerge, n as getNestedValue, r as isJSON, i as normalizeMongoFilter, a as setNestedValue };
|
|
@@ -1,135 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
//#region src/util/object/object.util.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(e), !0;
|
|
5
|
+
} catch {
|
|
6
|
+
return !1;
|
|
7
|
+
}
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
else
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
return n;
|
|
9
|
+
function t(e, t) {
|
|
10
|
+
let n = e, r = t.length;
|
|
11
|
+
for (let e = 0; e < r; e++) {
|
|
12
|
+
if (typeof n != "object" || !n) return;
|
|
13
|
+
let r = t[e];
|
|
14
|
+
if (r !== void 0 && r in n) n = n[r];
|
|
15
|
+
else return;
|
|
16
|
+
}
|
|
17
|
+
return n;
|
|
21
18
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
[r]: c(
|
|
35
|
-
typeof o == "object" && o !== null ? o : {},
|
|
36
|
-
t,
|
|
37
|
-
n,
|
|
38
|
-
s + 1
|
|
39
|
-
)
|
|
40
|
-
};
|
|
19
|
+
function n(e, t, r, i) {
|
|
20
|
+
if (i >= t.length) return e;
|
|
21
|
+
let a = t[i];
|
|
22
|
+
if (i === t.length - 1) return {
|
|
23
|
+
...e,
|
|
24
|
+
[a]: r
|
|
25
|
+
};
|
|
26
|
+
let o = e[a];
|
|
27
|
+
return {
|
|
28
|
+
...e,
|
|
29
|
+
[a]: n(typeof o == "object" && o ? o : {}, t, r, i + 1)
|
|
30
|
+
};
|
|
41
31
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
32
|
+
function r(e, t, r) {
|
|
33
|
+
return t.length === 0 ? e : n(e, t, r, 0);
|
|
44
34
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
Object.hasOwn(e, s) && (n[s] = f(e[s]));
|
|
60
|
-
return n;
|
|
35
|
+
function i(e) {
|
|
36
|
+
if (typeof e != "object" || !e) return e;
|
|
37
|
+
if (e instanceof Date) return new Date(e.getTime());
|
|
38
|
+
if (e instanceof RegExp) return new RegExp(e.source, e.flags);
|
|
39
|
+
if (Array.isArray(e)) {
|
|
40
|
+
let t = e.length, n = Array(t);
|
|
41
|
+
for (let r = 0; r < t; r++) n[r] = i(e[r]);
|
|
42
|
+
return n;
|
|
43
|
+
}
|
|
44
|
+
let t = Object.getPrototypeOf(e);
|
|
45
|
+
if (t !== Object.prototype && t !== null) return e;
|
|
46
|
+
let n = {};
|
|
47
|
+
for (let t in e) Object.hasOwn(e, t) && (n[t] = i(e[t]));
|
|
48
|
+
return n;
|
|
61
49
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
} else
|
|
86
|
-
r[i] = u;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return r;
|
|
90
|
-
}
|
|
91
|
-
if (t.every((r) => typeof r != "object" || r === null))
|
|
92
|
-
throw new Error(
|
|
93
|
-
"deepMerge: Cannot merge primitive values. All arguments must be objects or arrays."
|
|
94
|
-
);
|
|
95
|
-
const n = t.some(Array.isArray), s = t.some(
|
|
96
|
-
(r) => typeof r == "object" && r !== null && !Array.isArray(r)
|
|
97
|
-
);
|
|
98
|
-
throw n && s ? new Error(
|
|
99
|
-
"deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."
|
|
100
|
-
) : new Error(
|
|
101
|
-
"deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type."
|
|
102
|
-
);
|
|
50
|
+
function a(...e) {
|
|
51
|
+
if (e.length === 0) return {};
|
|
52
|
+
let t = e.filter((e) => e != null);
|
|
53
|
+
if (t.length === 0) return {};
|
|
54
|
+
if (t.length === 1) return t[0];
|
|
55
|
+
if (t.every(Array.isArray)) return t.flat();
|
|
56
|
+
if (t.every((e) => typeof e == "object" && !!e && !Array.isArray(e))) {
|
|
57
|
+
let e = {};
|
|
58
|
+
for (let n of t) {
|
|
59
|
+
let t = n;
|
|
60
|
+
for (let n in t) if (Object.hasOwn(t, n)) {
|
|
61
|
+
let r = t[n];
|
|
62
|
+
if (Object.hasOwn(e, n)) {
|
|
63
|
+
let t = e[n];
|
|
64
|
+
typeof r == "object" && r && typeof t == "object" && t ? Array.isArray(r) && Array.isArray(t) ? e[n] = [...t, ...r] : !Array.isArray(r) && !Array.isArray(t) ? e[n] = a(t, r) : e[n] = r : e[n] = r;
|
|
65
|
+
} else e[n] = r;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return e;
|
|
69
|
+
}
|
|
70
|
+
if (t.every((e) => typeof e != "object" || !e)) throw Error("deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.");
|
|
71
|
+
let n = t.some(Array.isArray), r = t.some((e) => typeof e == "object" && !!e && !Array.isArray(e));
|
|
72
|
+
throw Error(n && r ? "deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects." : "deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.");
|
|
103
73
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
74
|
+
function o(e) {
|
|
75
|
+
if (!e || typeof e != "object") return e;
|
|
76
|
+
let t = {};
|
|
77
|
+
function n(e, r) {
|
|
78
|
+
for (let i in e) {
|
|
79
|
+
if (!Object.hasOwn(e, i)) continue;
|
|
80
|
+
let a = e[i], o = r ? `${r}.${i}` : i;
|
|
81
|
+
if (a && typeof a == "object" && !Array.isArray(a)) {
|
|
82
|
+
let e = Object.getPrototypeOf(a);
|
|
83
|
+
if (e !== Object.prototype && e !== null) {
|
|
84
|
+
t[o] = a;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
let r = !1;
|
|
88
|
+
for (let e in a) if (Object.hasOwn(a, e) && e.startsWith("$")) {
|
|
89
|
+
r = !0;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
r ? t[o] = a : n(a, o);
|
|
93
|
+
} else t[o] = a;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return n(e, ""), t;
|
|
126
97
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
A as isJSON,
|
|
132
|
-
h as normalizeMongoFilter,
|
|
133
|
-
g as setNestedValue
|
|
134
|
-
};
|
|
135
|
-
//# sourceMappingURL=object.util.js.map
|
|
98
|
+
//#endregion
|
|
99
|
+
export { i as deepClone, a as deepMerge, t as getNestedValue, e as isJSON, o as normalizeMongoFilter, r as setNestedValue };
|
|
100
|
+
|
|
101
|
+
//# sourceMappingURL=object.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.util.js","sources":["../../../src/util/object/object.util.ts"],"sourcesContent":["/**\n * Check if a string is a valid JSON string.\n * This function attempts to parse the string as JSON and returns true if successful,\n * false if the string is not valid JSON.\n *\n * @param str - The string to check for valid JSON format.\n * @returns True if the string is a valid JSON string, false otherwise.\n */\nexport function isJSON(str: string): boolean {\n try {\n JSON.parse(str);\n return true;\n }\n catch {\n return false;\n }\n}\n\n/**\n * Gets a nested value from an object using a path array.\n * This function traverses the object following the provided path and returns\n * the value at the specified location, or undefined if the path doesn't exist.\n *\n * @param obj - The object to get the value from.\n * @param path - An array of keys representing the path to the desired value.\n * @returns The value at the specified path, or undefined if the path doesn't exist.\n */\nexport function getNestedValue<T>(obj: T, path: (string | number)[]): unknown {\n // Optimization: Loop is faster than reduce and allows early exit\n let current: unknown = obj;\n const len = path.length;\n\n for (let i = 0; i < len; i++) {\n // Optimization: Early return if current value is null/undefined or not an object\n // This avoids unnecessary key lookups and type checks\n if (current == null || typeof current !== 'object') {\n return undefined;\n }\n\n const key = path[i];\n\n if (key !== undefined && key in (current as Record<string | number, unknown>)) {\n current = (current as Record<string | number, unknown>)[key];\n }\n else {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n *\n */\nfunction setNestedValueHelper<T>(obj: T, path: (string | number)[], value: unknown, index: number): T {\n if (index >= path.length)\n return obj;\n\n const head = path[index];\n\n if (index === path.length - 1) {\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number]: value,\n } as T;\n }\n\n const current = (obj as Record<string | number, unknown>)[head as string | number];\n\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number | symbol]: setNestedValueHelper(\n typeof current === 'object' && current !== null\n ? (current as object)\n : {},\n path,\n value,\n index + 1,\n ),\n } as T;\n}\n\n/**\n * Sets a nested value in an object using a path array.\n * This function creates the path if it doesn't exist and sets the value at the specified location.\n * The function returns a new object with the updated value, maintaining immutability.\n *\n * @param obj - The object to set the value in.\n * @param path - An array of keys representing the path to the desired location.\n * @param value - The value to set at the specified path.\n * @returns A new object with the updated value at the specified path.\n */\nexport function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T {\n if (path.length === 0)\n return obj;\n\n return setNestedValueHelper(obj, path, value, 0);\n}\n\n/**\n * Deep clones an object or array.\n * This function creates a deep copy of the input, recursively cloning objects and arrays.\n * Primitive values, dates, and other non-plain objects are returned as is (or cloned if supported).\n * Note: This implementation focuses on plain objects and arrays. For complex types like Map/Set/Buffer/ObjectId,\n * it returns the reference or handles them according to specific logic.\n *\n * @param obj - The object to clone.\n * @returns A deep copy of the object.\n */\nexport function deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map(item => deepClone(item)) as unknown as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as unknown as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as unknown as T;\n }\n\n // Handle Mongoose ObjectId and other custom classes by returning reference\n // structuredClone would fail here. We assume if it's not a plain object, we keep the reference\n // unless we want to implement specific cloning logic for every type.\n // However, we want to clone POJOs (Plain Old JavaScript Objects).\n const proto = Object.getPrototypeOf(obj);\n if (proto !== Object.prototype && proto !== null) {\n return obj;\n }\n\n const result = {} as Record<string, unknown>;\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n result[key] = deepClone((obj as Record<string, unknown>)[key]);\n }\n }\n\n return result as T;\n}\n\n/**\n * Deep merges multiple objects into a single object.\n * @param args - The objects to merge. Can be empty, in which case returns an empty object.\n * @returns The merged object.\n */\nexport function deepMerge<T = Record<string, unknown>>(\n ...args: (object | null | undefined)[]\n): T;\n\n/**\n * Deep merges multiple arrays into a single array.\n * @param args - The arrays to merge. Can be empty, in which case returns an empty array.\n * @returns The merged array.\n */\nexport function deepMerge<T = unknown[]>(\n ...args: (unknown[] | null | undefined)[]\n): T;\n\n/**\n * Implementation of deepMerge function.\n * @param args - The objects or arrays to merge.\n * @returns The merged result.\n */\nexport function deepMerge<T = Record<string, unknown> | unknown[]>(\n ...args: (object | unknown[] | null | undefined)[]\n): T {\n // Handle empty arguments\n if (args.length === 0) {\n return {} as T;\n }\n\n // Filter out null/undefined and convert to empty objects/arrays\n const validArgs = args.filter((arg): arg is object => arg !== null && arg !== undefined);\n\n // If no valid arguments after filtering, return empty object/array\n if (validArgs.length === 0) {\n return {} as T;\n }\n\n // If only one argument, return it directly\n if (validArgs.length === 1) {\n return validArgs[0] as T;\n }\n\n // Check if all arguments are arrays\n if (validArgs.every(Array.isArray)) {\n return (validArgs as unknown[][]).flat() as T;\n }\n\n // Check if all arguments are objects (but not arrays)\n if (validArgs.every(arg => typeof arg === 'object' && arg !== null && !Array.isArray(arg))) {\n const result = {} as Record<string, unknown>;\n\n for (const arg of validArgs) {\n const obj = arg as Record<string, unknown>;\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key];\n if (Object.hasOwn(result, key)) {\n const existingValue = result[key];\n if (\n typeof value === 'object' && value !== null\n && typeof existingValue === 'object' && existingValue !== null\n ) {\n if (Array.isArray(value) && Array.isArray(existingValue)) {\n result[key] = [...existingValue, ...value];\n }\n else if (!Array.isArray(value) && !Array.isArray(existingValue)) {\n result[key] = deepMerge(\n existingValue as Record<string, unknown>,\n value as Record<string, unknown>,\n );\n }\n else {\n // One is array, other is object (shouldn't happen with strict types but possible)\n // Overwrite\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n }\n }\n return result as T;\n }\n\n // Check if all arguments are primitive values\n if (validArgs.every(arg => typeof arg !== 'object' || arg === null)) {\n throw new Error(\n 'deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.',\n );\n }\n\n // Mixed types error\n const hasArrays = validArgs.some(Array.isArray);\n const hasObjects = validArgs.some(arg =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg),\n );\n\n if (hasArrays && hasObjects) {\n throw new Error(\n 'deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects.',\n );\n }\n\n // Fallback for unexpected cases\n throw new Error(\n 'deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.',\n );\n}\n\n/**\n * Normalizes MongoDB filters to support both dot notation strings and nested objects.\n * This function converts nested object filters to dot notation format while preserving\n * MongoDB operators to ensure consistent behavior across different filter input formats.\n *\n * @param filter - The filter object to normalize.\n * @returns A normalized filter object with nested objects converted to dot notation,\n * while preserving MongoDB operators as nested objects.\n *\n * @example\n * ```typescript\n * // Both of these will work the same way:\n * normalizeMongoFilter({ \"location.countryId\": \"240\" })\n * normalizeMongoFilter({ location: { countryId: \"240\" } })\n * // Both return: { \"location.countryId\": \"240\" }\n *\n * // MongoDB operators are preserved:\n * normalizeMongoFilter({ id: { $in: [\"240\", \"59\"] } })\n * // Returns: { id: { $in: [\"240\", \"59\"] } }\n * ```\n */\nexport function normalizeMongoFilter<T extends Record<string, unknown>>(filter: T): T {\n if (!filter || typeof filter !== 'object') {\n return filter;\n }\n\n const normalized: Record<string, unknown> = {};\n\n /**\n *\n */\n function flatten(current: Record<string, unknown>, prefix: string) {\n for (const key in current) {\n if (!Object.hasOwn(current, key))\n continue;\n\n const value = current[key];\n const newKey = prefix ? `${prefix}.${key}` : key;\n\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n // Check for Mongo operator\n let hasMongoOperator = false;\n for (const subKey in value as Record<string, unknown>) {\n if (Object.hasOwn(value, subKey) && subKey.startsWith('$')) {\n hasMongoOperator = true;\n break;\n }\n }\n\n if (hasMongoOperator) {\n normalized[newKey] = value;\n }\n else {\n flatten(value as Record<string, unknown>, newKey);\n }\n }\n else {\n normalized[newKey] = value;\n }\n }\n }\n\n flatten(filter, '');\n\n return normalized as T;\n}\n"],"names":["isJSON","str","getNestedValue","obj","path","current","len","i","key","setNestedValueHelper","value","index","head","setNestedValue","deepClone","item","proto","result","deepMerge","args","validArgs","arg","existingValue","hasArrays","hasObjects","normalizeMongoFilter","filter","normalized","flatten","prefix","newKey","hasMongoOperator","subKey"],"mappings":"AAQO,SAASA,EAAOC,GAAsB;AACzC,MAAI;AACA,gBAAK,MAAMA,CAAG,GACP;AAAA,EACX,QACM;AACF,WAAO;AAAA,EACX;AACJ;AAWO,SAASC,EAAkBC,GAAQC,GAAoC;AAE1E,MAAIC,IAAmBF;AACvB,QAAMG,IAAMF,EAAK;AAEjB,WAASG,IAAI,GAAGA,IAAID,GAAKC,KAAK;AAG1B,QAAIF,KAAW,QAAQ,OAA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,YAAYA,MAAQ,IAAI;AAC9D,UAAM,IAAI;AAAA,MACN;AAAA,IAAA;AAKR,QAAME,IAAYH,EAAU,KAAK,MAAM,OAAO,GACxCI,IAAaJ,EAAU;AAAA,IAAK,CAAAC,MAC9B,OAAOA,KAAQ,YAAYA,MAAQ,QAAQ,CAAC,MAAM,QAAQA,CAAG;AAAA,EAAA;AAGjE,QAAIE,KAAaC,IACP,IAAI;AAAA,IACN;AAAA,EAAA,IAKF,IAAI;AAAA,IACN;AAAA,EAAA;AAER;AAuBO,SAASC,EAAwDC,GAAc;AAClF,MAAI,CAACA,KAAU,OAAOA,KAAW;AAC7B,WAAOA;AAGX,QAAMC,IAAsC,CAAA;AAK5C,WAASC,EAAQvB,GAAkCwB,GAAgB;AAC/D,eAAWrB,KAAOH,GAAS;AACvB,UAAI,CAAC,OAAO,OAAOA,GAASG,CAAG;AAC3B;AAEJ,YAAME,IAAQL,EAAQG,CAAG,GACnBsB,IAASD,IAAS,GAAGA,CAAM,IAAIrB,CAAG,KAAKA;AAE7C,UAAIE,KAAS,OAAOA,KAAU,YAAY,CAAC,MAAM,QAAQA,CAAK,GAAG;AAE7D,YAAIqB,IAAmB;AACvB,mBAAWC,KAAUtB;AACjB,cAAI,OAAO,OAAOA,GAAOsB,CAAM,KAAKA,EAAO,WAAW,GAAG,GAAG;AACxD,YAAAD,IAAmB;AACnB;AAAA,UACJ;AAGJ,QAAIA,IACAJ,EAAWG,CAAM,IAAIpB,IAGrBkB,EAAQlB,GAAkCoB,CAAM;AAAA,MAExD;AAEI,QAAAH,EAAWG,CAAM,IAAIpB;AAAA,IAE7B;AAAA,EACJ;AAEA,SAAAkB,EAAQF,GAAQ,EAAE,GAEXC;AACX;"}
|
|
1
|
+
{"version":3,"file":"object.util.js","names":[],"sources":["../../../src/util/object/object.util.ts"],"sourcesContent":["/**\n * Check if a string is a valid JSON string.\n * This function attempts to parse the string as JSON and returns true if successful,\n * false if the string is not valid JSON.\n *\n * @param str - The string to check for valid JSON format.\n * @returns True if the string is a valid JSON string, false otherwise.\n */\nexport function isJSON(str: string): boolean {\n try {\n JSON.parse(str);\n return true;\n }\n catch {\n return false;\n }\n}\n\n/**\n * Gets a nested value from an object using a path array.\n * This function traverses the object following the provided path and returns\n * the value at the specified location, or undefined if the path doesn't exist.\n *\n * @param obj - The object to get the value from.\n * @param path - An array of keys representing the path to the desired value.\n * @returns The value at the specified path, or undefined if the path doesn't exist.\n */\nexport function getNestedValue<T>(obj: T, path: (string | number)[]): unknown {\n // Optimization: Loop is faster than reduce and allows early exit\n let current: unknown = obj;\n const len = path.length;\n\n for (let i = 0; i < len; i++) {\n // Optimization: Early return if current value is null/undefined or not an object\n // This avoids unnecessary key lookups and type checks\n if (current == null || typeof current !== 'object') {\n return undefined;\n }\n\n const key = path[i];\n\n if (key !== undefined && key in (current as Record<string | number, unknown>)) {\n current = (current as Record<string | number, unknown>)[key];\n }\n else {\n return undefined;\n }\n }\n\n return current;\n}\n\n/**\n * Recursively sets a value at a nested path within an object, creating intermediate objects as needed.\n *\n * @param obj - The source object.\n * @param path - Array of keys forming the path.\n * @param value - The value to set.\n * @param index - Current recursion depth.\n * @returns A new object with the value set at the specified path.\n */\nfunction setNestedValueHelper<T>(obj: T, path: (string | number)[], value: unknown, index: number): T {\n if (index >= path.length)\n return obj;\n\n const head = path[index];\n\n if (index === path.length - 1) {\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number]: value,\n } as T;\n }\n\n const current = (obj as Record<string | number, unknown>)[head as string | number];\n\n return {\n ...(obj as Record<string | number, unknown>),\n [head as string | number | symbol]: setNestedValueHelper(\n typeof current === 'object' && current !== null\n ? (current as object)\n : {},\n path,\n value,\n index + 1,\n ),\n } as T;\n}\n\n/**\n * Sets a nested value in an object using a path array.\n * This function creates the path if it doesn't exist and sets the value at the specified location.\n * The function returns a new object with the updated value, maintaining immutability.\n *\n * @param obj - The object to set the value in.\n * @param path - An array of keys representing the path to the desired location.\n * @param value - The value to set at the specified path.\n * @returns A new object with the updated value at the specified path.\n */\nexport function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T {\n if (path.length === 0)\n return obj;\n\n return setNestedValueHelper(obj, path, value, 0);\n}\n\n/**\n * Deep clones an object or array.\n * This function creates a deep copy of the input, recursively cloning objects and arrays.\n * Primitive values, dates, and other non-plain objects are returned as is (or cloned if supported).\n * Note: This implementation focuses on plain objects and arrays. For complex types like Map/Set/Buffer/ObjectId,\n * it returns the reference or handles them according to specific logic.\n *\n * @param obj - The object to clone.\n * @returns A deep copy of the object.\n */\nexport function deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as unknown as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as unknown as T;\n }\n\n if (Array.isArray(obj)) {\n // Optimization: `new Array(len)` + `for` loop is ~10-15% faster than `Array.map` or `Array.from`\n // for large arrays since it avoids callback overhead and pre-allocates memory.\n const len = obj.length;\n // eslint-disable-next-line unicorn/no-new-array -- Pre-allocating array size for performance\n const arr = new Array(len);\n for (let i = 0; i < len; i++) {\n arr[i] = deepClone(obj[i]);\n }\n return arr as unknown as T;\n }\n\n // Handle Mongoose ObjectId and other custom classes by returning reference.\n // structuredClone is not used here because it silently corrupts nested non-POJO\n // types (e.g., ObjectId → plain object) and Date instances in jsdom environments.\n const proto = Object.getPrototypeOf(obj);\n if (proto !== Object.prototype && proto !== null) {\n return obj;\n }\n\n const result = {} as Record<string, unknown>;\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n result[key] = deepClone((obj as Record<string, unknown>)[key]);\n }\n }\n\n return result as T;\n}\n\n/**\n * Deep merges multiple objects into a single object.\n * @param args - The objects to merge. Can be empty, in which case returns an empty object.\n * @returns The merged object.\n */\nexport function deepMerge<T = Record<string, unknown>>(\n ...args: (object | null | undefined)[]\n): T;\n\n/**\n * Deep merges multiple arrays into a single array.\n * @param args - The arrays to merge. Can be empty, in which case returns an empty array.\n * @returns The merged array.\n */\nexport function deepMerge<T = unknown[]>(\n ...args: (unknown[] | null | undefined)[]\n): T;\n\n/**\n * Implementation of deepMerge function.\n * @param args - The objects or arrays to merge.\n * @returns The merged result.\n */\nexport function deepMerge<T = Record<string, unknown> | unknown[]>(\n ...args: (object | unknown[] | null | undefined)[]\n): T {\n // Handle empty arguments\n if (args.length === 0) {\n return {} as T;\n }\n\n // Filter out null/undefined and convert to empty objects/arrays\n const validArgs = args.filter((arg): arg is object => arg !== null && arg !== undefined);\n\n // If no valid arguments after filtering, return empty object/array\n if (validArgs.length === 0) {\n return {} as T;\n }\n\n // If only one argument, return it directly\n if (validArgs.length === 1) {\n return validArgs[0] as T;\n }\n\n // Check if all arguments are arrays\n if (validArgs.every(Array.isArray)) {\n return (validArgs as unknown[][]).flat() as T;\n }\n\n // Check if all arguments are objects (but not arrays)\n if (validArgs.every(arg => typeof arg === 'object' && arg !== null && !Array.isArray(arg))) {\n const result = {} as Record<string, unknown>;\n\n for (const arg of validArgs) {\n const obj = arg as Record<string, unknown>;\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n const value = obj[key];\n if (Object.hasOwn(result, key)) {\n const existingValue = result[key];\n if (\n typeof value === 'object' && value !== null\n && typeof existingValue === 'object' && existingValue !== null\n ) {\n if (Array.isArray(value) && Array.isArray(existingValue)) {\n result[key] = [...existingValue, ...value];\n }\n else if (!Array.isArray(value) && !Array.isArray(existingValue)) {\n result[key] = deepMerge(\n existingValue as Record<string, unknown>,\n value as Record<string, unknown>,\n );\n }\n else {\n // One is array, other is object (shouldn't happen with strict types but possible)\n // Overwrite\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n else {\n result[key] = value;\n }\n }\n }\n }\n return result as T;\n }\n\n // Check if all arguments are primitive values\n if (validArgs.every(arg => typeof arg !== 'object' || arg === null)) {\n throw new Error(\n 'deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.',\n );\n }\n\n // Mixed types error\n const hasArrays = validArgs.some(Array.isArray);\n const hasObjects = validArgs.some(arg =>\n typeof arg === 'object' && arg !== null && !Array.isArray(arg),\n );\n\n if (hasArrays && hasObjects) {\n throw new Error(\n 'deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects.',\n );\n }\n\n // Fallback for unexpected cases\n throw new Error(\n 'deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.',\n );\n}\n\n/**\n * Normalizes MongoDB filters to support both dot notation strings and nested objects.\n * This function converts nested object filters to dot notation format while preserving\n * MongoDB operators to ensure consistent behavior across different filter input formats.\n *\n * @param filter - The filter object to normalize.\n * @returns A normalized filter object with nested objects converted to dot notation,\n * while preserving MongoDB operators as nested objects.\n *\n * @example\n * ```typescript\n * // Both of these will work the same way:\n * normalizeMongoFilter({ \"location.countryId\": \"240\" })\n * normalizeMongoFilter({ location: { countryId: \"240\" } })\n * // Both return: { \"location.countryId\": \"240\" }\n *\n * // MongoDB operators are preserved:\n * normalizeMongoFilter({ id: { $in: [\"240\", \"59\"] } })\n * // Returns: { id: { $in: [\"240\", \"59\"] } }\n * ```\n */\nexport function normalizeMongoFilter<T extends Record<string, unknown>>(filter: T): T {\n if (!filter || typeof filter !== 'object') {\n return filter;\n }\n\n const normalized: Record<string, unknown> = {};\n\n /**\n * Recursively flattens nested objects into dot-notation keys, preserving MongoDB operators.\n */\n function flatten(current: Record<string, unknown>, prefix: string) {\n for (const key in current) {\n if (!Object.hasOwn(current, key))\n continue;\n\n const value = current[key];\n const newKey = prefix ? `${prefix}.${key}` : key;\n\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n // Skip flattening for Mongoose ObjectId, Date, RegExp, and other non-POJO types\n const valueProto = Object.getPrototypeOf(value);\n if (valueProto !== Object.prototype && valueProto !== null) {\n normalized[newKey] = value;\n continue;\n }\n\n // Check for Mongo operator\n let hasMongoOperator = false;\n for (const subKey in value as Record<string, unknown>) {\n if (Object.hasOwn(value, subKey) && subKey.startsWith('$')) {\n hasMongoOperator = true;\n break;\n }\n }\n\n if (hasMongoOperator) {\n normalized[newKey] = value;\n }\n else {\n flatten(value as Record<string, unknown>, newKey);\n }\n }\n else {\n normalized[newKey] = value;\n }\n }\n }\n\n flatten(filter, '');\n\n return normalized as T;\n}\n"],"mappings":";AAQA,SAAgB,EAAO,GAAsB;AACzC,KAAI;AAEA,SADA,KAAK,MAAM,EAAI,EACR;SAEL;AACF,SAAO;;;AAaf,SAAgB,EAAkB,GAAQ,GAAoC;CAE1E,IAAI,IAAmB,GACjB,IAAM,EAAK;AAEjB,MAAK,IAAI,IAAI,GAAG,IAAI,GAAK,KAAK;AAG1B,MAAuB,OAAO,KAAY,aAAtC,EACA;EAGJ,IAAM,IAAM,EAAK;AAEjB,MAAI,MAAQ,KAAA,KAAa,KAAQ,EAC7B,KAAW,EAA6C;MAGxD;;AAIR,QAAO;;AAYX,SAAS,EAAwB,GAAQ,GAA2B,GAAgB,GAAkB;AAClG,KAAI,KAAS,EAAK,OACd,QAAO;CAEX,IAAM,IAAO,EAAK;AAElB,KAAI,MAAU,EAAK,SAAS,EACxB,QAAO;EACH,GAAI;GACH,IAA0B;EAC9B;CAGL,IAAM,IAAW,EAAyC;AAE1D,QAAO;EACH,GAAI;GACH,IAAmC,EAChC,OAAO,KAAY,YAAY,IACxB,IACD,EAAE,EACR,GACA,GACA,IAAQ,EACX;EACJ;;AAaL,SAAgB,EAAkB,GAAQ,GAA2B,GAAmB;AAIpF,QAHI,EAAK,WAAW,IACT,IAEJ,EAAqB,GAAK,GAAM,GAAO,EAAE;;AAapD,SAAgB,EAAa,GAAW;AACpC,KAAoB,OAAO,KAAQ,aAA/B,EACA,QAAO;AAGX,KAAI,aAAe,KACf,QAAO,IAAI,KAAK,EAAI,SAAS,CAAC;AAGlC,KAAI,aAAe,OACf,QAAO,IAAI,OAAO,EAAI,QAAQ,EAAI,MAAM;AAG5C,KAAI,MAAM,QAAQ,EAAI,EAAE;EAGpB,IAAM,IAAM,EAAI,QAEV,IAAU,MAAM,EAAI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