@cyberskill/shared 2.20.0 → 2.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/storybook/storybook.main.cjs +1 -1
- package/dist/config/storybook/storybook.main.js +1 -1
- package/dist/config/vitest/vitest.e2e.cjs +1 -1
- package/dist/config/vitest/vitest.e2e.js +6 -6
- package/dist/config/vitest/vitest.unit.cjs +1 -1
- package/dist/config/vitest/vitest.unit.js +5 -5
- package/dist/node/mongo/mongo-controller.test.unit.d.ts +1 -0
- package/dist/node/mongo/mongo.test.unit.d.ts +1 -0
- package/dist/node/mongo/mongo.util.cjs +2 -2
- package/dist/node/mongo/mongo.util.d.ts +9 -203
- package/dist/node/mongo/mongo.util.js +70 -68
- package/dist/node/path/path.constant.cjs +1 -1
- package/dist/node/path/path.constant.js +113 -109
- package/dist/node/path/path.test.unit.d.ts +1 -0
- package/dist/node/path/path.util.d.ts +2 -2
- package/dist/react/loading/loading.component.cjs +2 -2
- package/dist/react/loading/loading.component.js +32 -19
- package/dist/react/loading/loading.test.unit.d.ts +1 -0
- package/dist/react/loading/loading.type.d.ts +2 -1
- package/dist/util/common/common.test.unit.d.ts +1 -0
- package/dist/util/common/common.util.cjs +1 -1
- package/dist/util/common/common.util.js +14 -15
- package/dist/util/index.cjs +1 -1
- package/dist/util/index.js +16 -15
- package/dist/util/object/index.cjs +1 -1
- package/dist/util/object/index.js +4 -3
- package/dist/util/object/object.test.unit.d.ts +1 -0
- package/dist/util/object/object.util.cjs +1 -1
- package/dist/util/object/object.util.d.ts +10 -30
- package/dist/util/object/object.util.js +102 -69
- package/dist/util/serializer/serializer.test.unit.d.ts +1 -0
- package/dist/util/serializer/serializer.util.cjs +1 -1
- package/dist/util/serializer/serializer.util.js +19 -16
- package/dist/util/string/string.test.unit.d.ts +1 -0
- package/dist/util/string/string.util.cjs +1 -1
- package/dist/util/string/string.util.d.ts +4 -3
- package/dist/util/string/string.util.js +32 -41
- package/dist/util/validate/validate.test.unit.d.ts +1 -0
- package/dist/util/validate/validate.util.cjs +1 -1
- package/dist/util/validate/validate.util.js +9 -9
- package/package.json +37 -45
- /package/dist/node_modules/.pnpm/{vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.3.0_sass@1.97.0_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.cjs +0 -0
- /package/dist/node_modules/.pnpm/{vitest@4.0.13_@types_debug@4.1.12_@types_node@24.10.1_jiti@2.6.1_jsdom@27.2.0_sass@1.94.2_tsx@4.20.6_yaml@2.8.1 → vitest@4.0.16_@types_node@25.0.3_jiti@2.6.1_jsdom@27.3.0_sass@1.97.0_tsx@4.21.0_yaml@2.8.2}/node_modules/vitest/dist/config.js +0 -0
package/dist/util/index.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { mapEnvironment as t, regexSearchMapper as o, removeAccent as a, uniqueArray as n } from "./common/common.util.js";
|
|
2
|
-
import {
|
|
3
|
-
import { serializer as
|
|
4
|
-
import { generateRandomPassword as
|
|
5
|
-
import { validate as
|
|
2
|
+
import { deepClone as g, deepMerge as i, getNestedValue as p, isJSON as l, normalizeMongoFilter as s, setNestedValue as d } from "./object/object.util.js";
|
|
3
|
+
import { serializer as x } from "./serializer/serializer.util.js";
|
|
4
|
+
import { generateRandomPassword as N, generateShortId as S, generateSlug as c, getFileName as v, substringBetween as M } from "./string/string.util.js";
|
|
5
|
+
import { validate as w } from "./validate/validate.util.js";
|
|
6
6
|
export {
|
|
7
|
-
g as
|
|
8
|
-
|
|
9
|
-
N as
|
|
10
|
-
S as
|
|
11
|
-
c as
|
|
12
|
-
|
|
13
|
-
p as
|
|
7
|
+
g as deepClone,
|
|
8
|
+
i as deepMerge,
|
|
9
|
+
N as generateRandomPassword,
|
|
10
|
+
S as generateShortId,
|
|
11
|
+
c as generateSlug,
|
|
12
|
+
v as getFileName,
|
|
13
|
+
p as getNestedValue,
|
|
14
|
+
l as isJSON,
|
|
14
15
|
t as mapEnvironment,
|
|
15
16
|
s as normalizeMongoFilter,
|
|
16
17
|
o as regexSearchMapper,
|
|
17
18
|
a as removeAccent,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
x as serializer,
|
|
20
|
+
d as setNestedValue,
|
|
21
|
+
M as substringBetween,
|
|
21
22
|
n as uniqueArray,
|
|
22
|
-
|
|
23
|
+
w as validate
|
|
23
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./object.util.cjs");exports.deepClone=e.deepClone;exports.deepMerge=e.deepMerge;exports.getNestedValue=e.getNestedValue;exports.isJSON=e.isJSON;exports.normalizeMongoFilter=e.normalizeMongoFilter;exports.setNestedValue=e.setNestedValue;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { deepMerge as
|
|
1
|
+
import { deepClone as t, deepMerge as l, getNestedValue as r, isJSON as d, normalizeMongoFilter as s, setNestedValue as a } from "./object.util.js";
|
|
2
2
|
export {
|
|
3
|
-
|
|
3
|
+
t as deepClone,
|
|
4
|
+
l as deepMerge,
|
|
4
5
|
r as getNestedValue,
|
|
5
|
-
|
|
6
|
+
d as isJSON,
|
|
6
7
|
s as normalizeMongoFilter,
|
|
7
8
|
a as setNestedValue
|
|
8
9
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var A=Object.defineProperty,v=Object.defineProperties,h=Object.getOwnPropertyDescriptors,f=Object.getOwnPropertySymbols,w=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,y=(e,r,n)=>r in e?A(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n,p=(e,r)=>{for(var n in r||(r={}))w.call(r,n)&&y(e,n,r[n]);if(f)for(var n of f(r))_.call(r,n)&&y(e,n,r[n]);return e},d=(e,r)=>v(e,h(r));function P(e){try{return JSON.parse(e),!0}catch(r){return!1}}function b(e,r){let n=e;const o=r.length;for(let t=0;t<o;t++)if(n&&typeof n=="object"&&r[t]in n)n=n[r[t]];else return;return n}function O(e,r,n){if(r.length===0)return e;const[o,...t]=r;if(t.length===0)return d(p({},e),{[o]:n});const i=e[o];return d(p({},e),{[o]:O(typeof i=="object"&&i!==null?i:{},t,n)})}function u(e){if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(o=>u(o));if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);const r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)return e;const n={};for(const o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=u(e[o]));return n}function g(...e){if(e.length===0)return{};const r=e.filter(t=>t!=null);if(r.length===0)return{};if(r.length===1)return r[0];if(r.every(Array.isArray))return[].concat(...r);if(r.every(t=>typeof t=="object"&&t!==null&&!Array.isArray(t))){const t={};for(const i of r){const c=i;for(const s in c)if(Object.prototype.hasOwnProperty.call(c,s)){const a=c[s];if(Object.prototype.hasOwnProperty.call(t,s)){const l=t[s];typeof a=="object"&&a!==null&&typeof l=="object"&&l!==null?Array.isArray(a)&&Array.isArray(l)?t[s]=l.concat(a):!Array.isArray(a)&&!Array.isArray(l)?t[s]=g(l,a):t[s]=a:t[s]=a}else t[s]=a}}return t}if(r.every(t=>typeof t!="object"||t===null))throw new Error("deepMerge: Cannot merge primitive values. All arguments must be objects or arrays.");const n=r.some(Array.isArray),o=r.some(t=>typeof t=="object"&&t!==null&&!Array.isArray(t));throw n&&o?new Error("deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."):new Error("deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type.")}function m(e){if(!e||typeof e!="object")return e;const r={};for(const[n,o]of Object.entries(e))if(o&&typeof o=="object"&&!Array.isArray(o))if(Object.keys(o).some(i=>i.startsWith("$")))r[n]=o;else{const i=m(o);for(const[c,s]of Object.entries(i)){const a=`${n}.${c}`;r[a]=s}}else r[n]=o;return r}exports.deepClone=u;exports.deepMerge=g;exports.getNestedValue=b;exports.isJSON=P;exports.normalizeMongoFilter=m;exports.setNestedValue=O;
|
|
@@ -29,48 +29,28 @@ export declare function getNestedValue<T>(obj: T, path: (string | number)[]): un
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function setNestedValue<T>(obj: T, path: (string | number)[], value: unknown): T;
|
|
31
31
|
/**
|
|
32
|
-
* Deep
|
|
33
|
-
* This function
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* - Provides better type inference and safety
|
|
38
|
-
* - Throws descriptive errors for invalid input
|
|
32
|
+
* Deep clones an object or array.
|
|
33
|
+
* This function creates a deep copy of the input, recursively cloning objects and arrays.
|
|
34
|
+
* Primitive values, dates, and other non-plain objects are returned as is (or cloned if supported).
|
|
35
|
+
* Note: This implementation focuses on plain objects and arrays. For complex types like Map/Set/Buffer/ObjectId,
|
|
36
|
+
* it returns the reference or handles them according to specific logic.
|
|
39
37
|
*
|
|
40
|
-
* @param
|
|
41
|
-
* @returns
|
|
42
|
-
* @throws {Error} When arguments are mixed types (some arrays, some objects) or when all arguments are primitive values.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```typescript
|
|
46
|
-
* // Merge objects
|
|
47
|
-
* deepMerge({ a: 1 }, { b: 2 }, { a: 3 }) // { a: 3, b: 2 }
|
|
48
|
-
*
|
|
49
|
-
* // Merge arrays
|
|
50
|
-
* deepMerge([1, 2], [3, 4]) // [1, 2, 3, 4]
|
|
51
|
-
*
|
|
52
|
-
* // Handle null/undefined
|
|
53
|
-
* deepMerge({ a: 1 }, null, undefined, { b: 2 }) // { a: 1, b: 2 }
|
|
54
|
-
*
|
|
55
|
-
* // Nested objects with arrays
|
|
56
|
-
* deepMerge(
|
|
57
|
-
* { items: [1, 2], config: { theme: 'dark' } },
|
|
58
|
-
* { items: [3, 4], config: { size: 'large' } }
|
|
59
|
-
* ) // { items: [1, 2, 3, 4], config: { theme: 'dark', size: 'large' } }
|
|
60
|
-
* ```
|
|
38
|
+
* @param obj - The object to clone.
|
|
39
|
+
* @returns A deep copy of the object.
|
|
61
40
|
*/
|
|
41
|
+
export declare function deepClone<T>(obj: T): T;
|
|
62
42
|
/**
|
|
63
43
|
* Deep merges multiple objects into a single object.
|
|
64
44
|
* @param args - The objects to merge. Can be empty, in which case returns an empty object.
|
|
65
45
|
* @returns The merged object.
|
|
66
46
|
*/
|
|
67
|
-
export declare function deepMerge<T
|
|
47
|
+
export declare function deepMerge<T = Record<string, unknown>>(...args: (object | null | undefined)[]): T;
|
|
68
48
|
/**
|
|
69
49
|
* Deep merges multiple arrays into a single array.
|
|
70
50
|
* @param args - The arrays to merge. Can be empty, in which case returns an empty array.
|
|
71
51
|
* @returns The merged array.
|
|
72
52
|
*/
|
|
73
|
-
export declare function deepMerge<T
|
|
53
|
+
export declare function deepMerge<T = unknown[]>(...args: (unknown[] | null | undefined)[]): T;
|
|
74
54
|
/**
|
|
75
55
|
* Normalizes MongoDB filters to support both dot notation strings and nested objects.
|
|
76
56
|
* This function converts nested object filters to dot notation format while preserving
|
|
@@ -1,97 +1,130 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function w(r) {
|
|
1
|
+
var d = Object.defineProperty, g = Object.defineProperties, m = Object.getOwnPropertyDescriptors, f = Object.getOwnPropertySymbols, A = Object.prototype.hasOwnProperty, v = Object.prototype.propertyIsEnumerable, u = (e, r, n) => r in e ? d(e, r, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[r] = n, y = (e, r) => {
|
|
2
|
+
for (var n in r || (r = {}))
|
|
3
|
+
A.call(r, n) && u(e, n, r[n]);
|
|
4
|
+
if (f)
|
|
5
|
+
for (var n of f(r))
|
|
6
|
+
v.call(r, n) && u(e, n, r[n]);
|
|
7
|
+
return e;
|
|
8
|
+
}, p = (e, r) => g(e, m(r));
|
|
9
|
+
function P(e) {
|
|
11
10
|
try {
|
|
12
|
-
return JSON.parse(
|
|
13
|
-
} catch (
|
|
11
|
+
return JSON.parse(e), !0;
|
|
12
|
+
} catch (r) {
|
|
14
13
|
return !1;
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
function b(e, r) {
|
|
17
|
+
let n = e;
|
|
18
|
+
const o = r.length;
|
|
19
|
+
for (let t = 0; t < o; t++)
|
|
20
|
+
if (n && typeof n == "object" && r[t] in n)
|
|
21
|
+
n = n[r[t]];
|
|
22
|
+
else
|
|
23
|
+
return;
|
|
24
|
+
return n;
|
|
22
25
|
}
|
|
23
|
-
function
|
|
24
|
-
if (
|
|
25
|
-
return
|
|
26
|
-
const [
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
29
|
-
[
|
|
26
|
+
function h(e, r, n) {
|
|
27
|
+
if (r.length === 0)
|
|
28
|
+
return e;
|
|
29
|
+
const [o, ...t] = r;
|
|
30
|
+
if (t.length === 0)
|
|
31
|
+
return p(y({}, e), {
|
|
32
|
+
[o]: n
|
|
30
33
|
});
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
[
|
|
34
|
-
typeof
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const i = e[o];
|
|
35
|
+
return p(y({}, e), {
|
|
36
|
+
[o]: h(
|
|
37
|
+
typeof i == "object" && i !== null ? i : {},
|
|
38
|
+
t,
|
|
39
|
+
n
|
|
37
40
|
)
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
|
-
function
|
|
41
|
-
if (
|
|
42
|
-
return
|
|
43
|
-
|
|
43
|
+
function O(e) {
|
|
44
|
+
if (e === null || typeof e != "object")
|
|
45
|
+
return e;
|
|
46
|
+
if (Array.isArray(e))
|
|
47
|
+
return e.map((o) => O(o));
|
|
48
|
+
if (e instanceof Date)
|
|
49
|
+
return new Date(e.getTime());
|
|
50
|
+
if (e instanceof RegExp)
|
|
51
|
+
return new RegExp(e.source, e.flags);
|
|
52
|
+
const r = Object.getPrototypeOf(e);
|
|
53
|
+
if (r !== Object.prototype && r !== null)
|
|
54
|
+
return e;
|
|
55
|
+
const n = {};
|
|
56
|
+
for (const o in e)
|
|
57
|
+
Object.prototype.hasOwnProperty.call(e, o) && (n[o] = O(e[o]));
|
|
58
|
+
return n;
|
|
59
|
+
}
|
|
60
|
+
function w(...e) {
|
|
44
61
|
if (e.length === 0)
|
|
45
62
|
return {};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
const r = e.filter((t) => t != null);
|
|
64
|
+
if (r.length === 0)
|
|
65
|
+
return {};
|
|
66
|
+
if (r.length === 1)
|
|
67
|
+
return r[0];
|
|
68
|
+
if (r.every(Array.isArray))
|
|
69
|
+
return [].concat(...r);
|
|
70
|
+
if (r.every((t) => typeof t == "object" && t !== null && !Array.isArray(t))) {
|
|
71
|
+
const t = {};
|
|
72
|
+
for (const i of r) {
|
|
73
|
+
const l = i;
|
|
74
|
+
for (const s in l)
|
|
75
|
+
if (Object.prototype.hasOwnProperty.call(l, s)) {
|
|
76
|
+
const a = l[s];
|
|
77
|
+
if (Object.prototype.hasOwnProperty.call(t, s)) {
|
|
78
|
+
const c = t[s];
|
|
79
|
+
typeof a == "object" && a !== null && typeof c == "object" && c !== null ? Array.isArray(a) && Array.isArray(c) ? t[s] = c.concat(a) : !Array.isArray(a) && !Array.isArray(c) ? t[s] = w(
|
|
80
|
+
c,
|
|
81
|
+
a
|
|
82
|
+
) : t[s] = a : t[s] = a;
|
|
83
|
+
} else
|
|
84
|
+
t[s] = a;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return t;
|
|
88
|
+
}
|
|
89
|
+
if (r.every((t) => typeof t != "object" || t === null))
|
|
58
90
|
throw new Error(
|
|
59
91
|
"deepMerge: Cannot merge primitive values. All arguments must be objects or arrays."
|
|
60
92
|
);
|
|
61
|
-
const
|
|
62
|
-
(
|
|
93
|
+
const n = r.some(Array.isArray), o = r.some(
|
|
94
|
+
(t) => typeof t == "object" && t !== null && !Array.isArray(t)
|
|
63
95
|
);
|
|
64
|
-
throw
|
|
96
|
+
throw n && o ? new Error(
|
|
65
97
|
"deepMerge: Cannot mix arrays and objects. All arguments must be either arrays or objects."
|
|
66
98
|
) : new Error(
|
|
67
99
|
"deepMerge: Invalid arguments provided. All arguments must be objects or arrays of the same type."
|
|
68
100
|
);
|
|
69
101
|
}
|
|
70
|
-
function
|
|
71
|
-
if (!
|
|
72
|
-
return
|
|
73
|
-
const
|
|
74
|
-
for (const [
|
|
75
|
-
if (
|
|
76
|
-
if (Object.keys(
|
|
77
|
-
(
|
|
102
|
+
function _(e) {
|
|
103
|
+
if (!e || typeof e != "object")
|
|
104
|
+
return e;
|
|
105
|
+
const r = {};
|
|
106
|
+
for (const [n, o] of Object.entries(e))
|
|
107
|
+
if (o && typeof o == "object" && !Array.isArray(o))
|
|
108
|
+
if (Object.keys(o).some(
|
|
109
|
+
(i) => i.startsWith("$")
|
|
78
110
|
))
|
|
79
|
-
|
|
111
|
+
r[n] = o;
|
|
80
112
|
else {
|
|
81
|
-
const
|
|
82
|
-
for (const [l,
|
|
83
|
-
const
|
|
84
|
-
|
|
113
|
+
const i = _(o);
|
|
114
|
+
for (const [l, s] of Object.entries(i)) {
|
|
115
|
+
const a = `${n}.${l}`;
|
|
116
|
+
r[a] = s;
|
|
85
117
|
}
|
|
86
118
|
}
|
|
87
119
|
else
|
|
88
|
-
|
|
89
|
-
return
|
|
120
|
+
r[n] = o;
|
|
121
|
+
return r;
|
|
90
122
|
}
|
|
91
123
|
export {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
_ as
|
|
124
|
+
O as deepClone,
|
|
125
|
+
w as deepMerge,
|
|
126
|
+
b as getNestedValue,
|
|
127
|
+
P as isJSON,
|
|
128
|
+
_ as normalizeMongoFilter,
|
|
129
|
+
h as setNestedValue
|
|
97
130
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s={Date:{is:e=>e instanceof Date,serialize:e=>({__type:"Date",value:e.toISOString()}),deserialize:e=>new Date(e)},Map:{is:e=>e instanceof Map,serialize:e=>({__type:"Map",value:Array.from(e.entries())}),deserialize:e=>new Map(e)},Set:{is:e=>e instanceof Set,serialize:e=>({__type:"Set",value:Array.from(e)}),deserialize:e=>new Set(e)},RegExp:{is:e=>e instanceof RegExp,serialize:e=>({__type:"RegExp",value:{source:e.source,flags:e.flags}}),deserialize:e=>{const{source:r,flags:t}=e;return new RegExp(r,t)}},BigInt:{is:e=>typeof e=="bigint",serialize:e=>({__type:"BigInt",value:e.toString()}),deserialize:e=>BigInt(e)}},l={serialize(e){return JSON.stringify(e,function(r,t){const i=this[r];if(i instanceof Date)return s.Date.serialize(i);for(const o of Object.keys(s)){const a=s[o];if(a.is(t))return a.serialize(t)}return t})},deserialize(e){return JSON.parse(e,(r,t)=>{if(t&&typeof t=="object"&&"__type"in t&&typeof t.__type=="string"){const n=t.__type,i=s[n];if(i)return i.deserialize(t.value)}return t})}};exports.serializer=l;
|
|
@@ -21,8 +21,8 @@ const n = {
|
|
|
21
21
|
value: { source: e.source, flags: e.flags }
|
|
22
22
|
}),
|
|
23
23
|
deserialize: (e) => {
|
|
24
|
-
const { source: r, flags:
|
|
25
|
-
return new RegExp(r,
|
|
24
|
+
const { source: r, flags: t } = e;
|
|
25
|
+
return new RegExp(r, t);
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
BigInt: {
|
|
@@ -30,7 +30,7 @@ const n = {
|
|
|
30
30
|
serialize: (e) => ({ __type: "BigInt", value: e.toString() }),
|
|
31
31
|
deserialize: (e) => BigInt(e)
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, p = {
|
|
34
34
|
/**
|
|
35
35
|
* Serializes a value to a JSON string.
|
|
36
36
|
* If the value is of a known type (Date, Map, Set, RegExp, BigInt),
|
|
@@ -41,13 +41,16 @@ const n = {
|
|
|
41
41
|
* @returns The serialized JSON string that can be safely stored or transmitted.
|
|
42
42
|
*/
|
|
43
43
|
serialize(e) {
|
|
44
|
-
return JSON.stringify(e, (r,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
return JSON.stringify(e, function(r, t) {
|
|
45
|
+
const i = this[r];
|
|
46
|
+
if (i instanceof Date)
|
|
47
|
+
return n.Date.serialize(i);
|
|
48
|
+
for (const o of Object.keys(n)) {
|
|
49
|
+
const a = n[o];
|
|
50
|
+
if (a.is(t))
|
|
51
|
+
return a.serialize(t);
|
|
49
52
|
}
|
|
50
|
-
return
|
|
53
|
+
return t;
|
|
51
54
|
});
|
|
52
55
|
},
|
|
53
56
|
/**
|
|
@@ -60,16 +63,16 @@ const n = {
|
|
|
60
63
|
* @returns The deserialized value with all special types reconstructed.
|
|
61
64
|
*/
|
|
62
65
|
deserialize(e) {
|
|
63
|
-
return JSON.parse(e, (r,
|
|
64
|
-
if (
|
|
65
|
-
const s =
|
|
66
|
-
if (
|
|
67
|
-
return
|
|
66
|
+
return JSON.parse(e, (r, t) => {
|
|
67
|
+
if (t && typeof t == "object" && "__type" in t && typeof t.__type == "string") {
|
|
68
|
+
const s = t.__type, i = n[s];
|
|
69
|
+
if (i)
|
|
70
|
+
return i.deserialize(t.value);
|
|
68
71
|
}
|
|
69
|
-
return
|
|
72
|
+
return t;
|
|
70
73
|
});
|
|
71
74
|
}
|
|
72
75
|
};
|
|
73
76
|
export {
|
|
74
|
-
|
|
77
|
+
p as serializer
|
|
75
78
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../common/common.util.cjs");function a(t,r){let e=t.trim();return e=l.removeAccent(e),(r==null?void 0:r.lower)!==!1&&(e=e.toLowerCase()),e=e.replace(/[^a-z0-9\s-]/gi," "),e=e.replace(/[\s-]+/g,"-"),e=e.replace(/^-+|-+$/g,""),e}function c(t,r){const e=n=>a(n!=null?n:"",r);if(typeof t=="object"&&t!==null){const n={};for(const[o,s]of Object.entries(t))n[o]=e(s);return n}return e(t)}function i(t,r=4){let e=2166136261;for(let o=0;o<t.length;o++)e^=t.charCodeAt(o),e=Math.imul(e,16777619);const n=(e>>>0).toString(16).padStart(8,"0");return r>8?t.replace(/-/g,"").slice(0,r):n.slice(0,r)}function u(t=8){const r="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?";return Array.from({length:t},()=>{const e=Math.floor(Math.random()*r.length);return r.charAt(e)}).join("")}function f(t="",r=!1){const e=t.split(/[?#]/)[0]||"",n=e.substring(e.lastIndexOf("/")+1);if(r)return n;const o=n.lastIndexOf(".");return o>0?n.slice(0,o):n}function g(t,r,e){const n=t.indexOf(r);if(n===-1)return"";const o=n+r.length,s=t.indexOf(e,o);return s===-1?"":t.slice(o,s)}exports.generateRandomPassword=u;exports.generateShortId=i;exports.generateSlug=c;exports.getFileName=f;exports.substringBetween=g;
|
|
@@ -12,12 +12,13 @@ import { I_SlugifyOptions } from './string.type.js';
|
|
|
12
12
|
export declare function generateSlug<T = string>(input: T, options?: I_SlugifyOptions): T;
|
|
13
13
|
/**
|
|
14
14
|
* Generates a short ID from a UUID.
|
|
15
|
-
* The ID is a substring of the
|
|
16
|
-
*
|
|
15
|
+
* The ID is a substring of the UUID, providing a shorter identifier.
|
|
16
|
+
* Note: This is NOT cryptographically secure and collisions are possible,
|
|
17
|
+
* but suitable for display purposes where uniqueness is handled elsewhere.
|
|
17
18
|
*
|
|
18
19
|
* @param uuid - The UUID to be converted to a short ID.
|
|
19
20
|
* @param length - The desired length of the short ID (default: 4 characters).
|
|
20
|
-
* @returns A short ID string of the specified length derived from the UUID
|
|
21
|
+
* @returns A short ID string of the specified length derived from the UUID.
|
|
21
22
|
*/
|
|
22
23
|
export declare function generateShortId(uuid: string, length?: number): string;
|
|
23
24
|
/**
|
|
@@ -1,59 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
m.call(r, t) && i(e, t, r[t]);
|
|
10
|
-
return e;
|
|
11
|
-
};
|
|
12
|
-
const p = u.default || u;
|
|
13
|
-
function h(e, r) {
|
|
14
|
-
const t = (n) => {
|
|
15
|
-
var o, l;
|
|
16
|
-
return p(n != null ? n : "", g({
|
|
17
|
-
lower: (o = r == null ? void 0 : r.lower) != null ? o : !0,
|
|
18
|
-
locale: (l = r == null ? void 0 : r.locale) != null ? l : "vi"
|
|
19
|
-
}, r));
|
|
20
|
-
};
|
|
21
|
-
if (s(e)) {
|
|
1
|
+
import { removeAccent as c } from "../common/common.util.js";
|
|
2
|
+
function l(t, r) {
|
|
3
|
+
let e = t.trim();
|
|
4
|
+
return e = c(e), (r == null ? void 0 : r.lower) !== !1 && (e = e.toLowerCase()), e = e.replace(/[^a-z0-9\s-]/gi, " "), e = e.replace(/[\s-]+/g, "-"), e = e.replace(/^-+|-+$/g, ""), e;
|
|
5
|
+
}
|
|
6
|
+
function a(t, r) {
|
|
7
|
+
const e = (n) => l(n != null ? n : "", r);
|
|
8
|
+
if (typeof t == "object" && t !== null) {
|
|
22
9
|
const n = {};
|
|
23
|
-
for (const [o,
|
|
24
|
-
n[o] =
|
|
10
|
+
for (const [o, s] of Object.entries(t))
|
|
11
|
+
n[o] = e(s);
|
|
25
12
|
return n;
|
|
26
13
|
}
|
|
27
|
-
return t
|
|
14
|
+
return e(t);
|
|
28
15
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
16
|
+
function f(t, r = 4) {
|
|
17
|
+
let e = 2166136261;
|
|
18
|
+
for (let o = 0; o < t.length; o++)
|
|
19
|
+
e ^= t.charCodeAt(o), e = Math.imul(e, 16777619);
|
|
20
|
+
const n = (e >>> 0).toString(16).padStart(8, "0");
|
|
21
|
+
return r > 8 ? t.replace(/-/g, "").slice(0, r) : n.slice(0, r);
|
|
31
22
|
}
|
|
32
|
-
function
|
|
23
|
+
function u(t = 8) {
|
|
33
24
|
const r = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?";
|
|
34
|
-
return Array.from({ length:
|
|
35
|
-
const
|
|
36
|
-
return r.charAt(
|
|
25
|
+
return Array.from({ length: t }, () => {
|
|
26
|
+
const e = Math.floor(Math.random() * r.length);
|
|
27
|
+
return r.charAt(e);
|
|
37
28
|
}).join("");
|
|
38
29
|
}
|
|
39
|
-
function
|
|
40
|
-
const
|
|
30
|
+
function g(t = "", r = !1) {
|
|
31
|
+
const e = t.split(/[?#]/)[0] || "", n = e.substring(e.lastIndexOf("/") + 1);
|
|
41
32
|
if (r)
|
|
42
33
|
return n;
|
|
43
34
|
const o = n.lastIndexOf(".");
|
|
44
35
|
return o > 0 ? n.slice(0, o) : n;
|
|
45
36
|
}
|
|
46
|
-
function
|
|
47
|
-
const n =
|
|
37
|
+
function d(t, r, e) {
|
|
38
|
+
const n = t.indexOf(r);
|
|
48
39
|
if (n === -1)
|
|
49
40
|
return "";
|
|
50
|
-
const o = n + r.length,
|
|
51
|
-
return
|
|
41
|
+
const o = n + r.length, s = t.indexOf(e, o);
|
|
42
|
+
return s === -1 ? "" : t.slice(o, s);
|
|
52
43
|
}
|
|
53
44
|
export {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
u as generateRandomPassword,
|
|
46
|
+
f as generateShortId,
|
|
47
|
+
a as generateSlug,
|
|
48
|
+
g as getFileName,
|
|
49
|
+
d as substringBetween
|
|
59
50
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r={isEmpty(d){return d==null?!0:typeof d=="string"?d.trim().length===0:Array.isArray(d)?d.length===0:typeof d=="object"?d instanceof Date?!1:d instanceof Map||d instanceof Set?d.size===0:d instanceof WeakMap||d instanceof WeakSet?!0:ArrayBuffer.isView(d)?d.byteLength===0:Object.keys(d).length===0:!1},isValidIP(d){const e=d.split(".");return e.length===4&&e.every(t=>/^\d+$/.test(t)&&Number(t)>=0&&Number(t)<=255)?!0:/^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[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1
|
+
const e = {
|
|
2
2
|
/**
|
|
3
3
|
* Checks if a value is empty.
|
|
4
4
|
* This function provides comprehensive empty checking for different data types:
|
|
@@ -15,8 +15,8 @@ const i = {
|
|
|
15
15
|
* @param value - The value to check for emptiness.
|
|
16
16
|
* @returns True if the value is empty, false otherwise.
|
|
17
17
|
*/
|
|
18
|
-
isEmpty(
|
|
19
|
-
return
|
|
18
|
+
isEmpty(d) {
|
|
19
|
+
return d == null ? !0 : typeof d == "string" ? d.trim().length === 0 : Array.isArray(d) ? d.length === 0 : typeof d == "object" ? d instanceof Date ? !1 : d instanceof Map || d instanceof Set ? d.size === 0 : d instanceof WeakMap || d instanceof WeakSet ? !0 : ArrayBuffer.isView(d) ? d.byteLength === 0 : Object.keys(d).length === 0 : !1;
|
|
20
20
|
},
|
|
21
21
|
/**
|
|
22
22
|
* Checks if a string is a valid IP address (IPv4 or IPv6).
|
|
@@ -27,13 +27,13 @@ const i = {
|
|
|
27
27
|
* @param ip - The IP address string to validate.
|
|
28
28
|
* @returns True if the IP is valid IPv4 or IPv6, false otherwise.
|
|
29
29
|
*/
|
|
30
|
-
isValidIP(
|
|
31
|
-
const
|
|
32
|
-
return
|
|
33
|
-
(
|
|
34
|
-
) ? !0 : /^(([a-
|
|
30
|
+
isValidIP(d) {
|
|
31
|
+
const f = d.split(".");
|
|
32
|
+
return f.length === 4 && f.every(
|
|
33
|
+
(t) => /^\d+$/.test(t) && Number(t) >= 0 && Number(t) <= 255
|
|
34
|
+
) ? !0 : /^(?:(?:[a-fA-F\d]{1,4}:){7}(?:[a-fA-F\d]{1,4}|:)|(?:[a-fA-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-fA-F\d]{1,4}|:)|(?:[a-fA-F\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]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