@cyberskill/shared 2.20.0 → 2.25.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 (63) hide show
  1. package/dist/config/eslint/index.cjs +1 -1
  2. package/dist/config/eslint/index.d.ts +2 -7
  3. package/dist/config/eslint/index.js +1 -1
  4. package/dist/config/storybook/storybook.main.cjs +1 -1
  5. package/dist/config/storybook/storybook.main.js +1 -1
  6. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  7. package/dist/config/vitest/vitest.e2e.js +6 -6
  8. package/dist/config/vitest/vitest.unit.cjs +1 -1
  9. package/dist/config/vitest/vitest.unit.js +5 -5
  10. package/dist/config/vitest/vitest.unit.setup.d.ts +0 -1
  11. package/dist/node/cli/index.cjs +4 -4
  12. package/dist/node/cli/index.js +56 -51
  13. package/dist/node/command/command.util.cjs +2 -2
  14. package/dist/node/command/command.util.d.ts +4 -1
  15. package/dist/node/command/command.util.js +125 -112
  16. package/dist/node/express/express.util.cjs +1 -1
  17. package/dist/node/express/express.util.js +24 -23
  18. package/dist/node/mongo/index.cjs +1 -1
  19. package/dist/node/mongo/index.d.ts +1 -0
  20. package/dist/node/mongo/index.js +15 -12
  21. package/dist/node/mongo/mongo.controller.cjs +1 -0
  22. package/dist/node/mongo/mongo.controller.d.ts +317 -0
  23. package/dist/node/mongo/mongo.controller.js +956 -0
  24. package/dist/node/mongo/mongo.controller.test.unit.d.ts +1 -0
  25. package/dist/node/mongo/mongo.type.d.ts +9 -10
  26. package/dist/node/mongo/mongo.util.cjs +5 -5
  27. package/dist/node/mongo/mongo.util.d.ts +32 -515
  28. package/dist/node/mongo/mongo.util.js +314 -1239
  29. package/dist/node/mongo/mongo.util.test.unit.d.ts +1 -0
  30. package/dist/node/path/path.constant.cjs +1 -1
  31. package/dist/node/path/path.constant.d.ts +2 -2
  32. package/dist/node/path/path.constant.js +120 -116
  33. package/dist/node/path/path.test.unit.d.ts +1 -0
  34. package/dist/node/path/path.util.d.ts +2 -2
  35. package/dist/react/loading/loading.component.cjs +2 -2
  36. package/dist/react/loading/loading.component.js +32 -19
  37. package/dist/react/loading/loading.test.unit.d.ts +1 -0
  38. package/dist/react/loading/loading.type.d.ts +2 -1
  39. package/dist/util/common/common.test.unit.d.ts +1 -0
  40. package/dist/util/common/common.util.cjs +1 -1
  41. package/dist/util/common/common.util.d.ts +3 -0
  42. package/dist/util/common/common.util.js +35 -35
  43. package/dist/util/index.cjs +1 -1
  44. package/dist/util/index.js +16 -15
  45. package/dist/util/object/index.cjs +1 -1
  46. package/dist/util/object/index.js +4 -3
  47. package/dist/util/object/object.test.unit.d.ts +1 -0
  48. package/dist/util/object/object.util.cjs +1 -1
  49. package/dist/util/object/object.util.d.ts +10 -30
  50. package/dist/util/object/object.util.js +110 -73
  51. package/dist/util/serializer/serializer.test.unit.d.ts +1 -0
  52. package/dist/util/serializer/serializer.util.cjs +1 -1
  53. package/dist/util/serializer/serializer.util.js +19 -16
  54. package/dist/util/string/string.test.unit.d.ts +1 -0
  55. package/dist/util/string/string.util.cjs +1 -1
  56. package/dist/util/string/string.util.d.ts +4 -3
  57. package/dist/util/string/string.util.js +32 -41
  58. package/dist/util/validate/validate.test.unit.d.ts +1 -0
  59. package/dist/util/validate/validate.util.cjs +1 -1
  60. package/dist/util/validate/validate.util.js +9 -9
  61. package/package.json +44 -51
  62. /package/dist/node_modules/.pnpm/{vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.cjs +0 -0
  63. /package/dist/node_modules/.pnpm/{vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.4.0_sass@1.97.2_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.js +0 -0
@@ -4,6 +4,9 @@ import { I_EnvFlags, I_NodeEnvInput } from './common.type.js';
4
4
  * This function normalizes the input string and creates a regex pattern that can match
5
5
  * both the original characters and their accented equivalents.
6
6
  *
7
+ * Optimization: Uses pre-computed regex and map to perform replacement in a single pass (O(N)),
8
+ * instead of iterating through all character groups (O(K*N)).
9
+ *
7
10
  * @param str - The string to convert to a regex pattern.
8
11
  * @returns The regex pattern as a string that matches the original string and its accented variations.
9
12
  */
@@ -1,14 +1,13 @@
1
- import u from "unorm";
2
1
  import { E_Environment as t } from "../../typescript/common.type.js";
3
- var O = Object.defineProperty, p = Object.getOwnPropertySymbols, f = Object.prototype.hasOwnProperty, m = Object.prototype.propertyIsEnumerable, i = (e, r, n) => r in e ? O(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n, E = (e, r) => {
4
- for (var n in r || (r = {}))
5
- f.call(r, n) && i(e, n, r[n]);
2
+ var f = Object.defineProperty, p = Object.getOwnPropertySymbols, m = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, i = (r, e, n) => e in r ? f(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n, s = (r, e) => {
3
+ for (var n in e || (e = {}))
4
+ m.call(e, n) && i(r, n, e[n]);
6
5
  if (p)
7
- for (var n of p(r))
8
- m.call(r, n) && i(e, n, r[n]);
9
- return e;
6
+ for (var n of p(e))
7
+ _.call(e, n) && i(r, n, e[n]);
8
+ return r;
10
9
  };
11
- const s = {
10
+ const E = {
12
11
  a: ["à", "á", "ạ", "ả", "ã", "â", "ầ", "ấ", "ậ", "ẩ", "ẫ", "ă", "ằ", "ắ", "ặ", "ẳ", "ẵ"],
13
12
  e: ["è", "é", "ẹ", "ẻ", "ẽ", "ê", "ề", "ế", "ệ", "ể", "ễ"],
14
13
  i: ["ì", "í", "ị", "ỉ", "ĩ"],
@@ -16,41 +15,42 @@ const s = {
16
15
  u: ["ù", "ú", "ụ", "ủ", "ũ", "ư", "ừ", "ứ", "ự", "ử", "ữ"],
17
16
  y: ["ỳ", "ý", "ỵ", "ỷ", "ỹ"],
18
17
  d: ["đ"]
19
- }, _ = Object.entries(s).reduce(
20
- (e, [r, n]) => (e[r.toUpperCase()] = n.map((o) => o.toUpperCase()), e),
18
+ }, D = Object.entries(E).reduce(
19
+ (r, [e, n]) => (r[e.toUpperCase()] = n.map((o) => o.toUpperCase()), r),
21
20
  {}
22
- );
23
- function P(e) {
24
- e = u.nfkc(e);
25
- const r = E(E({}, s), _);
26
- for (const [n, o] of Object.entries(r)) {
27
- const a = `[${n}${o.join("")}]`, c = `(${[n, ...o].join("|")})`;
28
- e = e.replace(new RegExp(a, "g"), c);
29
- }
30
- return e;
21
+ ), N = s(s({}, E), D), u = /* @__PURE__ */ new Map(), O = /* @__PURE__ */ new Set();
22
+ Object.entries(N).forEach(([r, e]) => {
23
+ const n = `(${[r, ...e].join("|")})`;
24
+ [r, ...e].forEach((o) => {
25
+ u.set(o, n), O.add(o);
26
+ });
27
+ });
28
+ const l = Array.from(O).join(""), P = new RegExp(`[${l}]`, "g");
29
+ function d(r) {
30
+ return r = r.normalize("NFD"), r.replace(P, (e) => u.get(e) || e);
31
31
  }
32
- function l(e) {
33
- return e.normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "");
32
+ function g(r) {
33
+ return r.normalize("NFD").replace(new RegExp("\\p{Diacritic}", "gu"), "");
34
34
  }
35
- function v(e, r) {
36
- if (!r)
37
- return Array.from(new Set(e));
35
+ function w(r, e) {
36
+ if (!e)
37
+ return Array.from(new Set(r));
38
38
  const n = /* @__PURE__ */ new Set(), o = [];
39
- for (const a of e) {
40
- const c = r(a);
41
- n.has(c) || (n.add(c), o.push(a));
39
+ for (const c of r) {
40
+ const a = e(c);
41
+ n.has(a) || (n.add(a), o.push(c));
42
42
  }
43
43
  return o;
44
44
  }
45
- function d(e) {
46
- const { NODE_ENV: r = t.DEVELOPMENT, NODE_ENV_MODE: n = t.DEVELOPMENT } = e, o = r === t.DEVELOPMENT && n === t.DEVELOPMENT, a = r === t.PRODUCTION && n === t.STAGING, c = r === t.PRODUCTION && n === t.PRODUCTION;
47
- if (r === t.PRODUCTION && n === t.DEVELOPMENT)
45
+ function S(r) {
46
+ const { NODE_ENV: e = t.DEVELOPMENT, NODE_ENV_MODE: n = t.DEVELOPMENT } = r, o = e === t.DEVELOPMENT && n === t.DEVELOPMENT, c = e === t.PRODUCTION && n === t.STAGING, a = e === t.PRODUCTION && n === t.PRODUCTION;
47
+ if (e === t.PRODUCTION && n === t.DEVELOPMENT)
48
48
  throw new Error("NODE_ENV_MODE must be set to staging or production in production environment");
49
- return { IS_DEV: o, IS_STAG: a, IS_PROD: c };
49
+ return { IS_DEV: o, IS_STAG: c, IS_PROD: a };
50
50
  }
51
51
  export {
52
- d as mapEnvironment,
53
- P as regexSearchMapper,
54
- l as removeAccent,
55
- v as uniqueArray
52
+ S as mapEnvironment,
53
+ d as regexSearchMapper,
54
+ g as removeAccent,
55
+ w as uniqueArray
56
56
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./common/common.util.cjs"),e=require("./object/object.util.cjs"),a=require("./serializer/serializer.util.cjs"),r=require("./string/string.util.cjs"),i=require("./validate/validate.util.cjs");exports.mapEnvironment=t.mapEnvironment;exports.regexSearchMapper=t.regexSearchMapper;exports.removeAccent=t.removeAccent;exports.uniqueArray=t.uniqueArray;exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;exports.serializer=a.serializer;exports.generateRandomPassword=r.generateRandomPassword;exports.generateShortId=r.generateShortId;exports.generateSlug=r.generateSlug;exports.getFileName=r.getFileName;exports.substringBetween=r.substringBetween;exports.validate=i.validate;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./common/common.util.cjs"),e=require("./object/object.util.cjs"),a=require("./serializer/serializer.util.cjs"),r=require("./string/string.util.cjs"),i=require("./validate/validate.util.cjs");exports.mapEnvironment=t.mapEnvironment;exports.regexSearchMapper=t.regexSearchMapper;exports.removeAccent=t.removeAccent;exports.uniqueArray=t.uniqueArray;exports.deepClone=e.deepClone;exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;exports.serializer=a.serializer;exports.generateRandomPassword=r.generateRandomPassword;exports.generateShortId=r.generateShortId;exports.generateSlug=r.generateSlug;exports.getFileName=r.getFileName;exports.substringBetween=r.substringBetween;exports.validate=i.validate;
@@ -1,23 +1,24 @@
1
1
  import { mapEnvironment as t, regexSearchMapper as o, removeAccent as a, uniqueArray as n } from "./common/common.util.js";
2
- import { deepMerge as g, getNestedValue as i, isJSON as p, normalizeMongoFilter as s, setNestedValue as l } from "./object/object.util.js";
3
- import { serializer as u } from "./serializer/serializer.util.js";
4
- import { generateRandomPassword as f, generateShortId as N, generateSlug as S, getFileName as c, substringBetween as v } from "./string/string.util.js";
5
- import { validate as h } from "./validate/validate.util.js";
2
+ import { deepClone as g, deepMerge as i, getNestedValue as p, isJSON as l, normalizeMongoFilter as s, setNestedValue as d } from "./object/object.util.js";
3
+ import { serializer as x } from "./serializer/serializer.util.js";
4
+ import { generateRandomPassword as N, generateShortId as S, generateSlug as c, getFileName as v, substringBetween as M } from "./string/string.util.js";
5
+ import { validate as w } from "./validate/validate.util.js";
6
6
  export {
7
- g as deepMerge,
8
- f as generateRandomPassword,
9
- N as generateShortId,
10
- S as generateSlug,
11
- c as getFileName,
12
- i as getNestedValue,
13
- p as isJSON,
7
+ g as deepClone,
8
+ i as deepMerge,
9
+ N as generateRandomPassword,
10
+ S as generateShortId,
11
+ c as generateSlug,
12
+ v as getFileName,
13
+ p as getNestedValue,
14
+ l as isJSON,
14
15
  t as mapEnvironment,
15
16
  s as normalizeMongoFilter,
16
17
  o as regexSearchMapper,
17
18
  a as removeAccent,
18
- u as serializer,
19
- l as setNestedValue,
20
- v as substringBetween,
19
+ x as serializer,
20
+ d as setNestedValue,
21
+ M as substringBetween,
21
22
  n as uniqueArray,
22
- h as validate
23
+ w as validate
23
24
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.deepClone=e.deepClone;exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;
@@ -1,8 +1,9 @@
1
- import { deepMerge as o, getNestedValue as r, isJSON as l, normalizeMongoFilter as s, setNestedValue as a } from "./object.util.js";
1
+ import { deepClone as t, deepMerge as l, getNestedValue as r, isJSON as d, normalizeMongoFilter as s, setNestedValue as a } from "./object.util.js";
2
2
  export {
3
- o as deepMerge,
3
+ t as deepClone,
4
+ l as deepMerge,
4
5
  r as getNestedValue,
5
- l as isJSON,
6
+ d as isJSON,
6
7
  s as normalizeMongoFilter,
7
8
  a as setNestedValue
8
9
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("lodash-es");var g=Object.defineProperty,v=Object.defineProperties,O=Object.getOwnPropertyDescriptors,a=Object.getOwnPropertySymbols,b=Object.prototype.hasOwnProperty,h=Object.prototype.propertyIsEnumerable,u=(r,e,t)=>e in r?g(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,l=(r,e)=>{for(var t in e||(e={}))b.call(e,t)&&u(r,t,e[t]);if(a)for(var t of a(e))h.call(e,t)&&u(r,t,e[t]);return r},c=(r,e)=>v(r,O(e));function _(r){try{return JSON.parse(r),!0}catch(e){return!1}}function j(r,e){return e.reduce((t,n)=>{if(t&&typeof t=="object"&&n in t)return t[n]},r)}function f(r,e,t){if(e.length===0)return r;const[n,...o]=e;if(o.length===0)return c(l({},r),{[n]:t});const s=r[n];return c(l({},r),{[n]:f(typeof s=="object"&&s!==null?s:{},o,t)})}function w(...r){if(r.length===0)return{};const e=r.filter(o=>o!=null).map(o=>typeof o!="object"?{}:o);if(e.length===0)return{};if(e.length===1)return e[0];if(e.every(i.isArray))return[].concat(...e);if(e.every(o=>typeof o=="object"&&o!==null&&!i.isArray(o)))return i.mergeWith({},...e,(o,s)=>{if(i.isArray(o)&&i.isArray(s))return o.concat(s)});if(e.every(o=>typeof o!="object"||o===null))throw new Error("deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.");const t=e.some(i.isArray),n=e.some(o=>typeof o=="object"&&o!==null&&!i.isArray(o));throw t&&n?new Error("deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."):new Error("deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.")}function p(r){if(!r||typeof r!="object")return r;const e={};for(const[t,n]of Object.entries(r))if(n&&typeof n=="object"&&!Array.isArray(n))if(Object.keys(n).some(s=>s.startsWith("$")))e[t]=n;else{const s=p(n);for(const[y,d]of Object.entries(s)){const m=`${t}.${y}`;e[m]=d}}else e[t]=n;return e}exports.deepMerge=w;exports.getNestedValue=j;exports.isJSON=_;exports.normalizeMongoFilter=p;exports.setNestedValue=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var m=Object.defineProperty,A=Object.defineProperties,v=Object.getOwnPropertyDescriptors,u=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable,y=(e,r,n)=>r in e?m(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,p=(e,r)=>{for(var n in r||(r={}))h.call(r,n)&&y(e,n,r[n]);if(u)for(var n of u(r))w.call(r,n)&&y(e,n,r[n]);return e},O=(e,r)=>A(e,v(r));function P(e){try{return JSON.parse(e),!0}catch(r){return!1}}function _(e,r){let n=e;const o=r.length;for(let t=0;t<o;t++){const s=r[t];if(s!==void 0&&n&&typeof n=="object"&&s in n)n=n[s];else return}return n}function d(e,r,n){if(r.length===0)return e;const[o,...t]=r;if(t.length===0)return O(p({},e),{[o]:n});const s=e[o];return O(p({},e),{[o]:d(typeof s=="object"&&s!==null?s:{},t,n)})}function f(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(o=>f(o));if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)return e;const n={};for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=f(e[o]));return n}function g(...e){if(e.length===0)return{};const r=e.filter(t=>t!=null);if(r.length===0)return{};if(r.length===1)return r[0];if(r.every(Array.isArray))return[].concat(...r);if(r.every(t=>typeof t=="object"&&t!==null&&!Array.isArray(t))){const t={};for(const s of r){const i=s;for(const a in i)if(Object.prototype.hasOwnProperty.call(i,a)){const l=i[a];if(Object.prototype.hasOwnProperty.call(t,a)){const c=t[a];typeof l=="object"&&l!==null&&typeof c=="object"&&c!==null?Array.isArray(l)&&Array.isArray(c)?t[a]=c.concat(l):!Array.isArray(l)&&!Array.isArray(c)?t[a]=g(c,l):t[a]=l:t[a]=l}else t[a]=l}}return t}if(r.every(t=>typeof t!="object"||t===null))throw new Error("deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.");const n=r.some(Array.isArray),o=r.some(t=>typeof t=="object"&&t!==null&&!Array.isArray(t));throw n&&o?new Error("deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."):new Error("deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.")}function b(e){if(!e||typeof e!="object")return e;const r={};function n(o,t){for(const s in o){if(!Object.prototype.hasOwnProperty.call(o,s))continue;const i=o[s],a=t?`${t}.${s}`:s;if(i&&typeof i=="object"&&!Array.isArray(i)){let l=!1;for(const c in i)if(Object.prototype.hasOwnProperty.call(i,c)&&c.startsWith("$")){l=!0;break}l?r[a]=i:n(i,a)}else r[a]=i}}return n(e,""),r}exports.deepClone=f;exports.deepMerge=g;exports.getNestedValue=_;exports.isJSON=P;exports.normalizeMongoFilter=b;exports.setNestedValue=d;
@@ -29,48 +29,28 @@ export declare function getNestedValue<T>(obj: T, path: (string | number)[]): un
29
29
  */
30
30
  export declare function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T;
31
31
  /**
32
- * Deep merges multiple objects or arrays into a single object or array.
33
- * This function handles different types of merging with improved type safety and error handling:
34
- * - If all arguments are arrays, it concatenates them
35
- * - If all arguments are objects, it deeply merges them (concatenating arrays within objects)
36
- * - Handles null/undefined values gracefully by treating them as empty objects
37
- * - Provides better type inference and safety
38
- * - Throws descriptive errors for invalid input
32
+ * Deep clones an object or array.
33
+ * This function creates a deep copy of the input, recursively cloning objects and arrays.
34
+ * Primitive values, dates, and other non-plain objects are returned as is (or cloned if supported).
35
+ * Note: This implementation focuses on plain objects and arrays. For complex types like Map/Set/Buffer/ObjectId,
36
+ * it returns the reference or handles them according to specific logic.
39
37
  *
40
- * @param args - The objects or arrays to merge. Can be empty, in which case returns an empty object.
41
- * @returns The merged result - either a concatenated array or a deeply merged object.
42
- * @throws {Error} When arguments are mixed types (some arrays, some objects) or when all arguments are primitive values.
43
- *
44
- * @example
45
- * ```typescript
46
- * // Merge objects
47
- * deepMerge({ a: 1 }, { b: 2 }, { a: 3 }) // { a: 3, b: 2 }
48
- *
49
- * // Merge arrays
50
- * deepMerge([1, 2], [3, 4]) // [1, 2, 3, 4]
51
- *
52
- * // Handle null/undefined
53
- * deepMerge({ a: 1 }, null, undefined, { b: 2 }) // { a: 1, b: 2 }
54
- *
55
- * // Nested objects with arrays
56
- * deepMerge(
57
- * { items: [1, 2], config: { theme: 'dark' } },
58
- * { items: [3, 4], config: { size: 'large' } }
59
- * ) // { items: [1, 2, 3, 4], config: { theme: 'dark', size: 'large' } }
60
- * ```
38
+ * @param obj - The object to clone.
39
+ * @returns A deep copy of the object.
61
40
  */
41
+ export declare function deepClone<T>(obj: T): T;
62
42
  /**
63
43
  * Deep merges multiple objects into a single object.
64
44
  * @param args - The objects to merge. Can be empty, in which case returns an empty object.
65
45
  * @returns The merged object.
66
46
  */
67
- export declare function deepMerge<T extends Record<string, unknown>>(...args: (T | null | undefined)[]): T;
47
+ export declare function deepMerge<T = Record<string, unknown>>(...args: (object | null | undefined)[]): T;
68
48
  /**
69
49
  * Deep merges multiple arrays into a single array.
70
50
  * @param args - The arrays to merge. Can be empty, in which case returns an empty array.
71
51
  * @returns The merged array.
72
52
  */
73
- export declare function deepMerge<T extends unknown[]>(...args: (T | null | undefined)[]): T;
53
+ export declare function deepMerge<T = unknown[]>(...args: (unknown[] | null | undefined)[]): T;
74
54
  /**
75
55
  * Normalizes MongoDB filters to support both dot notation strings and nested objects.
76
56
  * This function converts nested object filters to dot notation format while preserving
@@ -1,97 +1,134 @@
1
- import { isArray as i, mergeWith as d } from "lodash-es";
2
- var m = Object.defineProperty, v = Object.defineProperties, O = Object.getOwnPropertyDescriptors, a = Object.getOwnPropertySymbols, b = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable, u = (r, e, t) => e in r ? m(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, f = (r, e) => {
3
- for (var t in e || (e = {}))
4
- b.call(e, t) && u(r, t, e[t]);
5
- if (a)
6
- for (var t of a(e))
7
- h.call(e, t) && u(r, t, e[t]);
8
- return r;
9
- }, c = (r, e) => v(r, O(e));
10
- function w(r) {
1
+ var A = Object.defineProperty, d = Object.defineProperties, g = Object.getOwnPropertyDescriptors, f = Object.getOwnPropertySymbols, m = Object.prototype.hasOwnProperty, h = Object.prototype.propertyIsEnumerable, y = (e, r, n) => r in e ? A(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n, u = (e, r) => {
2
+ for (var n in r || (r = {}))
3
+ m.call(r, n) && y(e, n, r[n]);
4
+ if (f)
5
+ for (var n of f(r))
6
+ h.call(r, n) && y(e, n, r[n]);
7
+ return e;
8
+ }, p = (e, r) => d(e, g(r));
9
+ function P(e) {
11
10
  try {
12
- return JSON.parse(r), !0;
13
- } catch (e) {
11
+ return JSON.parse(e), !0;
12
+ } catch (r) {
14
13
  return !1;
15
14
  }
16
15
  }
17
- function P(r, e) {
18
- return e.reduce((t, n) => {
19
- if (t && typeof t == "object" && n in t)
20
- return t[n];
21
- }, r);
16
+ function _(e, r) {
17
+ let n = e;
18
+ const o = r.length;
19
+ for (let t = 0; t < o; t++) {
20
+ const s = r[t];
21
+ if (s !== void 0 && n && typeof n == "object" && s in n)
22
+ n = n[s];
23
+ else
24
+ return;
25
+ }
26
+ return n;
22
27
  }
23
- function _(r, e, t) {
24
- if (e.length === 0)
25
- return r;
26
- const [n, ...o] = e;
27
- if (o.length === 0)
28
- return c(f({}, r), {
29
- [n]: t
28
+ function v(e, r, n) {
29
+ if (r.length === 0)
30
+ return e;
31
+ const [o, ...t] = r;
32
+ if (t.length === 0)
33
+ return p(u({}, e), {
34
+ [o]: n
30
35
  });
31
- const s = r[n];
32
- return c(f({}, r), {
33
- [n]: _(
36
+ const s = e[o];
37
+ return p(u({}, e), {
38
+ [o]: v(
34
39
  typeof s == "object" && s !== null ? s : {},
35
- o,
36
- t
40
+ t,
41
+ n
37
42
  )
38
43
  });
39
44
  }
40
- function A(...r) {
41
- if (r.length === 0)
42
- return {};
43
- const e = r.filter((o) => o != null).map((o) => typeof o != "object" ? {} : o);
45
+ function O(e) {
46
+ if (e === null || typeof e != "object")
47
+ return e;
48
+ if (Array.isArray(e))
49
+ return e.map((o) => O(o));
50
+ if (e instanceof Date)
51
+ return new Date(e.getTime());
52
+ if (e instanceof RegExp)
53
+ return new RegExp(e.source, e.flags);
54
+ const r = Object.getPrototypeOf(e);
55
+ if (r !== Object.prototype && r !== null)
56
+ return e;
57
+ const n = {};
58
+ for (const o in e)
59
+ Object.prototype.hasOwnProperty.call(e, o) && (n[o] = O(e[o]));
60
+ return n;
61
+ }
62
+ function w(...e) {
44
63
  if (e.length === 0)
45
64
  return {};
46
- if (e.length === 1)
47
- return e[0];
48
- if (e.every(i))
49
- return [].concat(...e);
50
- if (e.every(
51
- (o) => typeof o == "object" && o !== null && !i(o)
52
- ))
53
- return d({}, ...e, (o, s) => {
54
- if (i(o) && i(s))
55
- return o.concat(s);
56
- });
57
- if (e.every((o) => typeof o != "object" || o === null))
65
+ const r = e.filter((t) => t != null);
66
+ if (r.length === 0)
67
+ return {};
68
+ if (r.length === 1)
69
+ return r[0];
70
+ if (r.every(Array.isArray))
71
+ return [].concat(...r);
72
+ if (r.every((t) => typeof t == "object" && t !== null && !Array.isArray(t))) {
73
+ const t = {};
74
+ for (const s of r) {
75
+ const i = s;
76
+ for (const a in i)
77
+ if (Object.prototype.hasOwnProperty.call(i, a)) {
78
+ const l = i[a];
79
+ if (Object.prototype.hasOwnProperty.call(t, a)) {
80
+ const c = t[a];
81
+ typeof l == "object" && l !== null && typeof c == "object" && c !== null ? Array.isArray(l) && Array.isArray(c) ? t[a] = c.concat(l) : !Array.isArray(l) && !Array.isArray(c) ? t[a] = w(
82
+ c,
83
+ l
84
+ ) : t[a] = l : t[a] = l;
85
+ } else
86
+ t[a] = l;
87
+ }
88
+ }
89
+ return t;
90
+ }
91
+ if (r.every((t) => typeof t != "object" || t === null))
58
92
  throw new Error(
59
93
  "deepMerge: Cannot merge primitive values. All arguments must be objects or arrays."
60
94
  );
61
- const t = e.some(i), n = e.some(
62
- (o) => typeof o == "object" && o !== null && !i(o)
95
+ const n = r.some(Array.isArray), o = r.some(
96
+ (t) => typeof t == "object" && t !== null && !Array.isArray(t)
63
97
  );
64
- throw t && n ? new Error(
98
+ throw n && o ? new Error(
65
99
  "deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."
66
100
  ) : new Error(
67
101
  "deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type."
68
102
  );
69
103
  }
70
- function g(r) {
71
- if (!r || typeof r != "object")
72
- return r;
73
- const e = {};
74
- for (const [t, n] of Object.entries(r))
75
- if (n && typeof n == "object" && !Array.isArray(n))
76
- if (Object.keys(n).some(
77
- (s) => s.startsWith("$")
78
- ))
79
- e[t] = n;
80
- else {
81
- const s = g(n);
82
- for (const [l, p] of Object.entries(s)) {
83
- const y = `${t}.${l}`;
84
- e[y] = p;
85
- }
86
- }
87
- else
88
- e[t] = n;
89
- return e;
104
+ function b(e) {
105
+ if (!e || typeof e != "object")
106
+ return e;
107
+ const r = {};
108
+ function n(o, t) {
109
+ for (const s in o) {
110
+ if (!Object.prototype.hasOwnProperty.call(o, s))
111
+ continue;
112
+ const i = o[s], a = t ? `${t}.${s}` : s;
113
+ if (i && typeof i == "object" && !Array.isArray(i)) {
114
+ let l = !1;
115
+ for (const c in i)
116
+ if (Object.prototype.hasOwnProperty.call(i, c) && c.startsWith("$")) {
117
+ l = !0;
118
+ break;
119
+ }
120
+ l ? r[a] = i : n(i, a);
121
+ } else
122
+ r[a] = i;
123
+ }
124
+ }
125
+ return n(e, ""), r;
90
126
  }
91
127
  export {
92
- A as deepMerge,
93
- P as getNestedValue,
94
- w as isJSON,
95
- g as normalizeMongoFilter,
96
- _ as setNestedValue
128
+ O as deepClone,
129
+ w as deepMerge,
130
+ _ as getNestedValue,
131
+ P as isJSON,
132
+ b as normalizeMongoFilter,
133
+ v as setNestedValue
97
134
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n={Date:{is:e=>e instanceof Date,serialize:e=>({__type:"Date",value:e.toISOString()}),deserialize:e=>new Date(e)},Map:{is:e=>e instanceof Map,serialize:e=>({__type:"Map",value:Array.from(e.entries())}),deserialize:e=>new Map(e)},Set:{is:e=>e instanceof Set,serialize:e=>({__type:"Set",value:Array.from(e)}),deserialize:e=>new Set(e)},RegExp:{is:e=>e instanceof RegExp,serialize:e=>({__type:"RegExp",value:{source:e.source,flags:e.flags}}),deserialize:e=>{const{source:r,flags:i}=e;return new RegExp(r,i)}},BigInt:{is:e=>typeof e=="bigint",serialize:e=>({__type:"BigInt",value:e.toString()}),deserialize:e=>BigInt(e)}},a={serialize(e){return JSON.stringify(e,(r,i)=>{for(const s of Object.keys(n)){const t=n[s];if(t.is(i))return t.serialize(i)}return i})},deserialize(e){return JSON.parse(e,(r,i)=>{if(i&&typeof i=="object"&&"__type"in i&&typeof i.__type=="string"){const s=i.__type,t=n[s];if(t)return t.deserialize(i.value)}return i})}};exports.serializer=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s={Date:{is:e=>e instanceof Date,serialize:e=>({__type:"Date",value:e.toISOString()}),deserialize:e=>new Date(e)},Map:{is:e=>e instanceof Map,serialize:e=>({__type:"Map",value:Array.from(e.entries())}),deserialize:e=>new Map(e)},Set:{is:e=>e instanceof Set,serialize:e=>({__type:"Set",value:Array.from(e)}),deserialize:e=>new Set(e)},RegExp:{is:e=>e instanceof RegExp,serialize:e=>({__type:"RegExp",value:{source:e.source,flags:e.flags}}),deserialize:e=>{const{source:r,flags:t}=e;return new RegExp(r,t)}},BigInt:{is:e=>typeof e=="bigint",serialize:e=>({__type:"BigInt",value:e.toString()}),deserialize:e=>BigInt(e)}},l={serialize(e){return JSON.stringify(e,function(r,t){const i=this[r];if(i instanceof Date)return s.Date.serialize(i);for(const o of Object.keys(s)){const a=s[o];if(a.is(t))return a.serialize(t)}return t})},deserialize(e){return JSON.parse(e,(r,t)=>{if(t&&typeof t=="object"&&"__type"in t&&typeof t.__type=="string"){const n=t.__type,i=s[n];if(i)return i.deserialize(t.value)}return t})}};exports.serializer=l;
@@ -21,8 +21,8 @@ const n = {
21
21
  value: { source: e.source, flags: e.flags }
22
22
  }),
23
23
  deserialize: (e) => {
24
- const { source: r, flags: i } = e;
25
- return new RegExp(r, i);
24
+ const { source: r, flags: t } = e;
25
+ return new RegExp(r, t);
26
26
  }
27
27
  },
28
28
  BigInt: {
@@ -30,7 +30,7 @@ const n = {
30
30
  serialize: (e) => ({ __type: "BigInt", value: e.toString() }),
31
31
  deserialize: (e) => BigInt(e)
32
32
  }
33
- }, a = {
33
+ }, p = {
34
34
  /**
35
35
  * Serializes a value to a JSON string.
36
36
  * If the value is of a known type (Date, Map, Set, RegExp, BigInt),
@@ -41,13 +41,16 @@ const n = {
41
41
  * @returns The serialized JSON string that can be safely stored or transmitted.
42
42
  */
43
43
  serialize(e) {
44
- return JSON.stringify(e, (r, i) => {
45
- for (const s of Object.keys(n)) {
46
- const t = n[s];
47
- if (t.is(i))
48
- return t.serialize(i);
44
+ return JSON.stringify(e, function(r, t) {
45
+ const i = this[r];
46
+ if (i instanceof Date)
47
+ return n.Date.serialize(i);
48
+ for (const o of Object.keys(n)) {
49
+ const a = n[o];
50
+ if (a.is(t))
51
+ return a.serialize(t);
49
52
  }
50
- return i;
53
+ return t;
51
54
  });
52
55
  },
53
56
  /**
@@ -60,16 +63,16 @@ const n = {
60
63
  * @returns The deserialized value with all special types reconstructed.
61
64
  */
62
65
  deserialize(e) {
63
- return JSON.parse(e, (r, i) => {
64
- if (i && typeof i == "object" && "__type" in i && typeof i.__type == "string") {
65
- const s = i.__type, t = n[s];
66
- if (t)
67
- return t.deserialize(i.value);
66
+ return JSON.parse(e, (r, t) => {
67
+ if (t && typeof t == "object" && "__type" in t && typeof t.__type == "string") {
68
+ const s = t.__type, i = n[s];
69
+ if (i)
70
+ return i.deserialize(t.value);
68
71
  }
69
- return i;
72
+ return t;
70
73
  });
71
74
  }
72
75
  };
73
76
  export {
74
- a as serializer
77
+ p as serializer
75
78
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("crypto-js"),c=require("lodash-es"),u=require("slugify");var f=Object.defineProperty,s=Object.getOwnPropertySymbols,d=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable,i=(r,e,t)=>e in r?f(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,m=(r,e)=>{for(var t in e||(e={}))d.call(e,t)&&i(r,t,e[t]);if(s)for(var t of s(e))g.call(e,t)&&i(r,t,e[t]);return r};const O=u.default||u;function y(r,e){const t=n=>{var o,l;return O(n!=null?n:"",m({lower:(o=e==null?void 0:e.lower)!=null?o:!0,locale:(l=e==null?void 0:e.locale)!=null?l:"vi"},e))};if(c.isObject(r)){const n={};for(const[o,l]of Object.entries(r))n[o]=t(l);return n}return t(r)}function _(r,e=4){return a.SHA256(r).toString(a.enc.Hex).slice(0,e)}function h(r=8){const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?";return Array.from({length:r},()=>{const t=Math.floor(Math.random()*e.length);return e.charAt(t)}).join("")}function w(r="",e=!1){const t=r.split(/[?#]/)[0]||"",n=t.substring(t.lastIndexOf("/")+1);if(e)return n;const o=n.lastIndexOf(".");return o>0?n.slice(0,o):n}function p(r,e,t){const n=r.indexOf(e);if(n===-1)return"";const o=n+e.length,l=r.indexOf(t,o);return l===-1?"":r.slice(o,l)}exports.generateRandomPassword=h;exports.generateShortId=_;exports.generateSlug=y;exports.getFileName=w;exports.substringBetween=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../common/common.util.cjs");function a(t,r){let e=t.trim();return e=l.removeAccent(e),(r==null?void 0:r.lower)!==!1&&(e=e.toLowerCase()),e=e.replace(/[^a-z0-9\s-]/gi," "),e=e.replace(/[\s-]+/g,"-"),e=e.replace(/^-+|-+$/g,""),e}function c(t,r){const e=n=>a(n!=null?n:"",r);if(typeof t=="object"&&t!==null){const n={};for(const[o,s]of Object.entries(t))n[o]=e(s);return n}return e(t)}function i(t,r=4){let e=2166136261;for(let o=0;o<t.length;o++)e^=t.charCodeAt(o),e=Math.imul(e,16777619);const n=(e>>>0).toString(16).padStart(8,"0");return r>8?t.replace(/-/g,"").slice(0,r):n.slice(0,r)}function u(t=8){const r="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?";return Array.from({length:t},()=>{const e=Math.floor(Math.random()*r.length);return r.charAt(e)}).join("")}function f(t="",r=!1){const e=t.split(/[?#]/)[0]||"",n=e.substring(e.lastIndexOf("/")+1);if(r)return n;const o=n.lastIndexOf(".");return o>0?n.slice(0,o):n}function g(t,r,e){const n=t.indexOf(r);if(n===-1)return"";const o=n+r.length,s=t.indexOf(e,o);return s===-1?"":t.slice(o,s)}exports.generateRandomPassword=u;exports.generateShortId=i;exports.generateSlug=c;exports.getFileName=f;exports.substringBetween=g;
@@ -12,12 +12,13 @@ import { I_SlugifyOptions } from './string.type.js';
12
12
  export declare function generateSlug<T = string>(input: T, options?: I_SlugifyOptions): T;
13
13
  /**
14
14
  * Generates a short ID from a UUID.
15
- * The ID is a substring of the SHA256 hash of the UUID, providing a shorter
16
- * but still unique identifier based on the original UUID.
15
+ * The ID is a substring of the UUID, providing a shorter identifier.
16
+ * Note: This is NOT cryptographically secure and collisions are possible,
17
+ * but suitable for display purposes where uniqueness is handled elsewhere.
17
18
  *
18
19
  * @param uuid - The UUID to be converted to a short ID.
19
20
  * @param length - The desired length of the short ID (default: 4 characters).
20
- * @returns A short ID string of the specified length derived from the UUID's SHA256 hash.
21
+ * @returns A short ID string of the specified length derived from the UUID.
21
22
  */
22
23
  export declare function generateShortId(uuid: string, length?: number): string;
23
24
  /**