@kopexa/shared-utils 1.1.3 → 1.1.5
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/functions.d.mts +20 -1
- package/dist/functions.d.ts +20 -1
- package/dist/functions.js +10 -0
- package/dist/functions.mjs +9 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +53 -0
- package/dist/index.mjs +49 -0
- package/dist/object.d.mts +23 -0
- package/dist/object.d.ts +23 -0
- package/dist/object.js +68 -0
- package/dist/object.mjs +41 -0
- package/package.json +1 -1
package/dist/functions.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** biome-ignore-all lint/complexity/noBannedTypes: utility library */
|
|
2
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: utility library */
|
|
3
|
+
type Args<T extends Function> = T extends (...args: infer R) => any ? R : never;
|
|
1
4
|
/**
|
|
2
5
|
* Generates a unique identifier using a specified prefix and a random number.
|
|
3
6
|
*
|
|
@@ -8,5 +11,21 @@
|
|
|
8
11
|
* getUniqueID('btn'); // returns 'btn-123456'
|
|
9
12
|
*/
|
|
10
13
|
declare function getUniqueID(prefix: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a function that invokes each provided function with the same argument, until
|
|
16
|
+
* one of the functions calls `event.preventDefault()`.
|
|
17
|
+
*
|
|
18
|
+
* @param fns - An array of functions that may or may not be defined.
|
|
19
|
+
* @returns A function that takes an event and invokes each handler with this event.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam T - A function type that takes an event-like argument.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const handler1 = event => console.log('Handled by first', event.type);
|
|
25
|
+
* const handler2 = event => event.preventDefault();
|
|
26
|
+
* const allHandlers = callAllHandlers(handler1, handler2);
|
|
27
|
+
* allHandlers({ type: 'click' });
|
|
28
|
+
*/
|
|
29
|
+
declare function callAllHandlers<T extends (event: any) => void>(...fns: (T | undefined)[]): (event: Args<T>[0]) => void;
|
|
11
30
|
|
|
12
|
-
export { getUniqueID };
|
|
31
|
+
export { callAllHandlers, getUniqueID };
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/** biome-ignore-all lint/complexity/noBannedTypes: utility library */
|
|
2
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: utility library */
|
|
3
|
+
type Args<T extends Function> = T extends (...args: infer R) => any ? R : never;
|
|
1
4
|
/**
|
|
2
5
|
* Generates a unique identifier using a specified prefix and a random number.
|
|
3
6
|
*
|
|
@@ -8,5 +11,21 @@
|
|
|
8
11
|
* getUniqueID('btn'); // returns 'btn-123456'
|
|
9
12
|
*/
|
|
10
13
|
declare function getUniqueID(prefix: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a function that invokes each provided function with the same argument, until
|
|
16
|
+
* one of the functions calls `event.preventDefault()`.
|
|
17
|
+
*
|
|
18
|
+
* @param fns - An array of functions that may or may not be defined.
|
|
19
|
+
* @returns A function that takes an event and invokes each handler with this event.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam T - A function type that takes an event-like argument.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const handler1 = event => console.log('Handled by first', event.type);
|
|
25
|
+
* const handler2 = event => event.preventDefault();
|
|
26
|
+
* const allHandlers = callAllHandlers(handler1, handler2);
|
|
27
|
+
* allHandlers({ type: 'click' });
|
|
28
|
+
*/
|
|
29
|
+
declare function callAllHandlers<T extends (event: any) => void>(...fns: (T | undefined)[]): (event: Args<T>[0]) => void;
|
|
11
30
|
|
|
12
|
-
export { getUniqueID };
|
|
31
|
+
export { callAllHandlers, getUniqueID };
|
package/dist/functions.js
CHANGED
|
@@ -20,13 +20,23 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/functions.ts
|
|
21
21
|
var functions_exports = {};
|
|
22
22
|
__export(functions_exports, {
|
|
23
|
+
callAllHandlers: () => callAllHandlers,
|
|
23
24
|
getUniqueID: () => getUniqueID
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(functions_exports);
|
|
26
27
|
function getUniqueID(prefix) {
|
|
27
28
|
return `${prefix}-${Math.floor(Math.random() * 1e6)}`;
|
|
28
29
|
}
|
|
30
|
+
function callAllHandlers(...fns) {
|
|
31
|
+
return function func(event) {
|
|
32
|
+
fns.some((fn) => {
|
|
33
|
+
fn == null ? void 0 : fn(event);
|
|
34
|
+
return event == null ? void 0 : event.defaultPrevented;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
}
|
|
29
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
39
|
0 && (module.exports = {
|
|
40
|
+
callAllHandlers,
|
|
31
41
|
getUniqueID
|
|
32
42
|
});
|
package/dist/functions.mjs
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
function getUniqueID(prefix) {
|
|
3
3
|
return `${prefix}-${Math.floor(Math.random() * 1e6)}`;
|
|
4
4
|
}
|
|
5
|
+
function callAllHandlers(...fns) {
|
|
6
|
+
return function func(event) {
|
|
7
|
+
fns.some((fn) => {
|
|
8
|
+
fn == null ? void 0 : fn(event);
|
|
9
|
+
return event == null ? void 0 : event.defaultPrevented;
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
|
5
13
|
export {
|
|
14
|
+
callAllHandlers,
|
|
6
15
|
getUniqueID
|
|
7
16
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { ariaAttr, dataAttr, isArray, isEmpty, isEmptyArray, isEmptyObject, isObject } from './assertion.mjs';
|
|
2
2
|
export { cn } from './clsx.mjs';
|
|
3
|
-
export { getUniqueID } from './functions.mjs';
|
|
3
|
+
export { callAllHandlers, getUniqueID } from './functions.mjs';
|
|
4
4
|
export { clamp } from './numbers.mjs';
|
|
5
|
+
export { compact, mapPropsVariants, objectToDeps } from './object.mjs';
|
|
5
6
|
export { chain } from './ra.mjs';
|
|
6
7
|
export { getInitials, safeText } from './text.mjs';
|
|
7
8
|
import 'clsx';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { ariaAttr, dataAttr, isArray, isEmpty, isEmptyArray, isEmptyObject, isObject } from './assertion.js';
|
|
2
2
|
export { cn } from './clsx.js';
|
|
3
|
-
export { getUniqueID } from './functions.js';
|
|
3
|
+
export { callAllHandlers, getUniqueID } from './functions.js';
|
|
4
4
|
export { clamp } from './numbers.js';
|
|
5
|
+
export { compact, mapPropsVariants, objectToDeps } from './object.js';
|
|
5
6
|
export { chain } from './ra.js';
|
|
6
7
|
export { getInitials, safeText } from './text.js';
|
|
7
8
|
import 'clsx';
|
package/dist/index.js
CHANGED
|
@@ -21,9 +21,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ariaAttr: () => ariaAttr,
|
|
24
|
+
callAllHandlers: () => callAllHandlers,
|
|
24
25
|
chain: () => chain,
|
|
25
26
|
clamp: () => clamp,
|
|
26
27
|
cn: () => cn,
|
|
28
|
+
compact: () => compact,
|
|
27
29
|
dataAttr: () => dataAttr,
|
|
28
30
|
getInitials: () => getInitials,
|
|
29
31
|
getUniqueID: () => getUniqueID,
|
|
@@ -32,6 +34,8 @@ __export(index_exports, {
|
|
|
32
34
|
isEmptyArray: () => isEmptyArray,
|
|
33
35
|
isEmptyObject: () => isEmptyObject,
|
|
34
36
|
isObject: () => isObject,
|
|
37
|
+
mapPropsVariants: () => mapPropsVariants,
|
|
38
|
+
objectToDeps: () => objectToDeps,
|
|
35
39
|
safeText: () => safeText
|
|
36
40
|
});
|
|
37
41
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -70,12 +74,57 @@ function cn(...inputs) {
|
|
|
70
74
|
function getUniqueID(prefix) {
|
|
71
75
|
return `${prefix}-${Math.floor(Math.random() * 1e6)}`;
|
|
72
76
|
}
|
|
77
|
+
function callAllHandlers(...fns) {
|
|
78
|
+
return function func(event) {
|
|
79
|
+
fns.some((fn) => {
|
|
80
|
+
fn == null ? void 0 : fn(event);
|
|
81
|
+
return event == null ? void 0 : event.defaultPrevented;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
73
85
|
|
|
74
86
|
// src/numbers.ts
|
|
75
87
|
function clamp(value, min, max) {
|
|
76
88
|
return Math.min(Math.max(value, min), max);
|
|
77
89
|
}
|
|
78
90
|
|
|
91
|
+
// src/object.ts
|
|
92
|
+
function compact(object) {
|
|
93
|
+
const clone = Object.assign({}, object);
|
|
94
|
+
for (const key in clone) {
|
|
95
|
+
if (clone[key] === void 0) delete clone[key];
|
|
96
|
+
}
|
|
97
|
+
return clone;
|
|
98
|
+
}
|
|
99
|
+
var mapPropsVariants = (props, variantKeys, removeVariantProps = true) => {
|
|
100
|
+
if (!variantKeys) {
|
|
101
|
+
return [props, {}];
|
|
102
|
+
}
|
|
103
|
+
const picked = variantKeys.reduce((acc, key) => {
|
|
104
|
+
if (key in props) {
|
|
105
|
+
return { ...acc, [key]: props[key] };
|
|
106
|
+
} else {
|
|
107
|
+
return acc;
|
|
108
|
+
}
|
|
109
|
+
}, {});
|
|
110
|
+
if (removeVariantProps) {
|
|
111
|
+
const omitted = Object.keys(props).filter((key) => !variantKeys.includes(key)).reduce((acc, key) => ({ ...acc, [key]: props[key] }), {});
|
|
112
|
+
return [omitted, picked];
|
|
113
|
+
} else {
|
|
114
|
+
return [props, picked];
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
function objectToDeps(obj) {
|
|
118
|
+
if (!obj || typeof obj !== "object") {
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
return JSON.stringify(obj);
|
|
123
|
+
} catch {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
79
128
|
// src/ra.ts
|
|
80
129
|
function chain(...callbacks) {
|
|
81
130
|
return (...args) => {
|
|
@@ -104,9 +153,11 @@ var getInitials = (text) => {
|
|
|
104
153
|
// Annotate the CommonJS export names for ESM import in node:
|
|
105
154
|
0 && (module.exports = {
|
|
106
155
|
ariaAttr,
|
|
156
|
+
callAllHandlers,
|
|
107
157
|
chain,
|
|
108
158
|
clamp,
|
|
109
159
|
cn,
|
|
160
|
+
compact,
|
|
110
161
|
dataAttr,
|
|
111
162
|
getInitials,
|
|
112
163
|
getUniqueID,
|
|
@@ -115,5 +166,7 @@ var getInitials = (text) => {
|
|
|
115
166
|
isEmptyArray,
|
|
116
167
|
isEmptyObject,
|
|
117
168
|
isObject,
|
|
169
|
+
mapPropsVariants,
|
|
170
|
+
objectToDeps,
|
|
118
171
|
safeText
|
|
119
172
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -32,12 +32,57 @@ function cn(...inputs) {
|
|
|
32
32
|
function getUniqueID(prefix) {
|
|
33
33
|
return `${prefix}-${Math.floor(Math.random() * 1e6)}`;
|
|
34
34
|
}
|
|
35
|
+
function callAllHandlers(...fns) {
|
|
36
|
+
return function func(event) {
|
|
37
|
+
fns.some((fn) => {
|
|
38
|
+
fn == null ? void 0 : fn(event);
|
|
39
|
+
return event == null ? void 0 : event.defaultPrevented;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
35
43
|
|
|
36
44
|
// src/numbers.ts
|
|
37
45
|
function clamp(value, min, max) {
|
|
38
46
|
return Math.min(Math.max(value, min), max);
|
|
39
47
|
}
|
|
40
48
|
|
|
49
|
+
// src/object.ts
|
|
50
|
+
function compact(object) {
|
|
51
|
+
const clone = Object.assign({}, object);
|
|
52
|
+
for (const key in clone) {
|
|
53
|
+
if (clone[key] === void 0) delete clone[key];
|
|
54
|
+
}
|
|
55
|
+
return clone;
|
|
56
|
+
}
|
|
57
|
+
var mapPropsVariants = (props, variantKeys, removeVariantProps = true) => {
|
|
58
|
+
if (!variantKeys) {
|
|
59
|
+
return [props, {}];
|
|
60
|
+
}
|
|
61
|
+
const picked = variantKeys.reduce((acc, key) => {
|
|
62
|
+
if (key in props) {
|
|
63
|
+
return { ...acc, [key]: props[key] };
|
|
64
|
+
} else {
|
|
65
|
+
return acc;
|
|
66
|
+
}
|
|
67
|
+
}, {});
|
|
68
|
+
if (removeVariantProps) {
|
|
69
|
+
const omitted = Object.keys(props).filter((key) => !variantKeys.includes(key)).reduce((acc, key) => ({ ...acc, [key]: props[key] }), {});
|
|
70
|
+
return [omitted, picked];
|
|
71
|
+
} else {
|
|
72
|
+
return [props, picked];
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function objectToDeps(obj) {
|
|
76
|
+
if (!obj || typeof obj !== "object") {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
return JSON.stringify(obj);
|
|
81
|
+
} catch {
|
|
82
|
+
return "";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
41
86
|
// src/ra.ts
|
|
42
87
|
function chain(...callbacks) {
|
|
43
88
|
return (...args) => {
|
|
@@ -65,9 +110,11 @@ var getInitials = (text) => {
|
|
|
65
110
|
};
|
|
66
111
|
export {
|
|
67
112
|
ariaAttr,
|
|
113
|
+
callAllHandlers,
|
|
68
114
|
chain,
|
|
69
115
|
clamp,
|
|
70
116
|
cn,
|
|
117
|
+
compact,
|
|
71
118
|
dataAttr,
|
|
72
119
|
getInitials,
|
|
73
120
|
getUniqueID,
|
|
@@ -76,5 +123,7 @@ export {
|
|
|
76
123
|
isEmptyArray,
|
|
77
124
|
isEmptyObject,
|
|
78
125
|
isObject,
|
|
126
|
+
mapPropsVariants,
|
|
127
|
+
objectToDeps,
|
|
79
128
|
safeText
|
|
80
129
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: utility file */
|
|
2
|
+
/** biome-ignore-all lint/complexity/noBannedTypes: utility file */
|
|
3
|
+
/** biome-ignore-all lint/performance/noAccumulatingSpread: utility file */
|
|
4
|
+
type Extractable = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
} | undefined;
|
|
7
|
+
declare function compact<T extends Record<any, any>>(object: T): {} & T;
|
|
8
|
+
declare const mapPropsVariants: <T extends Record<string, any>, K extends keyof T>(props: T, variantKeys?: K[], removeVariantProps?: boolean) => readonly [Omit<T, K> | T, Pick<T, K> | {}];
|
|
9
|
+
/**
|
|
10
|
+
* Converts an object into a JSON string. Returns an empty string if the object
|
|
11
|
+
* is not extractable or if a circular reference is detected during stringification.
|
|
12
|
+
*
|
|
13
|
+
* @param obj - The object to convert into a dependency string.
|
|
14
|
+
*
|
|
15
|
+
* @returns A JSON string representation of the object or an empty string if conversion fails.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* objectToDeps({ key: 'value' }); // returns '{"key":"value"}'
|
|
19
|
+
* objectToDeps(undefined); // returns ""
|
|
20
|
+
*/
|
|
21
|
+
declare function objectToDeps(obj: Extractable): string;
|
|
22
|
+
|
|
23
|
+
export { compact, mapPropsVariants, objectToDeps };
|
package/dist/object.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: utility file */
|
|
2
|
+
/** biome-ignore-all lint/complexity/noBannedTypes: utility file */
|
|
3
|
+
/** biome-ignore-all lint/performance/noAccumulatingSpread: utility file */
|
|
4
|
+
type Extractable = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
} | undefined;
|
|
7
|
+
declare function compact<T extends Record<any, any>>(object: T): {} & T;
|
|
8
|
+
declare const mapPropsVariants: <T extends Record<string, any>, K extends keyof T>(props: T, variantKeys?: K[], removeVariantProps?: boolean) => readonly [Omit<T, K> | T, Pick<T, K> | {}];
|
|
9
|
+
/**
|
|
10
|
+
* Converts an object into a JSON string. Returns an empty string if the object
|
|
11
|
+
* is not extractable or if a circular reference is detected during stringification.
|
|
12
|
+
*
|
|
13
|
+
* @param obj - The object to convert into a dependency string.
|
|
14
|
+
*
|
|
15
|
+
* @returns A JSON string representation of the object or an empty string if conversion fails.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* objectToDeps({ key: 'value' }); // returns '{"key":"value"}'
|
|
19
|
+
* objectToDeps(undefined); // returns ""
|
|
20
|
+
*/
|
|
21
|
+
declare function objectToDeps(obj: Extractable): string;
|
|
22
|
+
|
|
23
|
+
export { compact, mapPropsVariants, objectToDeps };
|
package/dist/object.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/object.ts
|
|
21
|
+
var object_exports = {};
|
|
22
|
+
__export(object_exports, {
|
|
23
|
+
compact: () => compact,
|
|
24
|
+
mapPropsVariants: () => mapPropsVariants,
|
|
25
|
+
objectToDeps: () => objectToDeps
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(object_exports);
|
|
28
|
+
function compact(object) {
|
|
29
|
+
const clone = Object.assign({}, object);
|
|
30
|
+
for (const key in clone) {
|
|
31
|
+
if (clone[key] === void 0) delete clone[key];
|
|
32
|
+
}
|
|
33
|
+
return clone;
|
|
34
|
+
}
|
|
35
|
+
var mapPropsVariants = (props, variantKeys, removeVariantProps = true) => {
|
|
36
|
+
if (!variantKeys) {
|
|
37
|
+
return [props, {}];
|
|
38
|
+
}
|
|
39
|
+
const picked = variantKeys.reduce((acc, key) => {
|
|
40
|
+
if (key in props) {
|
|
41
|
+
return { ...acc, [key]: props[key] };
|
|
42
|
+
} else {
|
|
43
|
+
return acc;
|
|
44
|
+
}
|
|
45
|
+
}, {});
|
|
46
|
+
if (removeVariantProps) {
|
|
47
|
+
const omitted = Object.keys(props).filter((key) => !variantKeys.includes(key)).reduce((acc, key) => ({ ...acc, [key]: props[key] }), {});
|
|
48
|
+
return [omitted, picked];
|
|
49
|
+
} else {
|
|
50
|
+
return [props, picked];
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function objectToDeps(obj) {
|
|
54
|
+
if (!obj || typeof obj !== "object") {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
return JSON.stringify(obj);
|
|
59
|
+
} catch {
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
compact,
|
|
66
|
+
mapPropsVariants,
|
|
67
|
+
objectToDeps
|
|
68
|
+
});
|
package/dist/object.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/object.ts
|
|
2
|
+
function compact(object) {
|
|
3
|
+
const clone = Object.assign({}, object);
|
|
4
|
+
for (const key in clone) {
|
|
5
|
+
if (clone[key] === void 0) delete clone[key];
|
|
6
|
+
}
|
|
7
|
+
return clone;
|
|
8
|
+
}
|
|
9
|
+
var mapPropsVariants = (props, variantKeys, removeVariantProps = true) => {
|
|
10
|
+
if (!variantKeys) {
|
|
11
|
+
return [props, {}];
|
|
12
|
+
}
|
|
13
|
+
const picked = variantKeys.reduce((acc, key) => {
|
|
14
|
+
if (key in props) {
|
|
15
|
+
return { ...acc, [key]: props[key] };
|
|
16
|
+
} else {
|
|
17
|
+
return acc;
|
|
18
|
+
}
|
|
19
|
+
}, {});
|
|
20
|
+
if (removeVariantProps) {
|
|
21
|
+
const omitted = Object.keys(props).filter((key) => !variantKeys.includes(key)).reduce((acc, key) => ({ ...acc, [key]: props[key] }), {});
|
|
22
|
+
return [omitted, picked];
|
|
23
|
+
} else {
|
|
24
|
+
return [props, picked];
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function objectToDeps(obj) {
|
|
28
|
+
if (!obj || typeof obj !== "object") {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
return JSON.stringify(obj);
|
|
33
|
+
} catch {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
compact,
|
|
39
|
+
mapPropsVariants,
|
|
40
|
+
objectToDeps
|
|
41
|
+
};
|