@oxog/utils 1.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.
@@ -0,0 +1,157 @@
1
+ import { a as DiffResult } from '../types-XmRC5wYO.cjs';
2
+
3
+ /**
4
+ * Deep clone an object with circular reference support.
5
+ *
6
+ * Creates a deep copy of an object, handling circular references,
7
+ * Date, RegExp, Map, Set, and other special types.
8
+ *
9
+ * @param obj - Object to clone
10
+ * @returns Deep cloned object
11
+ *
12
+ * @example Basic usage
13
+ * ```typescript
14
+ * const obj = { a: 1, b: { c: 2 } };
15
+ * const clone = cloneDeep(obj);
16
+ * console.log(clone === obj); // false (different references)
17
+ * console.log(clone.b === obj.b); // false (deep clone)
18
+ * ```
19
+ *
20
+ * @example Circular reference handling
21
+ * ```typescript
22
+ * const obj = { a: 1 };
23
+ * obj.self = obj; // circular!
24
+ * const clone = cloneDeep(obj); // Works! No infinite loop
25
+ * ```
26
+ *
27
+ * @example Special types
28
+ * ```typescript
29
+ * const obj = {
30
+ * date: new Date(),
31
+ * regex: /test/g,
32
+ * map: new Map([['key', 'value']]),
33
+ * set: new Set([1, 2, 3])
34
+ * };
35
+ * const clone = cloneDeep(obj);
36
+ * console.log(clone.date instanceof Date); // true
37
+ * console.log(clone.regex instanceof RegExp); // true
38
+ * console.log(clone.map instanceof Map); // true
39
+ * console.log(clone.set instanceof Set); // true
40
+ * ```
41
+ */
42
+ declare function cloneDeep<T>(obj: T, seen?: WeakMap<object, any>): T;
43
+ /**
44
+ * Deep merge objects with prototype pollution protection.
45
+ *
46
+ * Recursively merges sources into target, creating new objects for nested structures.
47
+ * Prototype pollution protection: filters out __proto__, constructor, prototype.
48
+ *
49
+ * @param target - Target object
50
+ * @param sources - Source objects to merge
51
+ * @returns Deep merged object
52
+ *
53
+ * @example Basic usage
54
+ * ```typescript
55
+ * const target = { a: { b: 1, c: 1 } };
56
+ * const source = { a: { b: 2, d: 2 }, e: 3 };
57
+ * mergeDeep(target, source);
58
+ * // { a: { b: 2, c: 1, d: 2 }, e: 3 }
59
+ * ```
60
+ *
61
+ * @example Prototype pollution protection
62
+ * ```typescript
63
+ * mergeDeep({}, { a: { __proto__: { evil: true } } }); // { a: {} }
64
+ * mergeDeep({}, { __proto__: { evil: true } }); // {}
65
+ * ```
66
+ *
67
+ * @example Multiple sources
68
+ * ```typescript
69
+ * mergeDeep(
70
+ * { a: { b: 1 } },
71
+ * { a: { c: 2 } },
72
+ * { a: { d: 3 } }
73
+ * );
74
+ * // { a: { b: 1, c: 2, d: 3 } }
75
+ * ```
76
+ */
77
+ declare function mergeDeep<T extends object>(target: T, ...sources: Partial<T>[]): T;
78
+ /**
79
+ * Deep equality comparison.
80
+ *
81
+ * Recursively compares two values for deep equality.
82
+ * Handles objects, arrays, Date, RegExp, Map, Set, and primitives.
83
+ *
84
+ * @param a - First value to compare
85
+ * @param b - Second value to compare
86
+ * @returns True if values are deeply equal
87
+ *
88
+ * @example Primitives
89
+ * ```typescript
90
+ * isEqual(1, 1); // true
91
+ * isEqual('hello', 'hello'); // true
92
+ * isEqual(true, true); // true
93
+ * isEqual(1, '1'); // false
94
+ * ```
95
+ *
96
+ * @example Arrays
97
+ * ```typescript
98
+ * isEqual([1, 2, 3], [1, 2, 3]); // true
99
+ * isEqual([1, 2, 3], [1, 2, 4]); // false
100
+ * isEqual([1, [2, 3]], [1, [2, 3]]); // true
101
+ * ```
102
+ *
103
+ * @example Objects
104
+ * ```typescript
105
+ * isEqual({ a: 1, b: 2 }, { a: 1, b: 2 }); // true
106
+ * isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); // true (order doesn't matter)
107
+ * isEqual({ a: 1, b: 2 }, { a: 1, b: 3 }); // false
108
+ * isEqual({ a: { b: 1 } }, { a: { b: 1 } }); // true
109
+ * ```
110
+ *
111
+ * @example Special types
112
+ * ```typescript
113
+ * isEqual(new Date('2024-01-01'), new Date('2024-01-01')); // true
114
+ * isEqual(/test/g, /test/g); // true
115
+ * isEqual(new Set([1, 2]), new Set([1, 2])); // true
116
+ * isEqual(new Map([['a', 1]]), new Map([['a', 1]])); // true
117
+ * ```
118
+ *
119
+ * @example NaN handling
120
+ * ```typescript
121
+ * isEqual(NaN, NaN); // true
122
+ * ```
123
+ */
124
+ declare function isEqual(a: unknown, b: unknown): boolean;
125
+ /**
126
+ * Get differences between two objects.
127
+ *
128
+ * Compares two objects and returns a summary of changes.
129
+ *
130
+ * @param a - First object
131
+ * @param b - Second object
132
+ * @returns Diff result with changed, added, and removed properties
133
+ *
134
+ * @example Basic usage
135
+ * ```typescript
136
+ * diff({ a: 1, b: 2 }, { a: 1, b: 3, c: 4 });
137
+ * // { changed: { b: { from: 2, to: 3 } }, added: { c: 4 }, removed: {} }
138
+ * ```
139
+ *
140
+ * @example Complex object
141
+ * ```typescript
142
+ * diff(
143
+ * { user: { name: 'Alice', age: 30 } },
144
+ * { user: { name: 'Alice', age: 31 }, role: 'admin' }
145
+ * );
146
+ * // { changed: { user: { age: { from: 30, to: 31 } } }, added: { role: 'admin' }, removed: {} }
147
+ * ```
148
+ *
149
+ * @example Removed properties
150
+ * ```typescript
151
+ * diff({ a: 1, b: 2, c: 3 }, { a: 1 });
152
+ * // { changed: {}, added: {}, removed: { b: 2, c: 3 } }
153
+ * ```
154
+ */
155
+ declare function diff<T extends object>(a: T, b: Partial<T>): DiffResult;
156
+
157
+ export { cloneDeep, diff, isEqual, mergeDeep };
@@ -0,0 +1,157 @@
1
+ import { a as DiffResult } from '../types-XmRC5wYO.js';
2
+
3
+ /**
4
+ * Deep clone an object with circular reference support.
5
+ *
6
+ * Creates a deep copy of an object, handling circular references,
7
+ * Date, RegExp, Map, Set, and other special types.
8
+ *
9
+ * @param obj - Object to clone
10
+ * @returns Deep cloned object
11
+ *
12
+ * @example Basic usage
13
+ * ```typescript
14
+ * const obj = { a: 1, b: { c: 2 } };
15
+ * const clone = cloneDeep(obj);
16
+ * console.log(clone === obj); // false (different references)
17
+ * console.log(clone.b === obj.b); // false (deep clone)
18
+ * ```
19
+ *
20
+ * @example Circular reference handling
21
+ * ```typescript
22
+ * const obj = { a: 1 };
23
+ * obj.self = obj; // circular!
24
+ * const clone = cloneDeep(obj); // Works! No infinite loop
25
+ * ```
26
+ *
27
+ * @example Special types
28
+ * ```typescript
29
+ * const obj = {
30
+ * date: new Date(),
31
+ * regex: /test/g,
32
+ * map: new Map([['key', 'value']]),
33
+ * set: new Set([1, 2, 3])
34
+ * };
35
+ * const clone = cloneDeep(obj);
36
+ * console.log(clone.date instanceof Date); // true
37
+ * console.log(clone.regex instanceof RegExp); // true
38
+ * console.log(clone.map instanceof Map); // true
39
+ * console.log(clone.set instanceof Set); // true
40
+ * ```
41
+ */
42
+ declare function cloneDeep<T>(obj: T, seen?: WeakMap<object, any>): T;
43
+ /**
44
+ * Deep merge objects with prototype pollution protection.
45
+ *
46
+ * Recursively merges sources into target, creating new objects for nested structures.
47
+ * Prototype pollution protection: filters out __proto__, constructor, prototype.
48
+ *
49
+ * @param target - Target object
50
+ * @param sources - Source objects to merge
51
+ * @returns Deep merged object
52
+ *
53
+ * @example Basic usage
54
+ * ```typescript
55
+ * const target = { a: { b: 1, c: 1 } };
56
+ * const source = { a: { b: 2, d: 2 }, e: 3 };
57
+ * mergeDeep(target, source);
58
+ * // { a: { b: 2, c: 1, d: 2 }, e: 3 }
59
+ * ```
60
+ *
61
+ * @example Prototype pollution protection
62
+ * ```typescript
63
+ * mergeDeep({}, { a: { __proto__: { evil: true } } }); // { a: {} }
64
+ * mergeDeep({}, { __proto__: { evil: true } }); // {}
65
+ * ```
66
+ *
67
+ * @example Multiple sources
68
+ * ```typescript
69
+ * mergeDeep(
70
+ * { a: { b: 1 } },
71
+ * { a: { c: 2 } },
72
+ * { a: { d: 3 } }
73
+ * );
74
+ * // { a: { b: 1, c: 2, d: 3 } }
75
+ * ```
76
+ */
77
+ declare function mergeDeep<T extends object>(target: T, ...sources: Partial<T>[]): T;
78
+ /**
79
+ * Deep equality comparison.
80
+ *
81
+ * Recursively compares two values for deep equality.
82
+ * Handles objects, arrays, Date, RegExp, Map, Set, and primitives.
83
+ *
84
+ * @param a - First value to compare
85
+ * @param b - Second value to compare
86
+ * @returns True if values are deeply equal
87
+ *
88
+ * @example Primitives
89
+ * ```typescript
90
+ * isEqual(1, 1); // true
91
+ * isEqual('hello', 'hello'); // true
92
+ * isEqual(true, true); // true
93
+ * isEqual(1, '1'); // false
94
+ * ```
95
+ *
96
+ * @example Arrays
97
+ * ```typescript
98
+ * isEqual([1, 2, 3], [1, 2, 3]); // true
99
+ * isEqual([1, 2, 3], [1, 2, 4]); // false
100
+ * isEqual([1, [2, 3]], [1, [2, 3]]); // true
101
+ * ```
102
+ *
103
+ * @example Objects
104
+ * ```typescript
105
+ * isEqual({ a: 1, b: 2 }, { a: 1, b: 2 }); // true
106
+ * isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); // true (order doesn't matter)
107
+ * isEqual({ a: 1, b: 2 }, { a: 1, b: 3 }); // false
108
+ * isEqual({ a: { b: 1 } }, { a: { b: 1 } }); // true
109
+ * ```
110
+ *
111
+ * @example Special types
112
+ * ```typescript
113
+ * isEqual(new Date('2024-01-01'), new Date('2024-01-01')); // true
114
+ * isEqual(/test/g, /test/g); // true
115
+ * isEqual(new Set([1, 2]), new Set([1, 2])); // true
116
+ * isEqual(new Map([['a', 1]]), new Map([['a', 1]])); // true
117
+ * ```
118
+ *
119
+ * @example NaN handling
120
+ * ```typescript
121
+ * isEqual(NaN, NaN); // true
122
+ * ```
123
+ */
124
+ declare function isEqual(a: unknown, b: unknown): boolean;
125
+ /**
126
+ * Get differences between two objects.
127
+ *
128
+ * Compares two objects and returns a summary of changes.
129
+ *
130
+ * @param a - First object
131
+ * @param b - Second object
132
+ * @returns Diff result with changed, added, and removed properties
133
+ *
134
+ * @example Basic usage
135
+ * ```typescript
136
+ * diff({ a: 1, b: 2 }, { a: 1, b: 3, c: 4 });
137
+ * // { changed: { b: { from: 2, to: 3 } }, added: { c: 4 }, removed: {} }
138
+ * ```
139
+ *
140
+ * @example Complex object
141
+ * ```typescript
142
+ * diff(
143
+ * { user: { name: 'Alice', age: 30 } },
144
+ * { user: { name: 'Alice', age: 31 }, role: 'admin' }
145
+ * );
146
+ * // { changed: { user: { age: { from: 30, to: 31 } } }, added: { role: 'admin' }, removed: {} }
147
+ * ```
148
+ *
149
+ * @example Removed properties
150
+ * ```typescript
151
+ * diff({ a: 1, b: 2, c: 3 }, { a: 1 });
152
+ * // { changed: {}, added: {}, removed: { b: 2, c: 3 } }
153
+ * ```
154
+ */
155
+ declare function diff<T extends object>(a: T, b: Partial<T>): DiffResult;
156
+
157
+ export { cloneDeep, diff, isEqual, mergeDeep };
@@ -0,0 +1,152 @@
1
+ // src/plugins/optional/deep.ts
2
+ function cloneDeep(obj, seen = /* @__PURE__ */ new WeakMap()) {
3
+ if (obj === null || typeof obj !== "object") {
4
+ return obj;
5
+ }
6
+ if (seen.has(obj)) {
7
+ return seen.get(obj);
8
+ }
9
+ if (obj instanceof Date) {
10
+ const clone2 = new Date(obj.getTime());
11
+ seen.set(obj, clone2);
12
+ return clone2;
13
+ }
14
+ if (obj instanceof RegExp) {
15
+ const clone2 = new RegExp(obj.source, obj.flags);
16
+ seen.set(obj, clone2);
17
+ return clone2;
18
+ }
19
+ if (obj instanceof Map) {
20
+ const clone2 = /* @__PURE__ */ new Map();
21
+ seen.set(obj, clone2);
22
+ for (const [key, value] of obj) {
23
+ clone2.set(cloneDeep(key, seen), cloneDeep(value, seen));
24
+ }
25
+ return clone2;
26
+ }
27
+ if (obj instanceof Set) {
28
+ const clone2 = /* @__PURE__ */ new Set();
29
+ seen.set(obj, clone2);
30
+ for (const value of obj) {
31
+ clone2.add(cloneDeep(value, seen));
32
+ }
33
+ return clone2;
34
+ }
35
+ if (Array.isArray(obj)) {
36
+ const clone2 = [];
37
+ seen.set(obj, clone2);
38
+ for (let i = 0; i < obj.length; i++) {
39
+ clone2[i] = cloneDeep(obj[i], seen);
40
+ }
41
+ return clone2;
42
+ }
43
+ const clone = {};
44
+ seen.set(obj, clone);
45
+ for (const key in obj) {
46
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
47
+ clone[key] = cloneDeep(obj[key], seen);
48
+ }
49
+ }
50
+ return clone;
51
+ }
52
+ function mergeDeep(target, ...sources) {
53
+ const DANGEROUS_KEYS = ["__proto__", "constructor", "prototype"];
54
+ const result = cloneDeep(target);
55
+ for (const source of sources) {
56
+ if (!source || typeof source !== "object") continue;
57
+ for (const key of Object.keys(source)) {
58
+ if (DANGEROUS_KEYS.includes(key)) continue;
59
+ const sourceValue = source[key];
60
+ const targetValue = result[key];
61
+ if (sourceValue && typeof sourceValue === "object" && !Array.isArray(sourceValue) && targetValue && typeof targetValue === "object" && !Array.isArray(targetValue)) {
62
+ result[key] = mergeDeep(targetValue, sourceValue);
63
+ } else {
64
+ result[key] = cloneDeep(sourceValue);
65
+ }
66
+ }
67
+ }
68
+ return result;
69
+ }
70
+ function isEqual(a, b) {
71
+ if (a === b) return true;
72
+ if (Number.isNaN(a) && Number.isNaN(b)) return true;
73
+ if (a == null || b == null) return false;
74
+ if (typeof a !== typeof b) return false;
75
+ if (typeof a !== "object") return false;
76
+ if (a instanceof Date && b instanceof Date) {
77
+ return a.getTime() === b.getTime();
78
+ }
79
+ if (a instanceof RegExp && b instanceof RegExp) {
80
+ return a.source === b.source && a.flags === b.flags;
81
+ }
82
+ if (a instanceof Map && b instanceof Map) {
83
+ if (a.size !== b.size) return false;
84
+ for (const [key, value] of a) {
85
+ if (!b.has(key) || !isEqual(value, b.get(key))) {
86
+ return false;
87
+ }
88
+ }
89
+ return true;
90
+ }
91
+ if (a instanceof Set && b instanceof Set) {
92
+ if (a.size !== b.size) return false;
93
+ for (const value of a) {
94
+ if (!b.has(value)) {
95
+ return false;
96
+ }
97
+ }
98
+ return true;
99
+ }
100
+ if (Array.isArray(a) && Array.isArray(b)) {
101
+ if (a.length !== b.length) return false;
102
+ return a.every((item, index) => isEqual(item, b[index]));
103
+ }
104
+ if (typeof a === "object" && typeof b === "object") {
105
+ const keysA = Object.keys(a);
106
+ const keysB = Object.keys(b);
107
+ if (keysA.length !== keysB.length) return false;
108
+ for (const key of keysA) {
109
+ if (!Object.prototype.hasOwnProperty.call(b, key) || !isEqual(a[key], b[key])) {
110
+ return false;
111
+ }
112
+ }
113
+ return true;
114
+ }
115
+ return false;
116
+ }
117
+ function diff(a, b) {
118
+ const result = {
119
+ changed: {},
120
+ added: {},
121
+ removed: {}
122
+ };
123
+ const keysA = Object.keys(a);
124
+ const keysB = Object.keys(b);
125
+ const allKeys = Array.from(/* @__PURE__ */ new Set([...keysA, ...keysB]));
126
+ for (const key of allKeys) {
127
+ const valueA = a[key];
128
+ const valueB = b[key];
129
+ const hasA = Object.prototype.hasOwnProperty.call(a, key);
130
+ const hasB = Object.prototype.hasOwnProperty.call(b, key);
131
+ if (!hasA && hasB) {
132
+ result.added[key] = valueB;
133
+ } else if (hasA && !hasB) {
134
+ result.removed[key] = valueA;
135
+ } else if (!isEqual(valueA, valueB)) {
136
+ if (typeof valueA === "object" && valueA !== null && typeof valueB === "object" && valueB !== null) {
137
+ const nestedDiff = diff(valueA, valueB);
138
+ const nestedChanged = nestedDiff.changed || {};
139
+ if (Object.keys(nestedChanged).length > 0) {
140
+ result.changed[key] = nestedChanged;
141
+ }
142
+ } else {
143
+ result.changed[key] = { from: valueA, to: valueB };
144
+ }
145
+ }
146
+ }
147
+ return result;
148
+ }
149
+
150
+ export { cloneDeep, diff, isEqual, mergeDeep };
151
+ //# sourceMappingURL=deep.js.map
152
+ //# sourceMappingURL=deep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/optional/deep.ts"],"names":["clone"],"mappings":";AAyCO,SAAS,SAAA,CAAa,GAAA,EAAQ,IAAA,mBAAO,IAAI,SAAqB,EAAM;AACzE,EAAA,IAAI,GAAA,KAAQ,IAAA,IAAQ,OAAO,GAAA,KAAQ,QAAA,EAAU;AAC3C,IAAA,OAA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,GAAG,CAAA,GAAI,MAAA;AAAA,IAC/B,CAAA,MAAA,IAAW,IAAA,IAAQ,CAAC,IAAA,EAAM;AACxB,MAAC,MAAA,CAAO,OAAA,CAAgB,GAAG,CAAA,GAAI,MAAA;AAAA,IACjC,CAAA,MAAA,IAAW,CAAC,OAAA,CAAQ,MAAA,EAAQ,MAAM,CAAA,EAAG;AACnC,MAAA,IACE,OAAO,WAAW,QAAA,IAClB,MAAA,KAAW,QACX,OAAO,MAAA,KAAW,QAAA,IAClB,MAAA,KAAW,IAAA,EACX;AACA,QAAA,MAAM,UAAA,GAAa,IAAA,CAAK,MAAA,EAAkB,MAAgB,CAAA;AAE1D,QAAA,MAAM,aAAA,GAAgB,UAAA,CAAW,OAAA,IAAW,EAAC;AAC7C,QAAA,IAAI,MAAA,CAAO,IAAA,CAAK,aAAa,CAAA,CAAE,SAAS,CAAA,EAAG;AACzC,UAAC,MAAA,CAAO,OAAA,CAAgB,GAAG,CAAA,GAAI,aAAA;AAAA,QACjC;AAAA,MACF,CAAA,MAAO;AACL,QAAC,MAAA,CAAO,QAAgB,GAAG,CAAA,GAAI,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAI,MAAA,EAAO;AAAA,MAC5D;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"deep.js","sourcesContent":["import { DiffResult } from '../../types.js';\n\n/**\n * Deep clone an object with circular reference support.\n *\n * Creates a deep copy of an object, handling circular references,\n * Date, RegExp, Map, Set, and other special types.\n *\n * @param obj - Object to clone\n * @returns Deep cloned object\n *\n * @example Basic usage\n * ```typescript\n * const obj = { a: 1, b: { c: 2 } };\n * const clone = cloneDeep(obj);\n * console.log(clone === obj); // false (different references)\n * console.log(clone.b === obj.b); // false (deep clone)\n * ```\n *\n * @example Circular reference handling\n * ```typescript\n * const obj = { a: 1 };\n * obj.self = obj; // circular!\n * const clone = cloneDeep(obj); // Works! No infinite loop\n * ```\n *\n * @example Special types\n * ```typescript\n * const obj = {\n * date: new Date(),\n * regex: /test/g,\n * map: new Map([['key', 'value']]),\n * set: new Set([1, 2, 3])\n * };\n * const clone = cloneDeep(obj);\n * console.log(clone.date instanceof Date); // true\n * console.log(clone.regex instanceof RegExp); // true\n * console.log(clone.map instanceof Map); // true\n * console.log(clone.set instanceof Set); // true\n * ```\n */\nexport function cloneDeep<T>(obj: T, seen = new WeakMap<object, any>()): T {\n if (obj === null || typeof obj !== 'object') {\n return obj;\n }\n\n if (seen.has(obj)) {\n return seen.get(obj);\n }\n\n if (obj instanceof Date) {\n const clone = new Date(obj.getTime());\n seen.set(obj, clone);\n return clone as T;\n }\n\n if (obj instanceof RegExp) {\n const clone = new RegExp(obj.source, obj.flags);\n seen.set(obj, clone);\n return clone as T;\n }\n\n if (obj instanceof Map) {\n const clone = new Map();\n seen.set(obj, clone);\n for (const [key, value] of obj) {\n clone.set(cloneDeep(key, seen), cloneDeep(value, seen));\n }\n return clone as T;\n }\n\n if (obj instanceof Set) {\n const clone = new Set();\n seen.set(obj, clone);\n for (const value of obj) {\n clone.add(cloneDeep(value, seen));\n }\n return clone as T;\n }\n\n if (Array.isArray(obj)) {\n const clone = [] as any;\n seen.set(obj, clone);\n for (let i = 0; i < obj.length; i++) {\n clone[i] = cloneDeep(obj[i], seen);\n }\n return clone;\n }\n\n const clone = {} as any;\n seen.set(obj, clone);\n for (const key in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, key)) {\n clone[key] = cloneDeep(obj[key], seen);\n }\n }\n\n return clone;\n}\n\n/**\n * Deep merge objects with prototype pollution protection.\n *\n * Recursively merges sources into target, creating new objects for nested structures.\n * Prototype pollution protection: filters out __proto__, constructor, prototype.\n *\n * @param target - Target object\n * @param sources - Source objects to merge\n * @returns Deep merged object\n *\n * @example Basic usage\n * ```typescript\n * const target = { a: { b: 1, c: 1 } };\n * const source = { a: { b: 2, d: 2 }, e: 3 };\n * mergeDeep(target, source);\n * // { a: { b: 2, c: 1, d: 2 }, e: 3 }\n * ```\n *\n * @example Prototype pollution protection\n * ```typescript\n * mergeDeep({}, { a: { __proto__: { evil: true } } }); // { a: {} }\n * mergeDeep({}, { __proto__: { evil: true } }); // {}\n * ```\n *\n * @example Multiple sources\n * ```typescript\n * mergeDeep(\n * { a: { b: 1 } },\n * { a: { c: 2 } },\n * { a: { d: 3 } }\n * );\n * // { a: { b: 1, c: 2, d: 3 } }\n * ```\n */\nexport function mergeDeep<T extends object>(target: T, ...sources: Partial<T>[]): T {\n const DANGEROUS_KEYS = ['__proto__', 'constructor', 'prototype'];\n\n const result = cloneDeep(target);\n\n for (const source of sources) {\n if (!source || typeof source !== 'object') continue;\n\n for (const key of Object.keys(source)) {\n if (DANGEROUS_KEYS.includes(key)) continue;\n\n const sourceValue = (source as any)[key];\n const targetValue = (result as any)[key];\n\n if (\n sourceValue &&\n typeof sourceValue === 'object' &&\n !Array.isArray(sourceValue) &&\n targetValue &&\n typeof targetValue === 'object' &&\n !Array.isArray(targetValue)\n ) {\n (result as any)[key] = mergeDeep(targetValue, sourceValue);\n } else {\n (result as any)[key] = cloneDeep(sourceValue);\n }\n }\n }\n\n return result;\n}\n\n/**\n * Deep equality comparison.\n *\n * Recursively compares two values for deep equality.\n * Handles objects, arrays, Date, RegExp, Map, Set, and primitives.\n *\n * @param a - First value to compare\n * @param b - Second value to compare\n * @returns True if values are deeply equal\n *\n * @example Primitives\n * ```typescript\n * isEqual(1, 1); // true\n * isEqual('hello', 'hello'); // true\n * isEqual(true, true); // true\n * isEqual(1, '1'); // false\n * ```\n *\n * @example Arrays\n * ```typescript\n * isEqual([1, 2, 3], [1, 2, 3]); // true\n * isEqual([1, 2, 3], [1, 2, 4]); // false\n * isEqual([1, [2, 3]], [1, [2, 3]]); // true\n * ```\n *\n * @example Objects\n * ```typescript\n * isEqual({ a: 1, b: 2 }, { a: 1, b: 2 }); // true\n * isEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); // true (order doesn't matter)\n * isEqual({ a: 1, b: 2 }, { a: 1, b: 3 }); // false\n * isEqual({ a: { b: 1 } }, { a: { b: 1 } }); // true\n * ```\n *\n * @example Special types\n * ```typescript\n * isEqual(new Date('2024-01-01'), new Date('2024-01-01')); // true\n * isEqual(/test/g, /test/g); // true\n * isEqual(new Set([1, 2]), new Set([1, 2])); // true\n * isEqual(new Map([['a', 1]]), new Map([['a', 1]])); // true\n * ```\n *\n * @example NaN handling\n * ```typescript\n * isEqual(NaN, NaN); // true\n * ```\n */\nexport function isEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n\n // Handle NaN: NaN !== NaN, but we want them to be equal\n if (Number.isNaN(a) && Number.isNaN(b)) return true;\n\n if (a == null || b == null) return false;\n\n if (typeof a !== typeof b) return false;\n\n if (typeof a !== 'object') return false;\n\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n if (a instanceof RegExp && b instanceof RegExp) {\n return a.source === b.source && a.flags === b.flags;\n }\n\n if (a instanceof Map && b instanceof Map) {\n if (a.size !== b.size) return false;\n for (const [key, value] of a) {\n if (!b.has(key) || !isEqual(value, b.get(key))) {\n return false;\n }\n }\n return true;\n }\n\n if (a instanceof Set && b instanceof Set) {\n if (a.size !== b.size) return false;\n for (const value of a) {\n if (!b.has(value)) {\n return false;\n }\n }\n return true;\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((item, index) => isEqual(item, b[index]));\n }\n\n if (typeof a === 'object' && typeof b === 'object') {\n const keysA = Object.keys(a as object);\n const keysB = Object.keys(b as object);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (\n !Object.prototype.hasOwnProperty.call(b, key) ||\n !isEqual((a as any)[key], (b as any)[key])\n ) {\n return false;\n }\n }\n\n return true;\n }\n\n return false;\n}\n\n/**\n * Get differences between two objects.\n *\n * Compares two objects and returns a summary of changes.\n *\n * @param a - First object\n * @param b - Second object\n * @returns Diff result with changed, added, and removed properties\n *\n * @example Basic usage\n * ```typescript\n * diff({ a: 1, b: 2 }, { a: 1, b: 3, c: 4 });\n * // { changed: { b: { from: 2, to: 3 } }, added: { c: 4 }, removed: {} }\n * ```\n *\n * @example Complex object\n * ```typescript\n * diff(\n * { user: { name: 'Alice', age: 30 } },\n * { user: { name: 'Alice', age: 31 }, role: 'admin' }\n * );\n * // { changed: { user: { age: { from: 30, to: 31 } } }, added: { role: 'admin' }, removed: {} }\n * ```\n *\n * @example Removed properties\n * ```typescript\n * diff({ a: 1, b: 2, c: 3 }, { a: 1 });\n * // { changed: {}, added: {}, removed: { b: 2, c: 3 } }\n * ```\n */\nexport function diff<T extends object>(a: T, b: Partial<T>): DiffResult {\n const result: DiffResult = {\n changed: {},\n added: {},\n removed: {}\n };\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n const allKeys = Array.from(new Set([...keysA, ...keysB]));\n\n for (const key of allKeys) {\n const valueA = a[key as keyof T];\n const valueB = b[key as keyof T];\n\n const hasA = Object.prototype.hasOwnProperty.call(a, key);\n const hasB = Object.prototype.hasOwnProperty.call(b, key);\n\n if (!hasA && hasB) {\n (result.added as any)[key] = valueB;\n } else if (hasA && !hasB) {\n (result.removed as any)[key] = valueA;\n } else if (!isEqual(valueA, valueB)) {\n if (\n typeof valueA === 'object' &&\n valueA !== null &&\n typeof valueB === 'object' &&\n valueB !== null\n ) {\n const nestedDiff = diff(valueA as object, valueB as object);\n // For nested diffs, only include 'changed' property (not added/removed)\n const nestedChanged = nestedDiff.changed || {};\n if (Object.keys(nestedChanged).length > 0) {\n (result.changed as any)[key] = nestedChanged;\n }\n } else {\n (result.changed as any)[key] = { from: valueA, to: valueB };\n }\n }\n }\n\n return result;\n}\n"]}
@@ -0,0 +1,47 @@
1
+ 'use strict';
2
+
3
+ // src/plugins/optional/guard.ts
4
+ function isEmpty(value) {
5
+ if (Array.isArray(value)) return value.length === 0;
6
+ if (value instanceof Map) return value.size === 0;
7
+ if (value instanceof Set) return value.size === 0;
8
+ if (value instanceof Date || value instanceof RegExp) return false;
9
+ if (typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Map) && !(value instanceof Set)) {
10
+ return Object.keys(value).length === 0;
11
+ }
12
+ return false;
13
+ }
14
+ function isNil(value) {
15
+ return value === null || value === void 0;
16
+ }
17
+ function isPlainObject(value) {
18
+ if (typeof value !== "object" || value === null) return false;
19
+ const proto = Object.getPrototypeOf(value);
20
+ return proto === null || proto === Object.prototype;
21
+ }
22
+ function isArray(value) {
23
+ return Array.isArray(value);
24
+ }
25
+ function isString(value) {
26
+ return typeof value === "string";
27
+ }
28
+ function isNumber(value) {
29
+ return typeof value === "number" && !Number.isNaN(value);
30
+ }
31
+ function isFunction(value) {
32
+ return typeof value === "function";
33
+ }
34
+ function isDate(value) {
35
+ return value instanceof Date && !Number.isNaN(value.getTime());
36
+ }
37
+
38
+ exports.isArray = isArray;
39
+ exports.isDate = isDate;
40
+ exports.isEmpty = isEmpty;
41
+ exports.isFunction = isFunction;
42
+ exports.isNil = isNil;
43
+ exports.isNumber = isNumber;
44
+ exports.isPlainObject = isPlainObject;
45
+ exports.isString = isString;
46
+ //# sourceMappingURL=guard.cjs.map
47
+ //# sourceMappingURL=guard.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/optional/guard.ts"],"names":[],"mappings":";;;AAuCO,SAAS,QACd,KAAA,EAKa;AACb,EAAA,IAAI,MAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,OAAO,MAAM,MAAA,KAAW,CAAA;AAClD,EAAA,IAAI,KAAA,YAAiB,GAAA,EAAK,OAAO,KAAA,CAAM,IAAA,KAAS,CAAA;AAChD,EAAA,IAAI,KAAA,YAAiB,GAAA,EAAK,OAAO,KAAA,CAAM,IAAA,KAAS,CAAA;AAEhD,EAAA,IAAI,KAAA,YAAiB,IAAA,IAAQ,KAAA,YAAiB,MAAA,EAAQ,OAAO,KAAA;AAC7D,EAAA,IACE,OAAO,KAAA,KAAU,QAAA,IACjB,KAAA,KAAU,QACV,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,KACpB,EAAE,KAAA,YAAiB,GAAA,CAAA,IACnB,EAAE,iBAAiB,GAAA,CAAA,EACnB;AACA,IAAA,OAAO,MAAA,CAAO,IAAA,CAAK,KAAK,CAAA,CAAE,MAAA,KAAW,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,KAAA;AACT;AAyBO,SAAS,MAAM,KAAA,EAA2C;AAC/D,EAAA,OAAO,KAAA,KAAU,QAAQ,KAAA,KAAU,MAAA;AACrC;AAoCO,SAAS,cAAc,KAAA,EAAkD;AAC9E,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AAExD,EAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA;AACzC,EAAA,OAAO,KAAA,KAAU,IAAA,IAAQ,KAAA,KAAU,MAAA,CAAO,SAAA;AAC5C;AAgBO,SAAS,QAAQ,KAAA,EAAgC;AACtD,EAAA,OAAO,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5B;AAgBO,SAAS,SAAS,KAAA,EAAiC;AACxD,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA;AAC1B;AAgCO,SAAS,SAAS,KAAA,EAAiC;AACxD,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,CAAC,MAAA,CAAO,MAAM,KAAK,CAAA;AACzD;AAuBO,SAAS,WAAW,KAAA,EAAkD;AAC3E,EAAA,OAAO,OAAO,KAAA,KAAU,UAAA;AAC1B;AA8BO,SAAS,OAAO,KAAA,EAA+B;AACpD,EAAA,OAAO,iBAAiB,IAAA,IAAQ,CAAC,OAAO,KAAA,CAAM,KAAA,CAAM,SAAS,CAAA;AAC/D","file":"guard.cjs","sourcesContent":["/**\n * Check if collection is empty.\n *\n * Returns true for empty arrays, objects, Maps, or Sets.\n * Note: Unlike lodash, this returns false for strings and numbers!\n *\n * @param value - Value to check\n * @returns True if collection is empty\n *\n * @example Arrays\n * ```typescript\n * isEmpty([]); // true\n * isEmpty([1, 2, 3]); // false\n * ```\n *\n * @example Objects\n * ```typescript\n * isEmpty({}); // true\n * isEmpty({ a: 1 }); // false\n * ```\n *\n * @example Map and Set\n * ```typescript\n * isEmpty(new Map()); // true\n * isEmpty(new Set()); // true\n * isEmpty(new Map([['a', 1]])); // false\n * ```\n *\n * @example Non-collections (returns false)\n * ```typescript\n * isEmpty(''); // false - strings are not collections\n * isEmpty(0); // false - numbers are not collections\n * isEmpty(false); // false - booleans are not collections\n * isEmpty(null); // false - null is not a collection\n * isEmpty(undefined); // false - undefined is not a collection\n * ```\n *\n * @see {@link isNil} for null/undefined check\n */\nexport function isEmpty(\n value: unknown\n): value is\n | []\n | Record<string, never>\n | Map<any, never>\n | Set<never> {\n if (Array.isArray(value)) return value.length === 0;\n if (value instanceof Map) return value.size === 0;\n if (value instanceof Set) return value.size === 0;\n // Exclude Date, RegExp, and other built-in objects from \"empty object\" check\n if (value instanceof Date || value instanceof RegExp) return false;\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n !(value instanceof Map) &&\n !(value instanceof Set)\n ) {\n return Object.keys(value).length === 0;\n }\n return false;\n}\n\n/**\n * Check if value is null or undefined.\n *\n * @param value - Value to check\n * @returns True if value is null or undefined\n *\n * @example Basic usage\n * ```typescript\n * isNil(null); // true\n * isNil(undefined); // true\n * ```\n *\n * @example False cases\n * ```typescript\n * isNil(0); // false\n * isNil(''); // false\n * isNil(false); // false\n * isNil([]); // false\n * isNil({}); // false\n * ```\n *\n * @see {@link isEmpty} for collection emptiness check\n */\nexport function isNil(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * Check if value is a plain object.\n *\n * Returns true for plain objects created by object literal or Object.create(null).\n * Returns false for class instances, arrays, Date, RegExp, etc.\n *\n * @param value - Value to check\n * @returns True if value is a plain object\n *\n * @example Plain objects\n * ```typescript\n * isPlainObject({}); // true\n * isPlainObject({ a: 1 }); // true\n * isPlainObject(Object.create(null)); // true\n * ```\n *\n * @example Non-plain objects\n * ```typescript\n * isPlainObject(new Date()); // false (class instance)\n * isPlainObject([]); // false (array)\n * isPlainObject(/test/); // false (RegExp)\n * isPlainObject(new Map()); // false (Map)\n * isPlainObject(new Set()); // false (Set)\n * isPlainObject(() => {}); // false (function)\n * isPlainObject(null); // false\n * isPlainObject(undefined); // false\n * ```\n *\n * @example Class instances\n * ```typescript\n * class MyClass {}\n * isPlainObject(new MyClass()); // false\n * ```\n */\nexport function isPlainObject(value: unknown): value is Record<string, unknown> {\n if (typeof value !== 'object' || value === null) return false;\n\n const proto = Object.getPrototypeOf(value);\n return proto === null || proto === Object.prototype;\n}\n\n/**\n * Type guard for arrays.\n *\n * @param value - Value to check\n * @returns True if value is an array\n *\n * @example Basic usage\n * ```typescript\n * const value: unknown = [1, 2, 3];\n * if (isArray(value)) {\n * value.map(x => x * 2); // TypeScript knows it's an array\n * }\n * ```\n */\nexport function isArray(value: unknown): value is any[] {\n return Array.isArray(value);\n}\n\n/**\n * Type guard for strings.\n *\n * @param value - Value to check\n * @returns True if value is a string\n *\n * @example Basic usage\n * ```typescript\n * const value: unknown = 'hello';\n * if (isString(value)) {\n * value.toUpperCase(); // TypeScript knows it's a string\n * }\n * ```\n */\nexport function isString(value: unknown): value is string {\n return typeof value === 'string';\n}\n\n/**\n * Type guard for numbers.\n *\n * Returns false for NaN (unlike typeof operator).\n *\n * @param value - Value to check\n * @returns True if value is a valid number\n *\n * @example Basic usage\n * ```typescript\n * isNumber(42); // true\n * isNumber(3.14); // true\n * isNumber(-5); // true\n * isNumber(Infinity); // true\n * ```\n *\n * @example NaN handling\n * ```typescript\n * isNumber(NaN); // false (unlike typeof!)\n * typeof NaN === 'number'; // true\n * ```\n *\n * @example Non-numbers\n * ```typescript\n * isNumber('42'); // false\n * isNumber(null); // false\n * isNumber(undefined); // false\n * isNumber({}); // false\n * ```\n */\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number' && !Number.isNaN(value);\n}\n\n/**\n * Type guard for functions.\n *\n * @param value - Value to check\n * @returns True if value is a function\n *\n * @example Basic usage\n * ```typescript\n * isFunction(() => {}); // true\n * isFunction(function() {}); // true\n * isFunction(async () => {}); // true\n * ```\n *\n * @example Non-functions\n * ```typescript\n * isFunction({}); // false\n * isFunction(null); // false\n * isFunction(undefined); // false\n * isFunction('string'); // false\n * ```\n */\nexport function isFunction(value: unknown): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n\n/**\n * Type guard for valid Date objects.\n *\n * Returns true for Date objects with valid time values.\n *\n * @param value - Value to check\n * @returns True if value is a valid Date\n *\n * @example Valid dates\n * ```typescript\n * isDate(new Date()); // true\n * isDate(new Date('2024-01-01')); // true\n * ```\n *\n * @example Invalid dates\n * ```typescript\n * isDate(new Date('invalid')); // false\n * isDate(Date.now()); // false (number)\n * ```\n *\n * @example Non-dates\n * ```typescript\n * isDate({}); // false\n * isDate(null); // false\n * isDate(undefined); // false\n * isDate('2024-01-01'); // false (string)\n * ```\n */\nexport function isDate(value: unknown): value is Date {\n return value instanceof Date && !Number.isNaN(value.getTime());\n}\n"]}