@cyberskill/shared 1.217.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +330 -222
  2. package/dist/config/config.util.d.ts +17 -0
  3. package/dist/config/env/env.util.d.ts +26 -0
  4. package/dist/config/eslint/index.d.ts +4 -0
  5. package/dist/config/graphql-codegen/graphql-codegen.util.d.ts +23 -0
  6. package/dist/config/vitest/vitest.e2e.cjs +1 -1
  7. package/dist/config/vitest/vitest.e2e.d.ts +16 -0
  8. package/dist/config/vitest/vitest.e2e.js +1 -1
  9. package/dist/config/vitest/vitest.unit.cjs +1 -1
  10. package/dist/config/vitest/vitest.unit.d.ts +18 -0
  11. package/dist/config/vitest/vitest.unit.js +1 -1
  12. package/dist/constant/common.d.ts +4 -0
  13. package/dist/constant/index.d.ts +3 -0
  14. package/dist/node/apollo-server/apollo-server.util.d.ts +14 -0
  15. package/dist/node/command/command.type.d.ts +26 -6
  16. package/dist/node/command/command.util.d.ts +50 -0
  17. package/dist/node/express/express.util.d.ts +47 -0
  18. package/dist/node/fs/fs.type.d.ts +6 -0
  19. package/dist/node/fs/fs.util.d.ts +48 -1
  20. package/dist/node/log/log.type.d.ts +6 -1
  21. package/dist/node/log/log.util.cjs +1 -1
  22. package/dist/node/log/log.util.d.ts +30 -2
  23. package/dist/node/log/log.util.js +33 -20
  24. package/dist/node/mongo/mongo.constant.d.ts +5 -0
  25. package/dist/node/mongo/mongo.type.d.ts +4 -4
  26. package/dist/node/mongo/mongo.util.cjs +5 -5
  27. package/dist/node/mongo/mongo.util.d.ts +337 -3
  28. package/dist/node/mongo/mongo.util.js +406 -79
  29. package/dist/node/package/package.type.d.ts +2 -2
  30. package/dist/node/package/package.util.cjs +1 -1
  31. package/dist/node/package/package.util.d.ts +52 -1
  32. package/dist/node/package/package.util.js +97 -92
  33. package/dist/node/path/path.constant.d.ts +9 -0
  34. package/dist/node/path/path.util.d.ts +24 -0
  35. package/dist/node/storage/storage.util.d.ts +44 -0
  36. package/dist/node/storage/storage.util.js +39 -0
  37. package/dist/node/upload/upload.util.d.ts +21 -0
  38. package/dist/node/ws/ts.util.d.ts +16 -0
  39. package/dist/react/apollo-client/apollo-client.component.d.ts +19 -1
  40. package/dist/react/apollo-client/apollo-client.component.js +1 -4
  41. package/dist/react/apollo-client/apollo-client.constant.d.ts +5 -0
  42. package/dist/react/apollo-client/apollo-client.context.d.ts +15 -0
  43. package/dist/react/apollo-client/apollo-client.hook.d.ts +12 -0
  44. package/dist/react/apollo-client/apollo-client.util.d.ts +48 -0
  45. package/dist/react/apollo-client/apollo-client.util.js +9 -0
  46. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.d.ts +19 -1
  47. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.component.js +1 -4
  48. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.rsc.d.ts +10 -0
  49. package/dist/react/apollo-client-nextjs/apollo-client-nextjs.util.d.ts +10 -0
  50. package/dist/react/apollo-error/apollo-error.component.cjs +1 -1
  51. package/dist/react/apollo-error/apollo-error.component.d.ts +17 -0
  52. package/dist/react/apollo-error/apollo-error.component.js +10 -10
  53. package/dist/react/apollo-error/apollo-error.hook.d.ts +12 -0
  54. package/dist/react/apollo-error/apollo-error.provider.d.ts +15 -0
  55. package/dist/react/apollo-error/apollo-error.util.d.ts +17 -0
  56. package/dist/react/i18next/i18next.hook.d.ts +9 -0
  57. package/dist/react/i18next/i18next.util.d.ts +10 -0
  58. package/dist/react/loading/loading.component.d.ts +21 -0
  59. package/dist/react/loading/loading.hook.d.ts +12 -0
  60. package/dist/react/loading/loading.provider.d.ts +15 -0
  61. package/dist/react/log/log.util.d.ts +17 -0
  62. package/dist/react/next-intl/next-intl.constant.d.ts +9 -0
  63. package/dist/react/next-intl/next-intl.hoc.d.ts +16 -0
  64. package/dist/react/next-intl/next-intl.hook.d.ts +21 -0
  65. package/dist/react/next-intl/next-intl.provider.d.ts +21 -0
  66. package/dist/react/storage/storage.hook.d.ts +19 -0
  67. package/dist/react/storage/storage.hook.js +28 -30
  68. package/dist/react/storage/storage.util.d.ts +39 -0
  69. package/dist/react/storage/storage.util.js +33 -0
  70. package/dist/react/userback/userback.component.d.ts +18 -0
  71. package/dist/typescript/common.type.d.ts +6 -0
  72. package/dist/typescript/index.d.ts +3 -0
  73. package/dist/util/common/common.util.d.ts +19 -7
  74. package/dist/util/common/index.d.ts +3 -0
  75. package/dist/util/index.d.ts +3 -0
  76. package/dist/util/object/object.util.d.ts +25 -12
  77. package/dist/util/serializer/serializer.type.d.ts +1 -1
  78. package/dist/util/serializer/serializer.util.d.ts +8 -0
  79. package/dist/util/serializer/serializer.util.js +4 -4
  80. package/dist/util/string/string.util.cjs +1 -1
  81. package/dist/util/string/string.util.d.ts +30 -17
  82. package/dist/util/string/string.util.js +14 -16
  83. package/dist/util/validate/validate.util.d.ts +9 -3
  84. package/dist/util/validate/validate.util.js +5 -3
  85. package/package.json +7 -5
  86. /package/dist/node_modules/.pnpm/{vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.14_@vitest_browser@3.2.4_jiti@2.4.2_j_5b4f3b6d03b5e1745ce439b75ce4a42f → vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.15_@vitest_browser@3.2.4_jiti@2.4.2_j_e4a333d8aa4b05d17db10875e249d94f}/node_modules/vitest/dist/config.cjs +0 -0
  87. /package/dist/node_modules/.pnpm/{vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.14_@vitest_browser@3.2.4_jiti@2.4.2_j_5b4f3b6d03b5e1745ce439b75ce4a42f → vitest@3.2.4_@types_debug@4.1.12_@types_node@24.0.15_@vitest_browser@3.2.4_jiti@2.4.2_j_e4a333d8aa4b05d17db10875e249d94f}/node_modules/vitest/dist/config.js +0 -0
@@ -2,75 +2,73 @@ import { useState as h, useEffect as y, useCallback as z } from "react";
2
2
  import { storage as i } from "./storage.util.js";
3
3
  import { serializer as E } from "../../util/serializer/serializer.util.js";
4
4
  import { catchError as m } from "../log/log.util.js";
5
- var p = (o, l, t) => new Promise((c, r) => {
6
- var a = (s) => {
5
+ var p = (r, l, t) => new Promise((n, o) => {
6
+ var f = (s) => {
7
7
  try {
8
8
  u(t.next(s));
9
9
  } catch (e) {
10
- r(e);
10
+ o(e);
11
11
  }
12
- }, f = (s) => {
12
+ }, a = (s) => {
13
13
  try {
14
14
  u(t.throw(s));
15
15
  } catch (e) {
16
- r(e);
16
+ o(e);
17
17
  }
18
- }, u = (s) => s.done ? c(s.value) : Promise.resolve(s.value).then(a, f);
19
- u((t = t.apply(o, l)).next());
18
+ }, u = (s) => s.done ? n(s.value) : Promise.resolve(s.value).then(f, a);
19
+ u((t = t.apply(r, l)).next());
20
20
  });
21
- function b(o, l, t = E) {
22
- const [c, r] = h(l), [a, f] = h(!1);
21
+ function b(r, l, t = E) {
22
+ const [n, o] = h(l), [f, a] = h(!1);
23
23
  y(() => {
24
24
  let e = !0;
25
25
  return p(null, null, function* () {
26
26
  try {
27
- const d = yield i.get(o);
27
+ const d = yield i.get(r);
28
28
  if (e)
29
29
  if (d !== null) {
30
30
  const v = t.deserialize(d);
31
- r(v);
31
+ o(v);
32
32
  } else if (l !== void 0) {
33
33
  const v = t.serialize(l);
34
- yield i.set(o, v), r(l);
34
+ yield i.set(r, v), o(l);
35
35
  } else
36
- r(void 0);
36
+ o(void 0);
37
37
  } catch (d) {
38
- m(d), e && r(l);
38
+ m(d), e && o(l);
39
39
  } finally {
40
- e && f(!0);
40
+ e && a(!0);
41
41
  }
42
42
  }), () => {
43
- e = !1, f(!1);
43
+ e = !1, a(!1);
44
44
  };
45
- }, [o, l, t]), y(() => {
46
- if (!a)
45
+ }, [r, l, t]), y(() => {
46
+ if (!f)
47
47
  return;
48
48
  p(null, null, function* () {
49
49
  try {
50
- if (c !== void 0) {
51
- const n = t.serialize(c);
52
- yield i.set(o, n);
50
+ if (n !== void 0) {
51
+ const c = t.serialize(n);
52
+ yield i.set(r, c);
53
53
  }
54
- } catch (n) {
55
- m(n);
54
+ } catch (c) {
55
+ m(c);
56
56
  }
57
57
  });
58
- }, [c, o, t, a]);
58
+ }, [n, r, t, f]);
59
59
  const u = z(
60
60
  (e) => {
61
- r(
62
- (n) => typeof e == "function" ? e(n) : e
63
- );
61
+ o((c) => typeof e == "function" ? e(c) : e);
64
62
  },
65
63
  []
66
64
  ), s = z(() => p(null, null, function* () {
67
65
  try {
68
- yield i.remove(o), r(void 0);
66
+ yield i.remove(r), o(void 0);
69
67
  } catch (e) {
70
68
  m(e);
71
69
  }
72
- }), [o]);
73
- return { value: c, set: u, remove: s };
70
+ }), [r]);
71
+ return { value: n, set: u, remove: s };
74
72
  }
75
73
  export {
76
74
  b as useStorage
@@ -1,6 +1,45 @@
1
+ /**
2
+ * Browser storage utility object using localForage for cross-browser compatibility.
3
+ * This object provides a unified interface for browser storage operations using localForage,
4
+ * which automatically chooses the best available storage method (IndexedDB, WebSQL, or localStorage)
5
+ * based on browser capabilities. It includes comprehensive error handling and type safety.
6
+ */
1
7
  export declare const storage: {
8
+ /**
9
+ * Retrieves a value from browser storage by key.
10
+ * This method fetches data that was previously stored using the set method.
11
+ * Returns null if the key doesn't exist or if an error occurs during retrieval.
12
+ *
13
+ * @param key - The unique identifier for the stored value.
14
+ * @returns A promise that resolves to the stored value or null if not found.
15
+ */
2
16
  get<T = unknown>(key: string): Promise<T | null>;
17
+ /**
18
+ * Stores a value in browser storage with a unique key.
19
+ * This method saves data that can be retrieved later using the get method.
20
+ * The data is automatically handled by localForage which chooses the optimal
21
+ * storage method for the browser environment.
22
+ *
23
+ * @param key - The unique identifier for the value to store.
24
+ * @param value - The data to store (will be automatically handled by localForage).
25
+ * @returns A promise that resolves when the storage operation is complete.
26
+ */
3
27
  set<T = unknown>(key: string, value: T): Promise<void>;
28
+ /**
29
+ * Removes a value from browser storage by key.
30
+ * This method permanently deletes the stored data associated with the specified key.
31
+ * If the key doesn't exist, the operation completes successfully without error.
32
+ *
33
+ * @param key - The unique identifier of the value to remove.
34
+ * @returns A promise that resolves when the removal operation is complete.
35
+ */
4
36
  remove(key: string): Promise<void>;
37
+ /**
38
+ * Retrieves all storage keys.
39
+ * This method returns an array of all keys that currently have stored values.
40
+ * Returns an empty array if no keys exist or if an error occurs during retrieval.
41
+ *
42
+ * @returns A promise that resolves to an array of storage keys.
43
+ */
5
44
  keys(): Promise<string[]>;
6
45
  };
@@ -17,6 +17,14 @@ var o = (r, e, n) => new Promise((s, i) => {
17
17
  c((n = n.apply(r, e)).next());
18
18
  });
19
19
  const f = {
20
+ /**
21
+ * Retrieves a value from browser storage by key.
22
+ * This method fetches data that was previously stored using the set method.
23
+ * Returns null if the key doesn't exist or if an error occurs during retrieval.
24
+ *
25
+ * @param key - The unique identifier for the stored value.
26
+ * @returns A promise that resolves to the stored value or null if not found.
27
+ */
20
28
  get(r) {
21
29
  return o(this, null, function* () {
22
30
  try {
@@ -26,6 +34,16 @@ const f = {
26
34
  }
27
35
  });
28
36
  },
37
+ /**
38
+ * Stores a value in browser storage with a unique key.
39
+ * This method saves data that can be retrieved later using the get method.
40
+ * The data is automatically handled by localForage which chooses the optimal
41
+ * storage method for the browser environment.
42
+ *
43
+ * @param key - The unique identifier for the value to store.
44
+ * @param value - The data to store (will be automatically handled by localForage).
45
+ * @returns A promise that resolves when the storage operation is complete.
46
+ */
29
47
  set(r, e) {
30
48
  return o(this, null, function* () {
31
49
  try {
@@ -35,6 +53,14 @@ const f = {
35
53
  }
36
54
  });
37
55
  },
56
+ /**
57
+ * Removes a value from browser storage by key.
58
+ * This method permanently deletes the stored data associated with the specified key.
59
+ * If the key doesn't exist, the operation completes successfully without error.
60
+ *
61
+ * @param key - The unique identifier of the value to remove.
62
+ * @returns A promise that resolves when the removal operation is complete.
63
+ */
38
64
  remove(r) {
39
65
  return o(this, null, function* () {
40
66
  try {
@@ -44,6 +70,13 @@ const f = {
44
70
  }
45
71
  });
46
72
  },
73
+ /**
74
+ * Retrieves all storage keys.
75
+ * This method returns an array of all keys that currently have stored values.
76
+ * Returns an empty array if no keys exist or if an error occurs during retrieval.
77
+ *
78
+ * @returns A promise that resolves to an array of storage keys.
79
+ */
47
80
  keys() {
48
81
  return o(this, null, function* () {
49
82
  try {
@@ -1,2 +1,20 @@
1
1
  import { I_UserBackProps } from './userback.type.js';
2
+ /**
3
+ * Userback feedback widget component for collecting user feedback.
4
+ * This component integrates the Userback feedback widget into React applications,
5
+ * providing a customizable feedback collection interface for users to submit
6
+ * bug reports, feature requests, and general feedback.
7
+ *
8
+ * Features:
9
+ * - Userback widget integration
10
+ * - Customizable feedback collection
11
+ * - Automatic widget initialization
12
+ * - Token-based configuration
13
+ * - Responsive design support
14
+ *
15
+ * @param props - Component props containing token and options.
16
+ * @param props.token - The Userback token for widget authentication.
17
+ * @param props.options - Optional configuration options for the Userback widget.
18
+ * @returns A React component that renders the Userback feedback widget.
19
+ */
2
20
  export declare function Userback({ token, options }: I_UserBackProps): null;
@@ -1,5 +1,11 @@
1
1
  import { default as consola } from 'consola';
2
+ /**
3
+ * Generic object type with string keys and values of type T (defaults to unknown).
4
+ */
2
5
  export type T_Object<T = unknown> = Record<string, T>;
6
+ /**
7
+ * Logging interface for browser and Node.js environments, compatible with consola.
8
+ */
3
9
  export interface I_Log {
4
10
  silent: typeof consola['silent'];
5
11
  level: typeof consola['level'];
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Re-exports all common TypeScript types for shared usage across the codebase.
3
+ */
1
4
  export * from './common.type.js';
2
5
  export * from './react.type.js';
@@ -1,26 +1,38 @@
1
1
  import { I_EnvFlags, I_NodeEnvInput } from './common.type.js';
2
2
  /**
3
3
  * Convert a string to a regex pattern that matches the string and its accented variations.
4
- * @param str - The string to convert.
5
- * @returns The regex pattern as a string.
4
+ * This function normalizes the input string and creates a regex pattern that can match
5
+ * both the original characters and their accented equivalents.
6
+ *
7
+ * @param str - The string to convert to a regex pattern.
8
+ * @returns The regex pattern as a string that matches the original string and its accented variations.
6
9
  */
7
10
  export declare function regexSearchMapper(str: string): string;
8
11
  /**
9
12
  * Remove accents from a string.
13
+ * This function normalizes the string using NFD normalization and removes all diacritical marks.
14
+ *
10
15
  * @param str - The string to remove accents from.
11
- * @returns The string without accents.
16
+ * @returns The string without any accents or diacritical marks.
12
17
  */
13
18
  export declare function removeAccent(str: string): string;
14
19
  /**
15
20
  * Remove duplicates from an array based on a key function.
21
+ * This function can remove duplicates either by comparing values directly (when no keyFn is provided)
22
+ * or by using a custom key function to determine uniqueness.
23
+ *
16
24
  * @param arr - The array to remove duplicates from.
17
- * @param keyFn - A function that returns a unique key for each item in the array.
18
- * @returns A new array with duplicates removed.
25
+ * @param keyFn - Optional function that returns a unique key for each item in the array.
26
+ * @returns A new array with duplicates removed, maintaining the original order.
19
27
  */
20
28
  export declare function uniqueArray<T>(arr: T[], keyFn?: (item: T) => string | number): T[];
21
29
  /**
30
+ * Map environment variables to boolean flags indicating the current environment.
31
+ * This function takes NODE_ENV and NODE_ENV_MODE variables and returns flags
32
+ * indicating whether the current environment is development, staging, or production.
22
33
  *
23
- * @param env - The environment variables to map.
24
- * @returns An object containing flags for the environment.
34
+ * @param env - The environment variables object containing NODE_ENV and NODE_ENV_MODE.
35
+ * @returns An object containing boolean flags for the environment (IS_DEV, IS_STAG, IS_PROD).
36
+ * @throws {Error} When NODE_ENV is production but NODE_ENV_MODE is development.
25
37
  */
26
38
  export declare function mapEnvironment(env: I_NodeEnvInput): I_EnvFlags;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * Re-exports all common utility types for shared usage across the codebase.
3
+ */
1
4
  export * from './common.type.js';
2
5
  export * from './common.util.js';
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Re-exports all utility modules for shared usage across the codebase.
3
+ */
1
4
  export * from './common/index.js';
2
5
  export * from './object/index.js';
3
6
  export * from './serializer/index.js';
@@ -1,29 +1,42 @@
1
1
  /**
2
2
  * Check if a string is a valid JSON string.
3
- * @param str - The string to check.
3
+ * This function attempts to parse the string as JSON and returns true if successful,
4
+ * false if the string is not valid JSON.
5
+ *
6
+ * @param str - The string to check for valid JSON format.
4
7
  * @returns True if the string is a valid JSON string, false otherwise.
5
8
  */
6
9
  export declare function isJSON(str: string): boolean;
7
10
  /**
8
- * Gets a nested value from an object.
11
+ * Gets a nested value from an object using a path array.
12
+ * This function traverses the object following the provided path and returns
13
+ * the value at the specified location, or undefined if the path doesn't exist.
14
+ *
9
15
  * @param obj - The object to get the value from.
10
- * @param path - The path to the value.
11
- * @returns The value at the specified path, or undefined if it does not exist.
16
+ * @param path - An array of keys representing the path to the desired value.
17
+ * @returns The value at the specified path, or undefined if the path doesn't exist.
12
18
  */
13
19
  export declare function getNestedValue<T>(obj: T, path: (string | number)[]): unknown;
14
20
  /**
15
- * Sets a nested value in an object.
16
- * If the path does not exist, it will be created.
21
+ * Sets a nested value in an object using a path array.
22
+ * This function creates the path if it doesn't exist and sets the value at the specified location.
23
+ * The function returns a new object with the updated value, maintaining immutability.
24
+ *
17
25
  * @param obj - The object to set the value in.
18
- * @param path - The path to the value.
19
- * @param value - The value to set.
20
- * @returns The updated object.
26
+ * @param path - An array of keys representing the path to the desired location.
27
+ * @param value - The value to set at the specified path.
28
+ * @returns A new object with the updated value at the specified path.
21
29
  */
22
30
  export declare function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T;
23
31
  /**
24
32
  * Deep merges multiple objects or arrays into a single object or array.
25
- * If all arguments are arrays, concatenates them.
26
- * If all are objects, deeply merges (concatenating arrays within objects).
27
- * Throws if mixed types.
33
+ * This function handles different types of merging:
34
+ * - If all arguments are arrays, it concatenates them
35
+ * - If all arguments are objects, it deeply merges them (concatenating arrays within objects)
36
+ * - Throws an error if mixed types are provided
37
+ *
38
+ * @param args - The objects or arrays to merge.
39
+ * @returns The merged result - either a concatenated array or a deeply merged object.
40
+ * @throws {Error} When arguments are mixed types (some arrays, some objects).
28
41
  */
29
42
  export declare function deepMerge<T = unknown>(...args: T[]): T;
@@ -1,5 +1,5 @@
1
1
  export type T_SerializerKnownTypes = 'Date' | 'Map' | 'Set' | 'RegExp' | 'BigInt';
2
- export interface T_SerializerValueMap {
2
+ export interface I_SerializerValueMap {
3
3
  Date: Date;
4
4
  Map: Map<unknown, unknown>;
5
5
  Set: Set<unknown>;
@@ -1,2 +1,10 @@
1
1
  import { I_Serializer } from './serializer.type.js';
2
+ /**
3
+ * A serializer that can handle complex JavaScript types that cannot be directly JSON stringified.
4
+ * This serializer extends JSON.stringify and JSON.parse to handle types like Date, Map, Set, RegExp, and BigInt.
5
+ *
6
+ * The serializer works by:
7
+ * 1. During serialization: Wrapping special types with type information before JSON stringification
8
+ * 2. During deserialization: Detecting wrapped types and reconstructing them to their original form
9
+ */
2
10
  export declare const serializer: I_Serializer<unknown>;
@@ -37,8 +37,8 @@ const n = {
37
37
  * it will be serialized using the corresponding handler.
38
38
  * Otherwise, it will be serialized as is.
39
39
  *
40
- * @param value - The value to serialize.
41
- * @returns The serialized JSON string.
40
+ * @param value - The value to serialize to a JSON string.
41
+ * @returns The serialized JSON string that can be safely stored or transmitted.
42
42
  */
43
43
  serialize(e) {
44
44
  return JSON.stringify(e, (r, i) => {
@@ -56,8 +56,8 @@ const n = {
56
56
  * it will be deserialized using the corresponding handler.
57
57
  * Otherwise, it will be deserialized as is.
58
58
  *
59
- * @param json - The JSON string to deserialize.
60
- * @returns The deserialized value.
59
+ * @param json - The JSON string to deserialize back to its original form.
60
+ * @returns The deserialized value with all special types reconstructed.
61
61
  */
62
62
  deserialize(e) {
63
63
  return JSON.parse(e, (r, i) => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("crypto-js"),c=require("lodash-es"),s=require("slugify");var f=Object.defineProperty,u=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,O=(r,e)=>{for(var t in e||(e={}))d.call(e,t)&&i(r,t,e[t]);if(u)for(var t of u(e))g.call(e,t)&&i(r,t,e[t]);return r};const m=s.default||s;function w(r,e){const t=n=>{var o,l;return m(n!=null?n:"",O({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 y(r,e=4){return a.SHA256(r).toString(a.enc.Hex).slice(0,e)}function _(r=8){const e="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?";let t="";for(let n=0;n<r;n++){const o=Math.floor(Math.random()*e.length);t+=e.charAt(o)}return t}function h(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=_;exports.generateShortId=y;exports.generateSlug=w;exports.getFileName=h;exports.substringBetween=p;
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,39 +1,52 @@
1
1
  import { I_SlugifyOptions } from './string.type.js';
2
2
  /**
3
3
  * Generates a slug from a string or an object containing strings.
4
- * The slug is a URL-friendly version of the string.
4
+ * The slug is a URL-friendly version of the string, removing special characters
5
+ * and converting spaces to hyphens. This function can handle both single strings
6
+ * and objects with string values.
7
+ *
5
8
  * @param input - The string or object to be slugified.
6
- * @param options - Options for slugification.
7
- * @returns The slugified string or object.
9
+ * @param options - Options for slugification including replacement character, case sensitivity, locale, etc.
10
+ * @returns The slugified string or object with the same structure as the input.
8
11
  */
9
12
  export declare function generateSlug<T = string>(input: T, options?: I_SlugifyOptions): T;
10
13
  /**
11
14
  * Generates a short ID from a UUID.
12
- * The ID is a substring of the SHA256 hash of the UUID.
13
- * @param uuid - The UUID to be converted.
14
- * @param length - The length of the short ID.
15
- * @returns The short ID.
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.
17
+ *
18
+ * @param uuid - The UUID to be converted to a short ID.
19
+ * @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.
16
21
  */
17
22
  export declare function generateShortId(uuid: string, length?: number): string;
18
23
  /**
19
24
  * Generates a random password of a given length.
20
- * The password contains a mix of letters, numbers, and special characters.
21
- * @param length - The length of the password.
22
- * @returns The generated password.
25
+ * The password contains a mix of letters (both cases), numbers, and special characters
26
+ * to ensure complexity and security.
27
+ *
28
+ * @param length - The desired length of the password (default: 8 characters).
29
+ * @returns A randomly generated password string with the specified length.
23
30
  */
24
31
  export declare function generateRandomPassword(length?: number): string;
25
32
  /**
26
33
  * Get the file name from a URL.
27
- * @param url - The URL to extract the file name from.
28
- * @param getExtension - Whether to include the file extension.
29
- * @returns The file name.
34
+ * This function extracts the file name from a URL, optionally including or excluding
35
+ * the file extension. It handles URLs with query parameters and fragments.
36
+ *
37
+ * @param url - The URL to extract the file name from (default: empty string).
38
+ * @param getExtension - Whether to include the file extension in the result (default: false).
39
+ * @returns The file name extracted from the URL, with or without the extension.
30
40
  */
31
41
  export declare function getFileName(url?: string, getExtension?: boolean): string;
32
42
  /**
33
43
  * Extracts a substring between two strings.
34
- * @param s - The original string.
35
- * @param a - The starting string.
36
- * @param b - The ending string.
37
- * @returns The substring between the two strings.
44
+ * This function finds the first occurrence of the starting string, then finds the first
45
+ * occurrence of the ending string after the starting string, and returns the content between them.
46
+ *
47
+ * @param s - The original string to search within.
48
+ * @param a - The starting string that marks the beginning of the desired substring.
49
+ * @param b - The ending string that marks the end of the desired substring.
50
+ * @returns The substring between the two specified strings, or an empty string if either string is not found.
38
51
  */
39
52
  export declare function substringBetween(s: string, a: string, b: string): string;
@@ -1,6 +1,6 @@
1
1
  import a from "crypto-js";
2
- import { isObject as u } from "lodash-es";
3
- import s from "slugify";
2
+ import { isObject as s } from "lodash-es";
3
+ import u from "slugify";
4
4
  var c = Object.defineProperty, f = Object.getOwnPropertySymbols, d = Object.prototype.hasOwnProperty, m = Object.prototype.propertyIsEnumerable, i = (e, r, t) => r in e ? c(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, g = (e, r) => {
5
5
  for (var t in r || (r = {}))
6
6
  d.call(r, t) && i(e, t, r[t]);
@@ -9,8 +9,8 @@ var c = Object.defineProperty, f = Object.getOwnPropertySymbols, d = Object.prot
9
9
  m.call(r, t) && i(e, t, r[t]);
10
10
  return e;
11
11
  };
12
- const p = s.default || s;
13
- function y(e, r) {
12
+ const p = u.default || u;
13
+ function h(e, r) {
14
14
  const t = (n) => {
15
15
  var o, l;
16
16
  return p(n != null ? n : "", g({
@@ -18,7 +18,7 @@ function y(e, r) {
18
18
  locale: (l = r == null ? void 0 : r.locale) != null ? l : "vi"
19
19
  }, r));
20
20
  };
21
- if (u(e)) {
21
+ if (s(e)) {
22
22
  const n = {};
23
23
  for (const [o, l] of Object.entries(e))
24
24
  n[o] = t(l);
@@ -26,17 +26,15 @@ function y(e, r) {
26
26
  }
27
27
  return t(e);
28
28
  }
29
- function h(e, r = 4) {
29
+ function v(e, r = 4) {
30
30
  return a.SHA256(e).toString(a.enc.Hex).slice(0, r);
31
31
  }
32
- function v(e = 8) {
32
+ function w(e = 8) {
33
33
  const r = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?";
34
- let t = "";
35
- for (let n = 0; n < e; n++) {
36
- const o = Math.floor(Math.random() * r.length);
37
- t += r.charAt(o);
38
- }
39
- return t;
34
+ return Array.from({ length: e }, () => {
35
+ const t = Math.floor(Math.random() * r.length);
36
+ return r.charAt(t);
37
+ }).join("");
40
38
  }
41
39
  function x(e = "", r = !1) {
42
40
  const t = e.split(/[?#]/)[0] || "", n = t.substring(t.lastIndexOf("/") + 1);
@@ -53,9 +51,9 @@ function P(e, r, t) {
53
51
  return l === -1 ? "" : e.slice(o, l);
54
52
  }
55
53
  export {
56
- v as generateRandomPassword,
57
- h as generateShortId,
58
- y as generateSlug,
54
+ w as generateRandomPassword,
55
+ v as generateShortId,
56
+ h as generateSlug,
59
57
  x as getFileName,
60
58
  P as substringBetween
61
59
  };
@@ -1,6 +1,11 @@
1
+ /**
2
+ * A collection of validation utility functions for common data validation tasks.
3
+ * This object provides methods to validate various data types and formats.
4
+ */
1
5
  export declare const validate: {
2
6
  /**
3
7
  * Checks if a value is empty.
8
+ * This function provides comprehensive empty checking for different data types:
4
9
  * - For strings, it checks if the string is empty or contains only whitespace.
5
10
  * - For arrays, it checks if the array has no elements.
6
11
  * - For objects, it checks if the object has no own properties.
@@ -10,18 +15,19 @@ export declare const validate: {
10
15
  * - For Dates, it returns false.
11
16
  * - For null and undefined, it returns true.
12
17
  * - For all other types, it returns false.
13
- * @param value - The value to check.
18
+ *
19
+ * @param value - The value to check for emptiness.
14
20
  * @returns True if the value is empty, false otherwise.
15
21
  */
16
22
  isEmpty(value: unknown): boolean;
17
23
  /**
18
24
  * Checks if a string is a valid IP address (IPv4 or IPv6).
19
- *
25
+ * This function validates IP addresses according to standard formats:
20
26
  * - IPv4: Four octets separated by dots, each between 0–255.
21
27
  * - IPv6: Eight groups of four hex digits, possibly compressed with `::`.
22
28
  *
23
29
  * @param ip - The IP address string to validate.
24
- * @returns True if the IP is valid IPv4 or IPv6.
30
+ * @returns True if the IP is valid IPv4 or IPv6, false otherwise.
25
31
  */
26
32
  isValidIP(ip: string): boolean;
27
33
  };
@@ -1,6 +1,7 @@
1
1
  const i = {
2
2
  /**
3
3
  * Checks if a value is empty.
4
+ * This function provides comprehensive empty checking for different data types:
4
5
  * - For strings, it checks if the string is empty or contains only whitespace.
5
6
  * - For arrays, it checks if the array has no elements.
6
7
  * - For objects, it checks if the object has no own properties.
@@ -10,7 +11,8 @@ const i = {
10
11
  * - For Dates, it returns false.
11
12
  * - For null and undefined, it returns true.
12
13
  * - For all other types, it returns false.
13
- * @param value - The value to check.
14
+ *
15
+ * @param value - The value to check for emptiness.
14
16
  * @returns True if the value is empty, false otherwise.
15
17
  */
16
18
  isEmpty(t) {
@@ -18,12 +20,12 @@ const i = {
18
20
  },
19
21
  /**
20
22
  * Checks if a string is a valid IP address (IPv4 or IPv6).
21
- *
23
+ * This function validates IP addresses according to standard formats:
22
24
  * - IPv4: Four octets separated by dots, each between 0–255.
23
25
  * - IPv6: Eight groups of four hex digits, possibly compressed with `::`.
24
26
  *
25
27
  * @param ip - The IP address string to validate.
26
- * @returns True if the IP is valid IPv4 or IPv6.
28
+ * @returns True if the IP is valid IPv4 or IPv6, false otherwise.
27
29
  */
28
30
  isValidIP(t) {
29
31
  const e = t.split(".");