@cyberskill/shared 3.1.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config.util.js +3 -2
- package/dist/config/config.util.js.map +1 -1
- package/dist/config/storybook/storybook.preview.d.ts +1 -1
- package/dist/config/storybook/storybook.preview.js +5 -4
- package/dist/config/storybook/storybook.preview.js.map +1 -1
- package/dist/config/vitest/vitest.e2e.d.ts +2 -0
- package/dist/config/vitest/vitest.e2e.js +11 -18
- package/dist/config/vitest/vitest.e2e.js.map +1 -1
- package/dist/config/vitest/vitest.unit.d.ts +2 -0
- package/dist/config/vitest/vitest.unit.js +7 -5
- package/dist/config/vitest/vitest.unit.js.map +1 -1
- package/dist/node/cli/index.js +55 -45
- package/dist/node/cli/index.js.map +1 -1
- package/dist/node/command/command.util.js +75 -75
- package/dist/node/command/command.util.js.map +1 -1
- package/dist/node/express/express.util.js +16 -16
- package/dist/node/express/express.util.js.map +1 -1
- package/dist/node/mongo/mongo.controller.d.ts +1 -1
- package/dist/node/mongo/mongo.controller.mongoose.js.map +1 -1
- package/dist/node/mongo/mongo.dynamic-populate.js +64 -64
- package/dist/node/mongo/mongo.dynamic-populate.js.map +1 -1
- package/dist/node/mongo/mongo.populate.js.map +1 -1
- package/dist/node/mongo/mongo.util.d.ts +16 -16
- package/dist/node/mongo/mongo.util.js.map +1 -1
- package/dist/node/path/path.constant.js +9 -9
- package/dist/node/path/path.constant.js.map +1 -1
- package/dist/node/ws/index.d.ts +1 -1
- package/dist/node_modules/.pnpm/{vitest@4.0.18_@types_node@25.3.3_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 → 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 +1 -1
- package/dist/react/apollo-client/apollo-client.util.js +13 -13
- package/dist/react/apollo-client/apollo-client.util.js.map +1 -1
- package/dist/react/apollo-error/apollo-error.component.js +22 -21
- package/dist/react/apollo-error/apollo-error.component.js.map +1 -1
- package/dist/util/common/common.util.js +26 -25
- package/dist/util/common/common.util.js.map +1 -1
- package/dist/util/object/object.util.js +49 -49
- package/dist/util/object/object.util.js.map +1 -1
- package/dist/util/serializer/serializer.util.js +12 -12
- package/dist/util/serializer/serializer.util.js.map +1 -1
- package/dist/util/string/string.util.js +29 -28
- package/dist/util/string/string.util.js.map +1 -1
- package/dist/util/validate/validate.util.d.ts +0 -4
- package/dist/util/validate/validate.util.js +3 -3
- package/dist/util/validate/validate.util.js.map +1 -1
- package/package.json +31 -29
- package/public/tsconfig.base.json +1 -1
- package/dist/config/config.test.unit.d.ts +0 -1
- package/dist/config/config.type.test.unit.d.ts +0 -1
- package/dist/constant/constant.test.unit.d.ts +0 -1
- package/dist/node/command/command.test.unit.d.ts +0 -1
- package/dist/node/fs/fs.test.unit.d.ts +0 -1
- package/dist/node/log/log.test.unit.d.ts +0 -1
- package/dist/node/mongo/mongo.controller.test.unit.d.ts +0 -1
- package/dist/node/mongo/mongo.util.test.unit.d.ts +0 -1
- package/dist/node/package/package.test.unit.d.ts +0 -1
- package/dist/node/path/path.test.unit.d.ts +0 -1
- package/dist/react/apollo-error/apollo-error.test.unit.d.ts +0 -1
- package/dist/react/loading/loading.test.unit.d.ts +0 -1
- package/dist/react/storage/storage.test.unit.d.ts +0 -1
- package/dist/typescript/typescript.test.unit.d.ts +0 -1
- package/dist/util/common/common.test.unit.d.ts +0 -1
- package/dist/util/object/object.test.unit.d.ts +0 -1
- package/dist/util/serializer/serializer.test.unit.d.ts +0 -1
- package/dist/util/string/string.test.unit.d.ts +0 -1
- package/dist/util/validate/validate.test.unit.d.ts +0 -1
- /package/dist/node_modules/.pnpm/{vitest@4.0.18_@types_node@25.3.3_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 → 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 -0
|
@@ -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\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.prototype.hasOwnProperty.call(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 ([] as unknown[]).concat(...validArgs) 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.prototype.hasOwnProperty.call(obj, key)) {\n const value = obj[key];\n if (Object.prototype.hasOwnProperty.call(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.concat(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.prototype.hasOwnProperty.call(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.prototype.hasOwnProperty.call(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,OAAOA,KAAY;AACtC;AAGJ,UAAMG,IAAMJ,EAAKG,CAAC;AAElB,QAAIC,MAAQ,UAAaA,KAAQH;AAC7B,MAAAA,IAAWA,EAA6CG,CAAG;AAAA;AAG3D;AAAA,EAER;AAEA,SAAOH;AACX;AAEA,SAASI,EAAwBN,GAAQC,GAA2BM,GAAgBC,GAAkB;AAClG,MAAIA,KAASP,EAAK;AACd,WAAOD;AAEX,QAAMS,IAAOR,EAAKO,CAAK;AAEvB,MAAIA,MAAUP,EAAK,SAAS;AACxB,WAAO;AAAA,MACH,GAAID;AAAA,MACJ,CAACS,CAAuB,GAAGF;AAAA,IAAA;AAInC,QAAML,IAAWF,EAAyCS,CAAuB;AAEjF,SAAO;AAAA,IACH,GAAIT;AAAA,IACJ,CAACS,CAAgC,GAAGH;AAAA,MAChC,OAAOJ,KAAY,YAAYA,MAAY,OACpCA,IACD,CAAA;AAAA,MACND;AAAA,MACAM;AAAA,MACAC,IAAQ;AAAA,IAAA;AAAA,EACZ;AAER;AAYO,SAASE,EAAkBV,GAAQC,GAA2BM,GAAmB;AACpF,SAAIN,EAAK,WAAW,IACTD,IAEJM,EAAq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AAS,OAAOA,KAAU,YAAY,CAAC,MAAM,QAAQA,CAAK,GAAG;AAE7D,YAAIqB,IAAmB;AACvB,mBAAWC,KAAUtB;AACjB,cAAI,OAAO,UAAU,eAAe,KAAKA,GAAOsB,CAAM,KAAKA,EAAO,WAAW,GAAG,GAAG;AAC/E,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","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,OAAOA,KAAY;AACtC;AAGJ,UAAMG,IAAMJ,EAAKG,CAAC;AAElB,QAAIC,MAAQ,UAAaA,KAAQH;AAC7B,MAAAA,IAAWA,EAA6CG,CAAG;AAAA;AAG3D;AAAA,EAER;AAEA,SAAOH;AACX;AAKA,SAASI,EAAwBN,GAAQC,GAA2BM,GAAgBC,GAAkB;AAClG,MAAIA,KAASP,EAAK;AACd,WAAOD;AAEX,QAAMS,IAAOR,EAAKO,CAAK;AAEvB,MAAIA,MAAUP,EAAK,SAAS;AACxB,WAAO;AAAA,MACH,GAAID;AAAA,MACJ,CAACS,CAAuB,GAAGF;AAAA,IAAA;AAInC,QAAML,IAAWF,EAAyCS,CAAuB;AAEjF,SAAO;AAAA,IACH,GAAIT;AAAA,IACJ,CAACS,CAAgC,GAAGH;AAAA,M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vB,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,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const s = {
|
|
2
2
|
Date: {
|
|
3
3
|
is: (e) => e instanceof Date,
|
|
4
4
|
serialize: (e) => ({ __type: "Date", value: e.toISOString() }),
|
|
@@ -6,12 +6,12 @@ const n = {
|
|
|
6
6
|
},
|
|
7
7
|
Map: {
|
|
8
8
|
is: (e) => e instanceof Map,
|
|
9
|
-
serialize: (e) => ({ __type: "Map", value:
|
|
9
|
+
serialize: (e) => ({ __type: "Map", value: [...e.entries()] }),
|
|
10
10
|
deserialize: (e) => new Map(e)
|
|
11
11
|
},
|
|
12
12
|
Set: {
|
|
13
13
|
is: (e) => e instanceof Set,
|
|
14
|
-
serialize: (e) => ({ __type: "Set", value:
|
|
14
|
+
serialize: (e) => ({ __type: "Set", value: [...e] }),
|
|
15
15
|
deserialize: (e) => new Set(e)
|
|
16
16
|
},
|
|
17
17
|
RegExp: {
|
|
@@ -21,8 +21,8 @@ const n = {
|
|
|
21
21
|
value: { source: e.source, flags: e.flags }
|
|
22
22
|
}),
|
|
23
23
|
deserialize: (e) => {
|
|
24
|
-
const { source:
|
|
25
|
-
return new RegExp(
|
|
24
|
+
const { source: n, flags: t } = e;
|
|
25
|
+
return new RegExp(n, t);
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
BigInt: {
|
|
@@ -41,12 +41,12 @@ 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, function(
|
|
45
|
-
const i = this[
|
|
44
|
+
return JSON.stringify(e, function(n, t) {
|
|
45
|
+
const i = this[n];
|
|
46
46
|
if (i instanceof Date)
|
|
47
|
-
return
|
|
48
|
-
for (const o of Object.keys(
|
|
49
|
-
const a =
|
|
47
|
+
return s.Date.serialize(i);
|
|
48
|
+
for (const o of Object.keys(s)) {
|
|
49
|
+
const a = s[o];
|
|
50
50
|
if (a.is(t))
|
|
51
51
|
return a.serialize(t);
|
|
52
52
|
}
|
|
@@ -63,9 +63,9 @@ const n = {
|
|
|
63
63
|
* @returns The deserialized value with all special types reconstructed.
|
|
64
64
|
*/
|
|
65
65
|
deserialize(e) {
|
|
66
|
-
return JSON.parse(e, (
|
|
66
|
+
return JSON.parse(e, (n, t) => {
|
|
67
67
|
if (t && typeof t == "object" && "__type" in t && typeof t.__type == "string") {
|
|
68
|
-
const
|
|
68
|
+
const r = t.__type, i = s[r];
|
|
69
69
|
if (i)
|
|
70
70
|
return i.deserialize(t.value);
|
|
71
71
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.util.js","sources":["../../../src/util/serializer/serializer.util.ts"],"sourcesContent":["import type {\n I_Serializer,\n I_SerializerTypeWrapper,\n I_SerializerValueMap,\n T_SerializerKnownTypes,\n} from './serializer.type.js';\n\n/**\n * Interface for handling serialization and deserialization of specific types.\n * Each handler provides methods to check if a value is of the specific type,\n * serialize it to a format that can be JSON stringified, and deserialize it back.\n */\ninterface I_Handler<T extends T_SerializerKnownTypes> {\n /** Checks if a value is of the specific type */\n is: (value: unknown) => value is I_SerializerValueMap[T];\n /** Serializes a value of the specific type to a format that can be JSON stringified */\n serialize: (value: I_SerializerValueMap[T]) => I_SerializerTypeWrapper<T>;\n /** Deserializes a value back to the specific type */\n deserialize: (value: unknown) => I_SerializerValueMap[T];\n}\n\n/**\n * Type handlers for different JavaScript types that cannot be directly serialized to JSON.\n * Each handler provides methods to serialize and deserialize specific types like Date, Map, Set, etc.\n */\nconst typeHandlers: {\n [K in T_SerializerKnownTypes]: I_Handler<K>;\n} = {\n Date: {\n is: (v): v is Date => v instanceof Date,\n serialize: v => ({ __type: 'Date', value: v.toISOString() }),\n deserialize: v => new Date(v as string),\n },\n Map: {\n is: (v): v is Map<unknown, unknown> => v instanceof Map,\n serialize: v => ({ __type: 'Map', value:
|
|
1
|
+
{"version":3,"file":"serializer.util.js","sources":["../../../src/util/serializer/serializer.util.ts"],"sourcesContent":["import type {\n I_Serializer,\n I_SerializerTypeWrapper,\n I_SerializerValueMap,\n T_SerializerKnownTypes,\n} from './serializer.type.js';\n\n/**\n * Interface for handling serialization and deserialization of specific types.\n * Each handler provides methods to check if a value is of the specific type,\n * serialize it to a format that can be JSON stringified, and deserialize it back.\n */\ninterface I_Handler<T extends T_SerializerKnownTypes> {\n /** Checks if a value is of the specific type */\n is: (value: unknown) => value is I_SerializerValueMap[T];\n /** Serializes a value of the specific type to a format that can be JSON stringified */\n serialize: (value: I_SerializerValueMap[T]) => I_SerializerTypeWrapper<T>;\n /** Deserializes a value back to the specific type */\n deserialize: (value: unknown) => I_SerializerValueMap[T];\n}\n\n/**\n * Type handlers for different JavaScript types that cannot be directly serialized to JSON.\n * Each handler provides methods to serialize and deserialize specific types like Date, Map, Set, etc.\n */\nconst typeHandlers: {\n [K in T_SerializerKnownTypes]: I_Handler<K>;\n} = {\n Date: {\n is: (v): v is Date => v instanceof Date,\n serialize: v => ({ __type: 'Date', value: v.toISOString() }),\n deserialize: v => new Date(v as string),\n },\n Map: {\n is: (v): v is Map<unknown, unknown> => v instanceof Map,\n serialize: v => ({ __type: 'Map', value: [...v.entries()] }),\n deserialize: v => new Map(v as [unknown, unknown][]),\n },\n Set: {\n is: (v): v is Set<unknown> => v instanceof Set,\n serialize: v => ({ __type: 'Set', value: [...v] }),\n deserialize: v => new Set(v as unknown[]),\n },\n RegExp: {\n is: (v): v is RegExp => v instanceof RegExp,\n serialize: v => ({\n __type: 'RegExp',\n value: { source: v.source, flags: v.flags },\n }),\n deserialize: (v) => {\n const { source, flags } = v as { source: string; flags: string };\n return new RegExp(source, flags);\n },\n },\n BigInt: {\n is: (v): v is bigint => typeof v === 'bigint',\n serialize: v => ({ __type: 'BigInt', value: v.toString() }),\n deserialize: v => BigInt(v as string),\n },\n};\n\n/**\n * A serializer that can handle complex JavaScript types that cannot be directly JSON stringified.\n * This serializer extends JSON.stringify and JSON.parse to handle types like Date, Map, Set, RegExp, and BigInt.\n *\n * The serializer works by:\n * 1. During serialization: Wrapping special types with type information before JSON stringification\n * 2. During deserialization: Detecting wrapped types and reconstructing them to their original form\n */\nexport const serializer: I_Serializer<unknown> = {\n /**\n * Serializes a value to a JSON string.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be serialized using the corresponding handler.\n * Otherwise, it will be serialized as is.\n *\n * @param value - The value to serialize to a JSON string.\n * @returns The serialized JSON string that can be safely stored or transmitted.\n */\n serialize(value) {\n return JSON.stringify(value, function (_key, val) {\n // eslint-disable-next-line ts/no-this-alias\n const context = this;\n const originalValue = context[_key];\n\n if (originalValue instanceof Date) {\n return typeHandlers.Date.serialize(originalValue);\n }\n\n for (const type of Object.keys(typeHandlers) as T_SerializerKnownTypes[]) {\n const handler = typeHandlers[type];\n\n if (handler.is(val)) {\n return (handler as I_Handler<typeof type>).serialize(val);\n }\n }\n\n return val;\n });\n },\n /**\n * Deserializes a JSON string to its original value.\n * If the value is of a known type (Date, Map, Set, RegExp, BigInt),\n * it will be deserialized using the corresponding handler.\n * Otherwise, it will be deserialized as is.\n *\n * @param json - The JSON string to deserialize back to its original form.\n * @returns The deserialized value with all special types reconstructed.\n */\n deserialize(json) {\n return JSON.parse(json, (_key, val) => {\n if (\n val\n && typeof val === 'object'\n && '__type' in val\n && typeof val.__type === 'string'\n ) {\n const type = val.__type as T_SerializerKnownTypes;\n const handler = typeHandlers[type];\n\n if (handler) {\n return handler.deserialize(val.value);\n }\n }\n return val;\n });\n },\n};\n"],"names":["typeHandlers","v","source","flags","serializer","value","_key","val","originalValue","type","handler","json"],"mappings":"AAyBA,MAAMA,IAEF;AAAA,EACA,MAAM;AAAA,IACF,IAAI,CAACC,MAAiBA,aAAa;AAAA,IACnC,WAAW,QAAM,EAAE,QAAQ,QAAQ,OAAOA,EAAE;IAC5C,aAAa,CAAAA,MAAK,IAAI,KAAKA,CAAW;AAAA,EAAA;AAAA,EAE1C,KAAK;AAAA,IACD,IAAI,CAACA,MAAkCA,aAAa;AAAA,IACpD,WAAW,CAAAA,OAAM,EAAE,QAAQ,OAAO,OAAO,CAAC,GAAGA,EAAE,QAAA,CAAS;IACxD,aAAa,CAAAA,MAAK,IAAI,IAAIA,CAAyB;AAAA,EAAA;AAAA,EAEvD,KAAK;AAAA,IACD,IAAI,CAACA,MAAyBA,aAAa;AAAA,IAC3C,WAAW,QAAM,EAAE,QAAQ,OAAO,OAAO,CAAC,GAAGA,CAAC;IAC9C,aAAa,CAAAA,MAAK,IAAI,IAAIA,CAAc;AAAA,EAAA;AAAA,EAE5C,QAAQ;AAAA,IACJ,IAAI,CAACA,MAAmBA,aAAa;AAAA,IACrC,WAAW,CAAAA,OAAM;AAAA,MACb,QAAQ;AAAA,MACR,OAAO,EAAE,QAAQA,EAAE,QAAQ,OAAOA,EAAE,MAAA;AAAA,IAAM;AAAA,IAE9C,aAAa,CAACA,MAAM;AAChB,YAAM,EAAE,QAAAC,GAAQ,OAAAC,EAAA,IAAUF;AAC1B,aAAO,IAAI,OAAOC,GAAQC,CAAK;AAAA,IACnC;AAAA,EAAA;AAAA,EAEJ,QAAQ;AAAA,IACJ,IAAI,CAACF,MAAmB,OAAOA,KAAM;AAAA,IACrC,WAAW,QAAM,EAAE,QAAQ,UAAU,OAAOA,EAAE;IAC9C,aAAa,CAAAA,MAAK,OAAOA,CAAW;AAAA,EAAA;AAE5C,GAUaG,IAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAU7C,UAAUC,GAAO;AACb,WAAO,KAAK,UAAUA,GAAO,SAAUC,GAAMC,GAAK;AAG9C,YAAMC,IADU,KACcF,CAAI;AAElC,UAAIE,aAAyB;AACzB,eAAOR,EAAa,KAAK,UAAUQ,CAAa;AAGpD,iBAAWC,KAAQ,OAAO,KAAKT,CAAY,GAA+B;AACtE,cAAMU,IAAUV,EAAaS,CAAI;AAEjC,YAAIC,EAAQ,GAAGH,CAAG;AACd,iBAAQG,EAAmC,UAAUH,CAAG;AAAA,MAEhE;AAEA,aAAOA;AAAA,IACX,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,YAAYI,GAAM;AACd,WAAO,KAAK,MAAMA,GAAM,CAACL,GAAMC,MAAQ;AACnC,UACIA,KACG,OAAOA,KAAQ,YACf,YAAYA,KACZ,OAAOA,EAAI,UAAW,UAC3B;AACE,cAAME,IAAOF,EAAI,QACXG,IAAUV,EAAaS,CAAI;AAEjC,YAAIC;AACA,iBAAOA,EAAQ,YAAYH,EAAI,KAAK;AAAA,MAE5C;AACA,aAAOA;AAAA,IACX,CAAC;AAAA,EACL;AACJ;"}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
|
-
import { removeAccent as
|
|
2
|
-
|
|
1
|
+
import { removeAccent as l } from "../common/common.util.js";
|
|
2
|
+
const u = /[^a-z0-9\s-]/gi, g = /[\s-]+/g, m = /^-+|-+$/g, h = /-/g, R = /[?#]/;
|
|
3
|
+
function d(e, n) {
|
|
3
4
|
let t = e.trim();
|
|
4
|
-
return t =
|
|
5
|
+
return t = l(t), n?.lower !== !1 && (t = t.toLowerCase()), t = t.replace(u, " "), t = t.replace(g, "-"), t = t.replace(m, ""), t;
|
|
5
6
|
}
|
|
6
|
-
function
|
|
7
|
-
const t = (r) =>
|
|
7
|
+
function E(e, n) {
|
|
8
|
+
const t = (r) => d(r ?? "", n);
|
|
8
9
|
if (typeof e == "object" && e !== null) {
|
|
9
10
|
const r = {};
|
|
10
|
-
for (const [o,
|
|
11
|
-
r[o] = t(
|
|
11
|
+
for (const [o, s] of Object.entries(e))
|
|
12
|
+
r[o] = t(s);
|
|
12
13
|
return r;
|
|
13
14
|
}
|
|
14
15
|
return t(e);
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function _(e, n = 4) {
|
|
17
18
|
let t = 2166136261;
|
|
18
19
|
for (let o = 0; o < e.length; o++)
|
|
19
20
|
t ^= e.charCodeAt(o), t = Math.imul(t, 16777619);
|
|
20
21
|
const r = (t >>> 0).toString(16).padStart(8, "0");
|
|
21
|
-
return n > 8 ? e.replace(
|
|
22
|
+
return n > 8 ? e.replace(h, "").slice(0, n) : r.slice(0, n);
|
|
22
23
|
}
|
|
23
|
-
function
|
|
24
|
+
function c(e, n) {
|
|
24
25
|
const t = Math.floor(4294967296 / n.length) * n.length, r = [], o = 16384;
|
|
25
26
|
for (; r.length < e; ) {
|
|
26
|
-
const
|
|
27
|
-
crypto.getRandomValues(
|
|
28
|
-
for (const a of
|
|
27
|
+
const s = e - r.length, f = s > o ? o : s, i = new Uint32Array(f);
|
|
28
|
+
crypto.getRandomValues(i);
|
|
29
|
+
for (const a of i) {
|
|
29
30
|
if (r.length >= e)
|
|
30
31
|
break;
|
|
31
32
|
a < t && r.push(n[a % n.length]);
|
|
@@ -33,38 +34,38 @@ function f(e, n) {
|
|
|
33
34
|
}
|
|
34
35
|
return r.join("");
|
|
35
36
|
}
|
|
36
|
-
function
|
|
37
|
+
function A(e = 8) {
|
|
37
38
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
38
39
|
throw new RangeError("length must be a non-negative safe integer");
|
|
39
|
-
return
|
|
40
|
+
return c(e, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?");
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
+
function b(e = 8, n = "abcdefghijklmnopqrstuvwxyz0123456789") {
|
|
42
43
|
if (!Number.isSafeInteger(e) || e < 0)
|
|
43
44
|
throw new RangeError("length must be a non-negative safe integer");
|
|
44
45
|
if (n.length === 0 || n.length > 2 ** 32)
|
|
45
46
|
throw new RangeError("charset.length must be between 1 and 2^32");
|
|
46
|
-
return
|
|
47
|
+
return c(e, n);
|
|
47
48
|
}
|
|
48
|
-
function
|
|
49
|
-
const t = e.split(
|
|
49
|
+
function N(e = "", n = !1) {
|
|
50
|
+
const t = e.split(R)[0] || "", r = t.substring(t.lastIndexOf("/") + 1);
|
|
50
51
|
if (n)
|
|
51
52
|
return r;
|
|
52
53
|
const o = r.lastIndexOf(".");
|
|
53
54
|
return o > 0 ? r.slice(0, o) : r;
|
|
54
55
|
}
|
|
55
|
-
function
|
|
56
|
+
function S(e, n, t) {
|
|
56
57
|
const r = e.indexOf(n);
|
|
57
58
|
if (r === -1)
|
|
58
59
|
return "";
|
|
59
|
-
const o = r + n.length,
|
|
60
|
-
return
|
|
60
|
+
const o = r + n.length, s = e.indexOf(t, o);
|
|
61
|
+
return s === -1 ? "" : e.slice(o, s);
|
|
61
62
|
}
|
|
62
63
|
export {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
A as generateRandomPassword,
|
|
65
|
+
b as generateRandomString,
|
|
66
|
+
_ as generateShortId,
|
|
67
|
+
E as generateSlug,
|
|
68
|
+
N as getFileName,
|
|
69
|
+
S as substringBetween
|
|
69
70
|
};
|
|
70
71
|
//# sourceMappingURL=string.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.util.js","sources":["../../../src/util/string/string.util.ts"],"sourcesContent":["import type { T_Object } from '#typescript/index.js';\n\nimport type { I_SlugifyOptions } from './string.type.js';\n\nimport { removeAccent } from '../common/common.util.js';\n\n/**\n * Generates a slug from a string.\n * The slug is a URL-friendly version of the string, removing special characters\n * and converting spaces to hyphens.\n *\n * @param input - The string to be slugified.\n * @param options - Options for slugification.\n * @returns The slugified string.\n */\nfunction slugify(input: string, options?: I_SlugifyOptions): string {\n let slug = input.trim();\n\n // 1. Remove accents\n slug = removeAccent(slug);\n\n // 2. To lower case if requested (default true)\n if (options?.lower !== false) {\n slug = slug.toLowerCase();\n }\n\n // 3. Replace invalid characters with space (keeping alphanumeric, hyphens, and spaces)\n slug = slug.replace(/[^a-z0-9\\s-]/gi, ' ');\n\n // 4. Replace multiple spaces or hyphens with a single hyphen\n slug = slug.replace(/[\\s-]+/g, '-');\n\n // 5. Remove leading/trailing hyphens\n slug = slug.replace(/^-+|-+$/g, '');\n\n return slug;\n}\n\n/**\n * Generates a slug from a string or an object containing strings.\n * The slug is a URL-friendly version of the string, removing special characters\n * and converting spaces to hyphens. This function can handle both single strings\n * and objects with string values.\n *\n * @param input - The string or object to be slugified.\n * @param options - Options for slugification including replacement character, case sensitivity, locale, etc.\n * @returns The slugified string or object with the same structure as the input.\n */\nexport function generateSlug<T = string>(\n input: T,\n options?: I_SlugifyOptions,\n): T {\n const slugifyWithOptions = (value: string) =>\n slugify(value ?? '', options);\n\n if (typeof input === 'object' && input !== null) {\n const result: T_Object = {};\n\n for (const [key, value] of Object.entries(input)) {\n result[key] = slugifyWithOptions(value as string);\n }\n\n return result as T;\n }\n\n return slugifyWithOptions(input as string) as T;\n}\n\n/**\n * Generates a short ID from a UUID.\n * The ID is a substring of the UUID, providing a shorter identifier.\n * Note: This is NOT cryptographically secure and collisions are possible,\n * but suitable for display purposes where uniqueness is handled elsewhere.\n *\n * @param uuid - The UUID to be converted to a short ID.\n * @param length - The desired length of the short ID (default: 4 characters).\n * @returns A short ID string of the specified length derived from the UUID.\n */\nexport function generateShortId(uuid: string, length = 4): string {\n // Simple hash function (FNV-1a variant) to generate a hex string from the UUID\n let hash = 0x811C9DC5;\n for (let i = 0; i < uuid.length; i++) {\n hash ^= uuid.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n // Convert to unsigned 32-bit integer hex string\n const hex = (hash >>> 0).toString(16).padStart(8, '0');\n\n // If we need more than 8 chars, we can just append part of the original UUID (stripped of dashes)\n // or use a different strategy. For short IDs (usually < 8), the hash is fine.\n // If length > 8, we fallback to just slicing the clean UUID.\n if (length > 8) {\n return uuid.replace(/-/g, '').slice(0, length);\n }\n\n return hex.slice(0, length);\n}\n\n/**\n * Internal helper that fills `length` characters from `charset` using\n * rejection-sampling over `crypto.getRandomValues` to avoid modulo bias.\n * Random values are requested in bounded chunks to keep allocations small.\n *\n * @param length - Number of characters to generate.\n * @param charset - The pool of characters to draw from.\n * @returns A randomly generated string of the requested length.\n */\nfunction generateRandomFromCharset(length: number, charset: string): string {\n const limit = Math.floor(2 ** 32 / charset.length) * charset.length;\n const result: string[] = [];\n const MAX_UINT32_VALUES_PER_CALL = 16384;\n\n while (result.length < length) {\n const remaining = length - result.length;\n const chunkSize = remaining > MAX_UINT32_VALUES_PER_CALL ? MAX_UINT32_VALUES_PER_CALL : remaining;\n const values = new Uint32Array(chunkSize);\n crypto.getRandomValues(values);\n\n for (const value of values) {\n if (result.length >= length) {\n break;\n }\n if (value < limit) {\n result.push(charset[value % charset.length] as string);\n }\n }\n }\n\n return result.join('');\n}\n\n/**\n * Generates a random password of a given length.\n * The password contains a mix of letters (both cases), numbers, and special characters\n * to ensure complexity and security.\n *\n * @param length - The desired length of the password (default: 8 characters).\n * @returns A randomly generated password string with the specified length.\n * @throws {RangeError} If `length` is not a non-negative safe integer.\n */\nexport function generateRandomPassword(length = 8): string {\n if (!Number.isSafeInteger(length) || length < 0) {\n throw new RangeError('length must be a non-negative safe integer');\n }\n\n const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?';\n\n return generateRandomFromCharset(length, charset);\n}\n\n/**\n * Generates a random string of a given length using a secure random number generator.\n * This function is a cryptographically secure alternative to Math.random().toString(36).\n *\n * @param length - The desired length of the string (default: 8 characters).\n * @param charset - The characters to use (default: lowercase alphanumeric).\n * @returns A randomly generated string.\n * @throws {RangeError} If `length` is not a non-negative safe integer.\n * @throws {RangeError} If `charset` is empty or exceeds 2^32 characters.\n */\nexport function generateRandomString(\n length = 8,\n charset = 'abcdefghijklmnopqrstuvwxyz0123456789',\n): string {\n if (!Number.isSafeInteger(length) || length < 0) {\n throw new RangeError('length must be a non-negative safe integer');\n }\n\n if (charset.length === 0 || charset.length > 2 ** 32) {\n throw new RangeError('charset.length must be between 1 and 2^32');\n }\n\n return generateRandomFromCharset(length, charset);\n}\n\n/**\n * Get the file name from a URL.\n * This function extracts the file name from a URL, optionally including or excluding\n * the file extension. It handles URLs with query parameters and fragments.\n *\n * @param url - The URL to extract the file name from (default: empty string).\n * @param getExtension - Whether to include the file extension in the result (default: false).\n * @returns The file name extracted from the URL, with or without the extension.\n */\nexport function getFileName(url = '', getExtension = false): string {\n const withoutQuery = url.split(/[?#]/)[0] || '';\n const fileName = withoutQuery.substring(withoutQuery.lastIndexOf('/') + 1);\n\n if (getExtension) {\n return fileName;\n }\n\n const dotIndex = fileName.lastIndexOf('.');\n\n return dotIndex > 0 ? fileName.slice(0, dotIndex) : fileName;\n}\n\n/**\n * Extracts a substring between two strings.\n * This function finds the first occurrence of the starting string, then finds the first\n * occurrence of the ending string after the starting string, and returns the content between them.\n *\n * @param s - The original string to search within.\n * @param a - The starting string that marks the beginning of the desired substring.\n * @param b - The ending string that marks the end of the desired substring.\n * @returns The substring between the two specified strings, or an empty string if either string is not found.\n */\nexport function substringBetween(s: string, a: string, b: string): string {\n const start = s.indexOf(a);\n\n if (start === -1) {\n return '';\n }\n\n const from = start + a.length;\n const end = s.indexOf(b, from);\n\n if (end === -1) {\n return '';\n }\n\n return s.slice(from, end);\n}\n"],"names":["removeAccent","slugify","input","options","slug","generateSlug","slugifyWithOptions","value","result","key","generateShortId","uuid","length","hash","i","hex","generateRandomFromCharset","charset","limit","MAX_UINT32_VALUES_PER_CALL","remaining","chunkSize","values","generateRandomPassword","generateRandomString","getFileName","url","getExtension","withoutQuery","fileName","dotIndex","substringBetween","s","a","b","start","from","end"],"mappings":"AAeA,SAAA,gBAAAA,SAAA;AAAA,SAASC,EAAQC,GAAeC,GAAoC;AAChE,MAAIC,IAAOF,EAAM,KAAA;AAGjB,SAAAE,IAAOJ,EAAaI,CAAI,GAGpBD,GAAS,UAAU,OACnBC,IAAOA,EAAK,YAAA,IAIhBA,IAAOA,EAAK,QAAQ,kBAAkB,GAAG,GAGzCA,IAAOA,EAAK,QAAQ,WAAW,GAAG,GAGlCA,IAAOA,EAAK,QAAQ,YAAY,EAAE,GAE3BA;AACX;AAYO,SAASC,EACZH,GACAC,GACC;AACD,QAAMG,IAAqB,CAACC,MACxBN,EAAQM,KAAS,IAAIJ,CAAO;AAEhC,MAAI,OAAOD,KAAU,YAAYA,MAAU,MAAM;AAC7C,UAAMM,IAAmB,CAAA;AAEzB,eAAW,CAACC,GAAKF,CAAK,KAAK,OAAO,QAAQL,CAAK;AAC3C,MAAAM,EAAOC,CAAG,IAAIH,EAAmBC,CAAe;AAGpD,WAAOC;AAAA,EACX;AAEA,SAAOF,EAAmBJ,CAAe;AAC7C;AAYO,SAASQ,EAAgBC,GAAcC,IAAS,GAAW;AAE9D,MAAIC,IAAO;AACX,WAASC,IAAI,GAAGA,IAAIH,EAAK,QAAQG;AAC7B,IAAAD,KAAQF,EAAK,WAAWG,CAAC,GACzBD,IAAO,KAAK,KAAKA,GAAM,QAAU;AAGrC,QAAME,KAAOF,MAAS,GAAG,SAAS,EAAE,EAAE,SAAS,GA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WAAOE;AAGX,QAAMC,IAAWD,EAAS,YAAY,GAAG;AAEzC,SAAOC,IAAW,IAAID,EAAS,MAAM,GAAGC,CAAQ,IAAID;AACxD;AAYO,SAASE,EAAiBC,GAAWC,GAAWC,GAAmB;AACtE,QAAMC,IAAQH,EAAE,QAAQC,CAAC;AAEzB,MAAIE,MAAU;AACV,WAAO;AAGX,QAAMC,IAAOD,IAAQF,EAAE,QACjBI,IAAML,EAAE,QAAQE,GAAGE,CAAI;AAE7B,SAAIC,MAAQ,KACD,KAGJL,EAAE,MAAMI,GAAMC,CAAG;AAC5B;"}
|
|
1
|
+
{"version":3,"file":"string.util.js","sources":["../../../src/util/string/string.util.ts"],"sourcesContent":["import type { T_Object } from '#typescript/index.js';\n\nimport type { I_SlugifyOptions } from './string.type.js';\n\nimport { removeAccent } from '../common/common.util.js';\n\nconst RE_NON_ALNUM = /[^a-z0-9\\s-]/gi;\nconst RE_MULTI_SPACE_DASH = /[\\s-]+/g;\nconst RE_LEADING_TRAILING_DASH = /^-+|-+$/g;\nconst RE_HYPHEN = /-/g;\nconst RE_QUERY_FRAGMENT = /[?#]/;\n\n/**\n * Generates a slug from a string.\n * The slug is a URL-friendly version of the string, removing special characters\n * and converting spaces to hyphens.\n *\n * @param input - The string to be slugified.\n * @param options - Options for slugification.\n * @returns The slugified string.\n */\nfunction slugify(input: string, options?: I_SlugifyOptions): string {\n let slug = input.trim();\n\n // 1. Remove accents\n slug = removeAccent(slug);\n\n // 2. To lower case if requested (default true)\n if (options?.lower !== false) {\n slug = slug.toLowerCase();\n }\n\n // 3. Replace invalid characters with space (keeping alphanumeric, hyphens, and spaces)\n slug = slug.replace(RE_NON_ALNUM, ' ');\n\n // 4. Replace multiple spaces or hyphens with a single hyphen\n slug = slug.replace(RE_MULTI_SPACE_DASH, '-');\n\n // 5. Remove leading/trailing hyphens\n slug = slug.replace(RE_LEADING_TRAILING_DASH, '');\n\n return slug;\n}\n\n/**\n * Generates a slug from a string or an object containing strings.\n * The slug is a URL-friendly version of the string, removing special characters\n * and converting spaces to hyphens. This function can handle both single strings\n * and objects with string values.\n *\n * @param input - The string or object to be slugified.\n * @param options - Options for slugification including replacement character, case sensitivity, locale, etc.\n * @returns The slugified string or object with the same structure as the input.\n */\nexport function generateSlug<T = string>(\n input: T,\n options?: I_SlugifyOptions,\n): T {\n const slugifyWithOptions = (value: string) =>\n slugify(value ?? '', options);\n\n if (typeof input === 'object' && input !== null) {\n const result: T_Object = {};\n\n for (const [key, value] of Object.entries(input)) {\n result[key] = slugifyWithOptions(value as string);\n }\n\n return result as T;\n }\n\n return slugifyWithOptions(input as string) as T;\n}\n\n/**\n * Generates a short ID from a UUID.\n * The ID is a substring of the UUID, providing a shorter identifier.\n * Note: This is NOT cryptographically secure and collisions are possible,\n * but suitable for display purposes where uniqueness is handled elsewhere.\n *\n * @param uuid - The UUID to be converted to a short ID.\n * @param length - The desired length of the short ID (default: 4 characters).\n * @returns A short ID string of the specified length derived from the UUID.\n */\nexport function generateShortId(uuid: string, length = 4): string {\n // Simple hash function (FNV-1a variant) to generate a hex string from the UUID\n let hash = 0x811C9DC5;\n for (let i = 0; i < uuid.length; i++) {\n hash ^= uuid.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193);\n }\n // Convert to unsigned 32-bit integer hex string\n const hex = (hash >>> 0).toString(16).padStart(8, '0');\n\n // If we need more than 8 chars, we can just append part of the original UUID (stripped of dashes)\n // or use a different strategy. For short IDs (usually < 8), the hash is fine.\n // If length > 8, we fallback to just slicing the clean UUID.\n if (length > 8) {\n return uuid.replace(RE_HYPHEN, '').slice(0, length);\n }\n\n return hex.slice(0, length);\n}\n\n/**\n * Internal helper that fills `length` characters from `charset` using\n * rejection-sampling over `crypto.getRandomValues` to avoid modulo bias.\n * Random values are requested in bounded chunks to keep allocations small.\n *\n * @param length - Number of characters to generate.\n * @param charset - The pool of characters to draw from.\n * @returns A randomly generated string of the requested length.\n */\nfunction generateRandomFromCharset(length: number, charset: string): string {\n const limit = Math.floor(2 ** 32 / charset.length) * charset.length;\n const result: string[] = [];\n const MAX_UINT32_VALUES_PER_CALL = 16384;\n\n while (result.length < length) {\n const remaining = length - result.length;\n const chunkSize = remaining > MAX_UINT32_VALUES_PER_CALL ? MAX_UINT32_VALUES_PER_CALL : remaining;\n const values = new Uint32Array(chunkSize);\n crypto.getRandomValues(values);\n\n for (const value of values) {\n if (result.length >= length) {\n break;\n }\n if (value < limit) {\n result.push(charset[value % charset.length] as string);\n }\n }\n }\n\n return result.join('');\n}\n\n/**\n * Generates a random password of a given length.\n * The password contains a mix of letters (both cases), numbers, and special characters\n * to ensure complexity and security.\n *\n * @param length - The desired length of the password (default: 8 characters).\n * @returns A randomly generated password string with the specified length.\n * @throws {RangeError} If `length` is not a non-negative safe integer.\n */\nexport function generateRandomPassword(length = 8): string {\n if (!Number.isSafeInteger(length) || length < 0) {\n throw new RangeError('length must be a non-negative safe integer');\n }\n\n const charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?';\n\n return generateRandomFromCharset(length, charset);\n}\n\n/**\n * Generates a random string of a given length using a secure random number generator.\n * This function is a cryptographically secure alternative to Math.random().toString(36).\n *\n * @param length - The desired length of the string (default: 8 characters).\n * @param charset - The characters to use (default: lowercase alphanumeric).\n * @returns A randomly generated string.\n * @throws {RangeError} If `length` is not a non-negative safe integer.\n * @throws {RangeError} If `charset` is empty or exceeds 2^32 characters.\n */\nexport function generateRandomString(\n length = 8,\n charset = 'abcdefghijklmnopqrstuvwxyz0123456789',\n): string {\n if (!Number.isSafeInteger(length) || length < 0) {\n throw new RangeError('length must be a non-negative safe integer');\n }\n\n if (charset.length === 0 || charset.length > 2 ** 32) {\n throw new RangeError('charset.length must be between 1 and 2^32');\n }\n\n return generateRandomFromCharset(length, charset);\n}\n\n/**\n * Get the file name from a URL.\n * This function extracts the file name from a URL, optionally including or excluding\n * the file extension. It handles URLs with query parameters and fragments.\n *\n * @param url - The URL to extract the file name from (default: empty string).\n * @param getExtension - Whether to include the file extension in the result (default: false).\n * @returns The file name extracted from the URL, with or without the extension.\n */\nexport function getFileName(url = '', getExtension = false): string {\n const withoutQuery = url.split(RE_QUERY_FRAGMENT)[0] || '';\n const fileName = withoutQuery.substring(withoutQuery.lastIndexOf('/') + 1);\n\n if (getExtension) {\n return fileName;\n }\n\n const dotIndex = fileName.lastIndexOf('.');\n\n return dotIndex > 0 ? fileName.slice(0, dotIndex) : fileName;\n}\n\n/**\n * Extracts a substring between two strings.\n * This function finds the first occurrence of the starting string, then finds the first\n * occurrence of the ending string after the starting string, and returns the content between them.\n *\n * @param s - The original string to search within.\n * @param a - The starting string that marks the beginning of the desired substring.\n * @param b - The ending string that marks the end of the desired substring.\n * @returns The substring between the two specified strings, or an empty string if either string is not found.\n */\nexport function substringBetween(s: string, a: string, b: string): string {\n const start = s.indexOf(a);\n\n if (start === -1) {\n return '';\n }\n\n const from = start + a.length;\n const end = s.indexOf(b, from);\n\n if (end === -1) {\n return '';\n }\n\n return s.slice(from, end);\n}\n"],"names":["RE_NON_ALNUM","RE_MULTI_SPACE_DASH","RE_LEADING_TRAILING_DASH","RE_HYPHEN","RE_QUERY_FRAGMENT","slugify","input","options","slug","removeAccent","generateSlug","slugifyWithOptions","value","result","key","generateShortId","uuid","length","hash","i","hex","generateRandomFromCharset","charset","limit","MAX_UINT32_VALUES_PER_CALL","remaining","chunkSize","values","generateRandomPassword","generateRandomString","getFileName","url","getExtension","withoutQuery","fileName","dotIndex","substringBetween","s","a","b","start","from","end"],"mappings":";AAMA,MAAMA,IAAe,kBACfC,IAAsB,WACtBC,IAA2B,YAC3BC,IAAY,MACZC,IAAoB;AAW1B,SAASC,EAAQC,GAAeC,GAAoC;AAChE,MAAIC,IAAOF,EAAM,KAAA;AAGjB,SAAAE,IAAOC,EAAaD,CAAI,GAGpBD,GAAS,UAAU,OACnBC,IAAOA,EAAK,YAAA,IAIhBA,IAAOA,EAAK,QAAQR,GAA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|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|:[a-f\d]{1,4}|:)|(?:[a-f\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,2}|:)|(?:[a-f\d]{1,4}:){4}(?:(?::[a-f\d]{1,4})?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,3}|:)|(?:[a-f\d]{1,4}:){3}(?:(?::[a-f\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,4}|:)|(?:[a-f\d]{1,4}:){2}(?:(?::[a-f\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,5}|:)|[a-f\d]{1,4}:(?:(?::[a-f\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,6}|:)|:(?:(?::[a-f\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}|(?::[a-f\d]{1,4}){1,7}|:))(?:%[0-9a-z]+)?$/i, e = {
|
|
2
2
|
/**
|
|
3
3
|
* Checks if a value is empty.
|
|
4
4
|
* This function provides comprehensive empty checking for different data types:
|
|
@@ -30,8 +30,8 @@ const e = {
|
|
|
30
30
|
isValidIP(d) {
|
|
31
31
|
const f = d.split(".");
|
|
32
32
|
return f.length === 4 && f.every(
|
|
33
|
-
(t) =>
|
|
34
|
-
) ? !0 :
|
|
33
|
+
(t) => r.test(t) && Number(t) >= 0 && Number(t) <= 255
|
|
34
|
+
) ? !0 : n.test(d);
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.util.js","sources":["../../../src/util/validate/validate.util.ts"],"sourcesContent":["/**\n * A collection of validation utility functions for common data validation tasks.\n * This object provides methods to validate various data types and formats.\n */\
|
|
1
|
+
{"version":3,"file":"validate.util.js","sources":["../../../src/util/validate/validate.util.ts"],"sourcesContent":["/**\n * A collection of validation utility functions for common data validation tasks.\n * This object provides methods to validate various data types and formats.\n */\nconst RE_DIGITS_ONLY = /^\\d+$/;\nconst RE_IPV6 = /^(?:(?:[a-f\\d]{1,4}:){7}(?:[a-f\\d]{1,4}|:)|(?:[a-f\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-f\\d]{1,4}|:)|(?:[a-f\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-f\\d]{1,4}){1,2}|:)|(?:[a-f\\d]{1,4}:){4}(?:(?::[a-f\\d]{1,4})?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-f\\d]{1,4}){1,3}|:)|(?:[a-f\\d]{1,4}:){3}(?:(?::[a-f\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-f\\d]{1,4}){1,4}|:)|(?:[a-f\\d]{1,4}:){2}(?:(?::[a-f\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-f\\d]{1,4}){1,5}|:)|[a-f\\d]{1,4}:(?:(?::[a-f\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-f\\d]{1,4}){1,6}|:)|:(?:(?::[a-f\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-f\\d]{1,4}){1,7}|:))(?:%[0-9a-z]+)?$/i;\n\nexport const validate = {\n /**\n * Checks if a value is empty.\n * This function provides comprehensive empty checking for different data types:\n * - For strings, it checks if the string is empty or contains only whitespace.\n * - For arrays, it checks if the array has no elements.\n * - For objects, it checks if the object has no own properties.\n * - For Maps and Sets, it checks if they are empty.\n * - For WeakMaps and WeakSets, it returns true (as they are not enumerable).\n * - For ArrayBuffer views, it checks if the byte length is 0.\n * - For Dates, it returns false.\n * - For null and undefined, it returns true.\n * - For all other types, it returns false.\n *\n * @param value - The value to check for emptiness.\n * @returns True if the value is empty, false otherwise.\n */\n isEmpty(value: unknown): boolean {\n if (value === null || value === undefined) {\n return true;\n }\n\n if (typeof value === 'string') {\n return value.trim().length === 0;\n }\n\n if (Array.isArray(value)) {\n return value.length === 0;\n }\n\n if (typeof value === 'object') {\n if (value instanceof Date) {\n return false;\n }\n\n if (value instanceof Map || value instanceof Set) {\n return value.size === 0;\n }\n\n if (value instanceof WeakMap || value instanceof WeakSet) {\n return true;\n }\n\n if (ArrayBuffer.isView(value)) {\n return value.byteLength === 0;\n }\n\n return Object.keys(value).length === 0;\n }\n\n return false;\n },\n /**\n * Checks if a string is a valid IP address (IPv4 or IPv6).\n * This function validates IP addresses according to standard formats:\n * - IPv4: Four octets separated by dots, each between 0–255.\n * - IPv6: Eight groups of four hex digits, possibly compressed with `::`.\n *\n * @param ip - The IP address string to validate.\n * @returns True if the IP is valid IPv4 or IPv6, false otherwise.\n */\n isValidIP(ip: string): boolean {\n const ipv4Parts = ip.split('.');\n\n if (ipv4Parts.length === 4 && ipv4Parts.every(octet =>\n RE_DIGITS_ONLY.test(octet)\n && Number(octet) >= 0\n && Number(octet) <= 255,\n )) {\n return true;\n }\n\n return RE_IPV6.test(ip);\n },\n};\n"],"names":["RE_DIGITS_ONLY","RE_IPV6","validate","value","ip","ipv4Parts","octet"],"mappings":"AAIA,MAAMA,IAAiB,SACjBC,IAAU,gjCAEHC,IAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBpB,QAAQC,GAAyB;AAC7B,WAAIA,KAAU,OACH,KAGP,OAAOA,KAAU,WACVA,EAAM,OAAO,WAAW,IAG/B,MAAM,QAAQA,CAAK,IACZA,EAAM,WAAW,IAGxB,OAAOA,KAAU,WACbA,aAAiB,OACV,KAGPA,aAAiB,OAAOA,aAAiB,MAClCA,EAAM,SAAS,IAGtBA,aAAiB,WAAWA,aAAiB,UACtC,KAGP,YAAY,OAAOA,CAAK,IACjBA,EAAM,eAAe,IAGzB,OAAO,KAAKA,CAAK,EAAE,WAAW,IAGlC;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,UAAUC,GAAqB;AAC3B,UAAMC,IAAYD,EAAG,MAAM,GAAG;AAE9B,WAAIC,EAAU,WAAW,KAAKA,EAAU;AAAA,MAAM,CAAAC,MAC1CN,EAAe,KAAKM,CAAK,KACtB,OAAOA,CAAK,KAAK,KACjB,OAAOA,CAAK,KAAK;AAAA,IAAA,IAEb,KAGJL,EAAQ,KAAKG,CAAE;AAAA,EAC1B;AACJ;"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyberskill/shared",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "3.2.1",
|
|
4
5
|
"description": "CyberSkill Shared",
|
|
6
|
+
"author": "Stephen Cheng",
|
|
7
|
+
"license": "MIT",
|
|
5
8
|
"homepage": "https://github.com/cyberskill-world/shared#readme",
|
|
6
|
-
"bugs": {
|
|
7
|
-
"url": "https://github.com/cyberskill-world/shared/issues"
|
|
8
|
-
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "git+https://github.com/cyberskill-world/shared.git"
|
|
12
12
|
},
|
|
13
|
-
"
|
|
14
|
-
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/cyberskill-world/shared/issues"
|
|
15
|
+
},
|
|
15
16
|
"sideEffects": [
|
|
16
17
|
"./dist/style.css"
|
|
17
18
|
],
|
|
18
|
-
"type": "module",
|
|
19
19
|
"exports": {
|
|
20
20
|
"./config": {
|
|
21
21
|
"types": "./dist/config/index.d.ts",
|
|
@@ -164,6 +164,9 @@
|
|
|
164
164
|
"dist",
|
|
165
165
|
"public"
|
|
166
166
|
],
|
|
167
|
+
"engines": {
|
|
168
|
+
"node": ">=24.0.0"
|
|
169
|
+
},
|
|
167
170
|
"scripts": {
|
|
168
171
|
"ai:setup": "tsx src/node/cli/index.ts ai:setup",
|
|
169
172
|
"build": "vite build",
|
|
@@ -177,21 +180,22 @@
|
|
|
177
180
|
"reset": "tsx src/node/cli/index.ts reset",
|
|
178
181
|
"test": "run-s test:unit test:e2e",
|
|
179
182
|
"test:e2e": "tsx src/node/cli/index.ts test:e2e",
|
|
180
|
-
"test:unit": "tsx src/node/cli/index.ts test:unit"
|
|
183
|
+
"test:unit": "tsx src/node/cli/index.ts test:unit",
|
|
184
|
+
"typecheck": "tsc --noEmit"
|
|
181
185
|
},
|
|
182
186
|
"dependencies": {
|
|
183
|
-
"@antfu/eslint-config": "7.
|
|
187
|
+
"@antfu/eslint-config": "7.7.0",
|
|
184
188
|
"@apollo/client": "4.1.6",
|
|
185
189
|
"@apollo/client-integration-nextjs": "0.14.4",
|
|
186
190
|
"@apollo/server": "5.4.0",
|
|
187
191
|
"@as-integrations/express5": "1.1.2",
|
|
188
|
-
"@dotenvx/dotenvx": "1.
|
|
192
|
+
"@dotenvx/dotenvx": "1.53.0",
|
|
189
193
|
"@eddeee888/gcg-typescript-resolver-files": "0.15.0",
|
|
190
194
|
"@eslint-react/eslint-plugin": "2.13.0",
|
|
191
195
|
"@graphql-codegen/cli": "6.1.2",
|
|
192
196
|
"@graphql-codegen/client-preset": "5.2.3",
|
|
193
|
-
"@nestjs/common": "11.1.
|
|
194
|
-
"@nestjs/core": "11.1.
|
|
197
|
+
"@nestjs/common": "11.1.16",
|
|
198
|
+
"@nestjs/core": "11.1.16",
|
|
195
199
|
"@userback/widget": "0.3.12",
|
|
196
200
|
"@vitejs/plugin-react-swc": "4.2.3",
|
|
197
201
|
"body-parser": "2.2.2",
|
|
@@ -212,16 +216,15 @@
|
|
|
212
216
|
"extract-files": "13.0.0",
|
|
213
217
|
"fs-extra": "11.3.4",
|
|
214
218
|
"globals": "17.4.0",
|
|
215
|
-
"graphql": "16.13.
|
|
219
|
+
"graphql": "16.13.1",
|
|
216
220
|
"graphql-upload": "17.0.0",
|
|
217
221
|
"graphql-ws": "6.0.7",
|
|
218
222
|
"helmet": "8.1.0",
|
|
219
|
-
"i18next": "25.8.
|
|
220
|
-
"jsdom": "28.1.0",
|
|
223
|
+
"i18next": "25.8.14",
|
|
221
224
|
"localforage": "1.10.0",
|
|
222
225
|
"migrate-mongo": "14.0.7",
|
|
223
226
|
"mongodb": "7.1.0",
|
|
224
|
-
"mongoose": "9.2.
|
|
227
|
+
"mongoose": "9.2.4",
|
|
225
228
|
"mongoose-aggregate-paginate-v2": "1.1.4",
|
|
226
229
|
"mongoose-paginate-v2": "1.9.1",
|
|
227
230
|
"next-intl": "4.8.3",
|
|
@@ -229,22 +232,22 @@
|
|
|
229
232
|
"react": "19.2.4",
|
|
230
233
|
"react-dom": "19.2.4",
|
|
231
234
|
"react-hot-toast": "2.6.0",
|
|
232
|
-
"react-i18next": "16.5.
|
|
235
|
+
"react-i18next": "16.5.5",
|
|
233
236
|
"rxjs": "7.8.2",
|
|
234
237
|
"vite": "7.3.1",
|
|
235
238
|
"ws": "8.19.0",
|
|
236
239
|
"yargs": "18.0.0"
|
|
237
240
|
},
|
|
238
241
|
"devDependencies": {
|
|
239
|
-
"@commitlint/cli": "20.4.
|
|
240
|
-
"@commitlint/config-conventional": "20.4.
|
|
241
|
-
"@eslint/config-inspector": "1.
|
|
242
|
+
"@commitlint/cli": "20.4.3",
|
|
243
|
+
"@commitlint/config-conventional": "20.4.3",
|
|
244
|
+
"@eslint/config-inspector": "1.5.0",
|
|
242
245
|
"@next/eslint-plugin-next": "16.1.6",
|
|
243
246
|
"@semantic-release/changelog": "6.0.3",
|
|
244
247
|
"@semantic-release/git": "10.0.1",
|
|
245
248
|
"@semantic-release/github": "12.0.6",
|
|
246
|
-
"@storybook/react": "10.2.
|
|
247
|
-
"@storybook/react-vite": "10.2.
|
|
249
|
+
"@storybook/react": "10.2.15",
|
|
250
|
+
"@storybook/react-vite": "10.2.15",
|
|
248
251
|
"@testing-library/jest-dom": "6.9.1",
|
|
249
252
|
"@testing-library/react": "16.3.2",
|
|
250
253
|
"@types/body-parser": "1.19.6",
|
|
@@ -258,18 +261,19 @@
|
|
|
258
261
|
"@types/fs-extra": "11.0.4",
|
|
259
262
|
"@types/graphql-upload": "17.0.0",
|
|
260
263
|
"@types/migrate-mongo": "10.0.6",
|
|
261
|
-
"@types/node": "25.3.
|
|
264
|
+
"@types/node": "25.3.5",
|
|
262
265
|
"@types/react": "19.2.14",
|
|
263
266
|
"@types/react-dom": "19.2.3",
|
|
264
267
|
"@types/ws": "8.18.1",
|
|
265
268
|
"@types/yargs": "17.0.35",
|
|
266
269
|
"@vitest/browser": "4.0.18",
|
|
270
|
+
"@vitest/coverage-istanbul": "4.0.18",
|
|
267
271
|
"eslint": "10.0.2",
|
|
268
272
|
"eslint-config-next": "16.1.6",
|
|
269
273
|
"glob": "13.0.6",
|
|
270
274
|
"jsdom": "28.1.0",
|
|
271
|
-
"lint-staged": "16.3.
|
|
272
|
-
"node-modules-inspector": "1.
|
|
275
|
+
"lint-staged": "16.3.2",
|
|
276
|
+
"node-modules-inspector": "1.4.2",
|
|
273
277
|
"npm-run-all2": "8.0.4",
|
|
274
278
|
"sass": "1.97.3",
|
|
275
279
|
"semantic-release": "25.0.3",
|
|
@@ -280,9 +284,6 @@
|
|
|
280
284
|
"vite-plugin-dts": "4.5.4",
|
|
281
285
|
"vitest": "4.0.18"
|
|
282
286
|
},
|
|
283
|
-
"engines": {
|
|
284
|
-
"node": ">=24.0.0"
|
|
285
|
-
},
|
|
286
287
|
"publishConfig": {
|
|
287
288
|
"access": "public",
|
|
288
289
|
"provenance": true,
|
|
@@ -290,7 +291,8 @@
|
|
|
290
291
|
},
|
|
291
292
|
"pnpm": {
|
|
292
293
|
"overrides": {
|
|
293
|
-
"minimatch": ">=10.2.3"
|
|
294
|
+
"minimatch": ">=10.2.3",
|
|
295
|
+
"minimatch@__comment": "Pinned to fix transitive vulnerability CVE in older minimatch versions used by some deps"
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
298
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|