@yamada-ui/utils 0.1.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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/array.d.ts +3 -0
- package/dist/array.js +30 -0
- package/dist/array.mjs +6 -0
- package/dist/assertion.d.ts +16 -0
- package/dist/assertion.js +63 -0
- package/dist/assertion.mjs +28 -0
- package/dist/calc.d.ts +17 -0
- package/dist/calc.js +55 -0
- package/dist/calc.mjs +6 -0
- package/dist/chunk-A6J4FUU7.mjs +401 -0
- package/dist/chunk-BZAW2D6U.mjs +6 -0
- package/dist/chunk-FW7XS4NH.mjs +120 -0
- package/dist/chunk-IVGIIDMV.mjs +28 -0
- package/dist/chunk-PF7LRFIA.mjs +51 -0
- package/dist/chunk-PURW64JE.mjs +6 -0
- package/dist/chunk-R5OUKGQ5.mjs +31 -0
- package/dist/chunk-SLJ4M7XC.mjs +0 -0
- package/dist/chunk-VYMGBE25.mjs +39 -0
- package/dist/color.d.ts +19 -0
- package/dist/color.js +181 -0
- package/dist/color.mjs +34 -0
- package/dist/dom.d.ts +33 -0
- package/dist/dom.js +168 -0
- package/dist/dom.mjs +54 -0
- package/dist/event.d.ts +30 -0
- package/dist/event.js +83 -0
- package/dist/event.mjs +22 -0
- package/dist/function.d.ts +6 -0
- package/dist/function.js +50 -0
- package/dist/function.mjs +20 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +796 -0
- package/dist/index.mjs +221 -0
- package/dist/index.types.d.ts +14 -0
- package/dist/index.types.js +18 -0
- package/dist/index.types.mjs +1 -0
- package/dist/number.d.ts +8 -0
- package/dist/number.js +68 -0
- package/dist/number.mjs +16 -0
- package/dist/object.d.ts +18 -0
- package/dist/object.js +192 -0
- package/dist/object.mjs +40 -0
- package/dist/react.d.ts +44 -0
- package/dist/react.js +176 -0
- package/dist/react.mjs +46 -0
- package/dist/string.d.ts +3 -0
- package/dist/string.js +30 -0
- package/dist/string.mjs +6 -0
- package/package.json +66 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignAfter,
|
|
3
|
+
assignRef,
|
|
4
|
+
brightenColor,
|
|
5
|
+
createContext,
|
|
6
|
+
cx,
|
|
7
|
+
darkenColor,
|
|
8
|
+
filterObject,
|
|
9
|
+
filterUndefined,
|
|
10
|
+
findChildren,
|
|
11
|
+
flattenObject,
|
|
12
|
+
funcAll,
|
|
13
|
+
getColor,
|
|
14
|
+
getMemoizedObject,
|
|
15
|
+
getObject,
|
|
16
|
+
getValidChildren,
|
|
17
|
+
handlerAll,
|
|
18
|
+
includesChildren,
|
|
19
|
+
isDark,
|
|
20
|
+
isLight,
|
|
21
|
+
isRefObject,
|
|
22
|
+
isValidElement,
|
|
23
|
+
keysFormObject,
|
|
24
|
+
lightenColor,
|
|
25
|
+
memoizeObject,
|
|
26
|
+
merge,
|
|
27
|
+
mergeRefs,
|
|
28
|
+
noop,
|
|
29
|
+
objectFromEntries,
|
|
30
|
+
omitChildren,
|
|
31
|
+
omitObject,
|
|
32
|
+
pickChildren,
|
|
33
|
+
pickObject,
|
|
34
|
+
randomColor,
|
|
35
|
+
replaceObject,
|
|
36
|
+
runIfFunc,
|
|
37
|
+
shadeColor,
|
|
38
|
+
splitObject,
|
|
39
|
+
tintColor,
|
|
40
|
+
toneColor,
|
|
41
|
+
transparentizeColor,
|
|
42
|
+
useCallbackRef,
|
|
43
|
+
useIsMounted,
|
|
44
|
+
useMergeRefs,
|
|
45
|
+
useSafeLayoutEffect,
|
|
46
|
+
useUnmountEffect,
|
|
47
|
+
useUpdateEffect
|
|
48
|
+
} from "./chunk-A6J4FUU7.mjs";
|
|
49
|
+
import "./chunk-SLJ4M7XC.mjs";
|
|
50
|
+
import {
|
|
51
|
+
clampNumber,
|
|
52
|
+
countDecimal,
|
|
53
|
+
percentToValue,
|
|
54
|
+
roundNumberToStep,
|
|
55
|
+
toPrecision,
|
|
56
|
+
valueToPercent
|
|
57
|
+
} from "./chunk-VYMGBE25.mjs";
|
|
58
|
+
import {
|
|
59
|
+
escape
|
|
60
|
+
} from "./chunk-BZAW2D6U.mjs";
|
|
61
|
+
import {
|
|
62
|
+
filterEmpty
|
|
63
|
+
} from "./chunk-PURW64JE.mjs";
|
|
64
|
+
import {
|
|
65
|
+
cast,
|
|
66
|
+
isArray,
|
|
67
|
+
isEmpty,
|
|
68
|
+
isFunction,
|
|
69
|
+
isNotNumber,
|
|
70
|
+
isNull,
|
|
71
|
+
isNumber,
|
|
72
|
+
isNumeric,
|
|
73
|
+
isObject,
|
|
74
|
+
isString,
|
|
75
|
+
isUndefined,
|
|
76
|
+
isUnit
|
|
77
|
+
} from "./chunk-IVGIIDMV.mjs";
|
|
78
|
+
import {
|
|
79
|
+
calc
|
|
80
|
+
} from "./chunk-R5OUKGQ5.mjs";
|
|
81
|
+
import {
|
|
82
|
+
ariaAttr,
|
|
83
|
+
createdDom,
|
|
84
|
+
dataAttr,
|
|
85
|
+
getActiveElement,
|
|
86
|
+
getAllFocusable,
|
|
87
|
+
getEventRelatedTarget,
|
|
88
|
+
getOwnerDocument,
|
|
89
|
+
getOwnerWindow,
|
|
90
|
+
getPlatform,
|
|
91
|
+
hasNegativeTabIndex,
|
|
92
|
+
hasTabIndex,
|
|
93
|
+
isActiveElement,
|
|
94
|
+
isApple,
|
|
95
|
+
isContains,
|
|
96
|
+
isContentEditable,
|
|
97
|
+
isDisabled,
|
|
98
|
+
isElement,
|
|
99
|
+
isFocusable,
|
|
100
|
+
isHTMLElement,
|
|
101
|
+
isHidden,
|
|
102
|
+
isMac,
|
|
103
|
+
isSafari,
|
|
104
|
+
isTabbable,
|
|
105
|
+
platform,
|
|
106
|
+
vendor
|
|
107
|
+
} from "./chunk-FW7XS4NH.mjs";
|
|
108
|
+
import {
|
|
109
|
+
addDomEvent,
|
|
110
|
+
addPointerEvent,
|
|
111
|
+
getEventPoint,
|
|
112
|
+
getEventWindow,
|
|
113
|
+
isMouseEvent,
|
|
114
|
+
isMultiTouchEvent,
|
|
115
|
+
isTouchEvent,
|
|
116
|
+
pointFromMouse,
|
|
117
|
+
pointFromTouch
|
|
118
|
+
} from "./chunk-PF7LRFIA.mjs";
|
|
119
|
+
export {
|
|
120
|
+
addDomEvent,
|
|
121
|
+
addPointerEvent,
|
|
122
|
+
ariaAttr,
|
|
123
|
+
assignAfter,
|
|
124
|
+
assignRef,
|
|
125
|
+
brightenColor,
|
|
126
|
+
calc,
|
|
127
|
+
cast,
|
|
128
|
+
clampNumber,
|
|
129
|
+
countDecimal,
|
|
130
|
+
createContext,
|
|
131
|
+
createdDom,
|
|
132
|
+
cx,
|
|
133
|
+
darkenColor,
|
|
134
|
+
dataAttr,
|
|
135
|
+
escape,
|
|
136
|
+
filterEmpty,
|
|
137
|
+
filterObject,
|
|
138
|
+
filterUndefined,
|
|
139
|
+
findChildren,
|
|
140
|
+
flattenObject,
|
|
141
|
+
funcAll,
|
|
142
|
+
getActiveElement,
|
|
143
|
+
getAllFocusable,
|
|
144
|
+
getColor,
|
|
145
|
+
getEventPoint,
|
|
146
|
+
getEventRelatedTarget,
|
|
147
|
+
getEventWindow,
|
|
148
|
+
getMemoizedObject,
|
|
149
|
+
getObject,
|
|
150
|
+
getOwnerDocument,
|
|
151
|
+
getOwnerWindow,
|
|
152
|
+
getPlatform,
|
|
153
|
+
getValidChildren,
|
|
154
|
+
handlerAll,
|
|
155
|
+
hasNegativeTabIndex,
|
|
156
|
+
hasTabIndex,
|
|
157
|
+
includesChildren,
|
|
158
|
+
isActiveElement,
|
|
159
|
+
isApple,
|
|
160
|
+
isArray,
|
|
161
|
+
isContains,
|
|
162
|
+
isContentEditable,
|
|
163
|
+
isDark,
|
|
164
|
+
isDisabled,
|
|
165
|
+
isElement,
|
|
166
|
+
isEmpty,
|
|
167
|
+
isFocusable,
|
|
168
|
+
isFunction,
|
|
169
|
+
isHTMLElement,
|
|
170
|
+
isHidden,
|
|
171
|
+
isLight,
|
|
172
|
+
isMac,
|
|
173
|
+
isMouseEvent,
|
|
174
|
+
isMultiTouchEvent,
|
|
175
|
+
isNotNumber,
|
|
176
|
+
isNull,
|
|
177
|
+
isNumber,
|
|
178
|
+
isNumeric,
|
|
179
|
+
isObject,
|
|
180
|
+
isRefObject,
|
|
181
|
+
isSafari,
|
|
182
|
+
isString,
|
|
183
|
+
isTabbable,
|
|
184
|
+
isTouchEvent,
|
|
185
|
+
isUndefined,
|
|
186
|
+
isUnit,
|
|
187
|
+
isValidElement,
|
|
188
|
+
keysFormObject,
|
|
189
|
+
lightenColor,
|
|
190
|
+
memoizeObject,
|
|
191
|
+
merge,
|
|
192
|
+
mergeRefs,
|
|
193
|
+
noop,
|
|
194
|
+
objectFromEntries,
|
|
195
|
+
omitChildren,
|
|
196
|
+
omitObject,
|
|
197
|
+
percentToValue,
|
|
198
|
+
pickChildren,
|
|
199
|
+
pickObject,
|
|
200
|
+
platform,
|
|
201
|
+
pointFromMouse,
|
|
202
|
+
pointFromTouch,
|
|
203
|
+
randomColor,
|
|
204
|
+
replaceObject,
|
|
205
|
+
roundNumberToStep,
|
|
206
|
+
runIfFunc,
|
|
207
|
+
shadeColor,
|
|
208
|
+
splitObject,
|
|
209
|
+
tintColor,
|
|
210
|
+
toPrecision,
|
|
211
|
+
toneColor,
|
|
212
|
+
transparentizeColor,
|
|
213
|
+
useCallbackRef,
|
|
214
|
+
useIsMounted,
|
|
215
|
+
useMergeRefs,
|
|
216
|
+
useSafeLayoutEffect,
|
|
217
|
+
useUnmountEffect,
|
|
218
|
+
useUpdateEffect,
|
|
219
|
+
valueToPercent,
|
|
220
|
+
vendor
|
|
221
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
2
|
+
type PathImpl<K extends string | number | symbol, V> = K extends string | number ? V extends Primitive ? `${K}` : `${K}.${Path<V>}` : ``;
|
|
3
|
+
type Path<T> = {
|
|
4
|
+
[K in keyof T]-?: PathImpl<K, T[K]>;
|
|
5
|
+
}[keyof T];
|
|
6
|
+
type Dict<T = any> = Record<string, T>;
|
|
7
|
+
type StringLiteral = string & {};
|
|
8
|
+
type Union<T> = T | StringLiteral;
|
|
9
|
+
type Length = string | 0 | number;
|
|
10
|
+
type DynamicRecord<T> = {
|
|
11
|
+
[K in keyof T]-?: T[K] extends Primitive ? string | number : DynamicRecord<T[K]>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { Dict, DynamicRecord, Length, Path, StringLiteral, Union };
|
|
@@ -0,0 +1,18 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/index.types.ts
|
|
17
|
+
var index_types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(index_types_exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chunk-SLJ4M7XC.mjs";
|
package/dist/number.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const toPrecision: (n: number, precision?: number) => string;
|
|
2
|
+
declare const countDecimal: (n: number) => number;
|
|
3
|
+
declare const roundNumberToStep: (n: number, from: number, step: number) => string;
|
|
4
|
+
declare const valueToPercent: (n: number, min: number, max: number) => number;
|
|
5
|
+
declare const percentToValue: (n: number, min: number, max: number) => number;
|
|
6
|
+
declare const clampNumber: (n: number, min: number, max: number) => number;
|
|
7
|
+
|
|
8
|
+
export { clampNumber, countDecimal, percentToValue, roundNumberToStep, toPrecision, valueToPercent };
|
package/dist/number.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/number.ts
|
|
21
|
+
var number_exports = {};
|
|
22
|
+
__export(number_exports, {
|
|
23
|
+
clampNumber: () => clampNumber,
|
|
24
|
+
countDecimal: () => countDecimal,
|
|
25
|
+
percentToValue: () => percentToValue,
|
|
26
|
+
roundNumberToStep: () => roundNumberToStep,
|
|
27
|
+
toPrecision: () => toPrecision,
|
|
28
|
+
valueToPercent: () => valueToPercent
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(number_exports);
|
|
31
|
+
var toNumber = (n) => {
|
|
32
|
+
const num = parseFloat(n);
|
|
33
|
+
return typeof num !== "number" || Number.isNaN(num) ? 0 : num;
|
|
34
|
+
};
|
|
35
|
+
var toPrecision = (n, precision) => {
|
|
36
|
+
n = toNumber(n);
|
|
37
|
+
const scale = 10 ** (precision != null ? precision : 10);
|
|
38
|
+
n = Math.round(n * scale) / scale;
|
|
39
|
+
return precision ? n.toFixed(precision) : n.toString();
|
|
40
|
+
};
|
|
41
|
+
var countDecimal = (n) => {
|
|
42
|
+
if (!Number.isFinite(n))
|
|
43
|
+
return 0;
|
|
44
|
+
let e = 1;
|
|
45
|
+
let p = 0;
|
|
46
|
+
while (Math.round(n * e) / e !== n) {
|
|
47
|
+
e *= 10;
|
|
48
|
+
p += 1;
|
|
49
|
+
}
|
|
50
|
+
return p;
|
|
51
|
+
};
|
|
52
|
+
var roundNumberToStep = (n, from, step) => {
|
|
53
|
+
const nextValue = Math.round((n - from) / step) * step + from;
|
|
54
|
+
const precision = countDecimal(step);
|
|
55
|
+
return toPrecision(nextValue, precision);
|
|
56
|
+
};
|
|
57
|
+
var valueToPercent = (n, min, max) => (n - min) * 100 / (max - min);
|
|
58
|
+
var percentToValue = (n, min, max) => (max - min) * n + min;
|
|
59
|
+
var clampNumber = (n, min, max) => Math.min(Math.max(n, min), max);
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
clampNumber,
|
|
63
|
+
countDecimal,
|
|
64
|
+
percentToValue,
|
|
65
|
+
roundNumberToStep,
|
|
66
|
+
toPrecision,
|
|
67
|
+
valueToPercent
|
|
68
|
+
});
|
package/dist/number.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clampNumber,
|
|
3
|
+
countDecimal,
|
|
4
|
+
percentToValue,
|
|
5
|
+
roundNumberToStep,
|
|
6
|
+
toPrecision,
|
|
7
|
+
valueToPercent
|
|
8
|
+
} from "./chunk-VYMGBE25.mjs";
|
|
9
|
+
export {
|
|
10
|
+
clampNumber,
|
|
11
|
+
countDecimal,
|
|
12
|
+
percentToValue,
|
|
13
|
+
roundNumberToStep,
|
|
14
|
+
toPrecision,
|
|
15
|
+
valueToPercent
|
|
16
|
+
};
|
package/dist/object.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Dict } from './index.types.js';
|
|
2
|
+
|
|
3
|
+
declare const omitObject: <T extends Dict<any>, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
|
|
4
|
+
declare const pickObject: <T extends Dict<any>, K extends keyof T>(obj: T, keys: K[]) => { [P in K]: T[P]; };
|
|
5
|
+
declare const splitObject: <T extends Dict<any>, K extends keyof T>(obj: T, keys: K[]) => [{ [P in K]: T[P]; }, Omit<T, K>];
|
|
6
|
+
declare const filterObject: <T extends Dict<any>, K extends Dict<any>>(obj: T, func: (key: keyof T, value: T[keyof T], obj: T) => boolean) => K;
|
|
7
|
+
declare const filterUndefined: <T extends Dict<any>>(obj: T) => T;
|
|
8
|
+
declare const merge: <T extends Dict<any>>(target: any, source: any, overrideArray?: boolean) => T;
|
|
9
|
+
declare const flattenObject: <T extends Dict<any>>(obj: any, maxDepth?: number) => T;
|
|
10
|
+
declare const objectFromEntries: <T extends Dict<any>>(entries: any[][]) => T;
|
|
11
|
+
declare const keysFormObject: <T extends Dict<any>>(obj: T) => (keyof T)[];
|
|
12
|
+
declare const replaceObject: <T extends unknown>(objOrArray: T, callBack: (value: any) => any) => T;
|
|
13
|
+
declare const getObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
|
|
14
|
+
declare const memoizeObject: (func: typeof getObject) => (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
|
|
15
|
+
declare const getMemoizedObject: (obj: Dict, path: string | number, fallback?: any, i?: number) => any;
|
|
16
|
+
declare const assignAfter: (target: Record<string, any>, ...sources: any[]) => Record<string, unknown>;
|
|
17
|
+
|
|
18
|
+
export { assignAfter, filterObject, filterUndefined, flattenObject, getMemoizedObject, getObject, keysFormObject, memoizeObject, merge, objectFromEntries, omitObject, pickObject, replaceObject, splitObject };
|
package/dist/object.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
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
|
+
assignAfter: () => assignAfter,
|
|
24
|
+
filterObject: () => filterObject,
|
|
25
|
+
filterUndefined: () => filterUndefined,
|
|
26
|
+
flattenObject: () => flattenObject,
|
|
27
|
+
getMemoizedObject: () => getMemoizedObject,
|
|
28
|
+
getObject: () => getObject,
|
|
29
|
+
keysFormObject: () => keysFormObject,
|
|
30
|
+
memoizeObject: () => memoizeObject,
|
|
31
|
+
merge: () => merge,
|
|
32
|
+
objectFromEntries: () => objectFromEntries,
|
|
33
|
+
omitObject: () => omitObject,
|
|
34
|
+
pickObject: () => pickObject,
|
|
35
|
+
replaceObject: () => replaceObject,
|
|
36
|
+
splitObject: () => splitObject
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(object_exports);
|
|
39
|
+
|
|
40
|
+
// src/assertion.ts
|
|
41
|
+
var isObject = (value) => value !== null && (typeof value === "object" || typeof value === "function") && !Array.isArray(value);
|
|
42
|
+
var isArray = (value) => Array.isArray(value);
|
|
43
|
+
var isFunction = (value) => typeof value === "function";
|
|
44
|
+
|
|
45
|
+
// src/object.ts
|
|
46
|
+
var omitObject = (obj, keys) => {
|
|
47
|
+
const result = {};
|
|
48
|
+
Object.keys(obj).forEach((key) => {
|
|
49
|
+
if (keys.includes(key))
|
|
50
|
+
return;
|
|
51
|
+
result[key] = obj[key];
|
|
52
|
+
});
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
var pickObject = (obj, keys) => {
|
|
56
|
+
const result = {};
|
|
57
|
+
keys.forEach((key) => {
|
|
58
|
+
if (key in obj)
|
|
59
|
+
result[key] = obj[key];
|
|
60
|
+
});
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
var splitObject = (obj, keys) => {
|
|
64
|
+
const picked = {};
|
|
65
|
+
const omitted = {};
|
|
66
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
67
|
+
if (keys.includes(key)) {
|
|
68
|
+
picked[key] = value;
|
|
69
|
+
} else {
|
|
70
|
+
omitted[key] = value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return [picked, omitted];
|
|
74
|
+
};
|
|
75
|
+
var filterObject = (obj, func) => {
|
|
76
|
+
const result = {};
|
|
77
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
78
|
+
const shouldPass = func(key, value, obj);
|
|
79
|
+
if (shouldPass)
|
|
80
|
+
result[key] = value;
|
|
81
|
+
});
|
|
82
|
+
return result;
|
|
83
|
+
};
|
|
84
|
+
var filterUndefined = (obj) => filterObject(obj, (_, val) => val !== null && val !== void 0);
|
|
85
|
+
var merge = (target, source, overrideArray = false) => {
|
|
86
|
+
let result = Object.assign({}, target);
|
|
87
|
+
if (isObject(target) && isObject(source)) {
|
|
88
|
+
for (const [sourceKey, sourceValue] of Object.entries(source)) {
|
|
89
|
+
const targetValue = target[sourceKey];
|
|
90
|
+
if (overrideArray && Array.isArray(sourceValue) && Array.isArray(targetValue)) {
|
|
91
|
+
result[sourceKey] = targetValue.concat(...sourceValue);
|
|
92
|
+
} else if (!isFunction(sourceValue) && isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
|
|
93
|
+
result[sourceKey] = merge(targetValue, sourceValue, overrideArray);
|
|
94
|
+
} else {
|
|
95
|
+
Object.assign(result, { [sourceKey]: sourceValue });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
};
|
|
101
|
+
var flattenObject = (obj, maxDepth = Infinity) => {
|
|
102
|
+
if (!isObject(obj) && !isArray(obj) || !maxDepth)
|
|
103
|
+
return obj;
|
|
104
|
+
return Object.entries(obj).reduce((result, [key, value]) => {
|
|
105
|
+
if (isObject(value)) {
|
|
106
|
+
Object.entries(flattenObject(value, maxDepth - 1)).forEach(([childKey, childValue]) => {
|
|
107
|
+
result[`${key}.${childKey}`] = childValue;
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
result[key] = value;
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}, {});
|
|
114
|
+
};
|
|
115
|
+
var objectFromEntries = (entries) => entries.reduce((result, [key, value]) => {
|
|
116
|
+
result[key] = value;
|
|
117
|
+
return result;
|
|
118
|
+
}, {});
|
|
119
|
+
var keysFormObject = (obj) => Object.keys(obj);
|
|
120
|
+
var replaceObject = (objOrArray, callBack) => {
|
|
121
|
+
if (isArray(objOrArray)) {
|
|
122
|
+
return objOrArray.map(callBack);
|
|
123
|
+
} else if (isObject(objOrArray)) {
|
|
124
|
+
return Object.entries(objOrArray).reduce((obj, [key, value]) => {
|
|
125
|
+
obj[key] = callBack(value);
|
|
126
|
+
return obj;
|
|
127
|
+
}, {});
|
|
128
|
+
} else {
|
|
129
|
+
return callBack(objOrArray);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var getObject = (obj, path, fallback, i) => {
|
|
133
|
+
const k = typeof path === "string" ? path.split(".") : [path];
|
|
134
|
+
for (i = 0; i < k.length; i += 1) {
|
|
135
|
+
if (!obj)
|
|
136
|
+
break;
|
|
137
|
+
obj = obj[k[i]];
|
|
138
|
+
}
|
|
139
|
+
return obj === void 0 ? fallback : obj;
|
|
140
|
+
};
|
|
141
|
+
var memoizeObject = (func) => {
|
|
142
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
143
|
+
const memoizedFunc = (obj, path, fallback, i) => {
|
|
144
|
+
if (typeof obj === "undefined") {
|
|
145
|
+
return func(obj, path, fallback);
|
|
146
|
+
}
|
|
147
|
+
if (!cache.has(obj))
|
|
148
|
+
cache.set(obj, /* @__PURE__ */ new Map());
|
|
149
|
+
const map = cache.get(obj);
|
|
150
|
+
if (map.has(path))
|
|
151
|
+
return map.get(path);
|
|
152
|
+
const value = func(obj, path, fallback, i);
|
|
153
|
+
map.set(path, value);
|
|
154
|
+
return value;
|
|
155
|
+
};
|
|
156
|
+
return memoizedFunc;
|
|
157
|
+
};
|
|
158
|
+
var getMemoizedObject = memoizeObject(getObject);
|
|
159
|
+
var assignAfter = (target, ...sources) => {
|
|
160
|
+
if (target == null)
|
|
161
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
162
|
+
const result = { ...target };
|
|
163
|
+
for (const nextSource of sources) {
|
|
164
|
+
if (nextSource == null)
|
|
165
|
+
continue;
|
|
166
|
+
for (const nextKey in nextSource) {
|
|
167
|
+
if (!Object.prototype.hasOwnProperty.call(nextSource, nextKey))
|
|
168
|
+
continue;
|
|
169
|
+
if (nextKey in result)
|
|
170
|
+
delete result[nextKey];
|
|
171
|
+
result[nextKey] = nextSource[nextKey];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
};
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
assignAfter,
|
|
179
|
+
filterObject,
|
|
180
|
+
filterUndefined,
|
|
181
|
+
flattenObject,
|
|
182
|
+
getMemoizedObject,
|
|
183
|
+
getObject,
|
|
184
|
+
keysFormObject,
|
|
185
|
+
memoizeObject,
|
|
186
|
+
merge,
|
|
187
|
+
objectFromEntries,
|
|
188
|
+
omitObject,
|
|
189
|
+
pickObject,
|
|
190
|
+
replaceObject,
|
|
191
|
+
splitObject
|
|
192
|
+
});
|
package/dist/object.mjs
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignAfter,
|
|
3
|
+
filterObject,
|
|
4
|
+
filterUndefined,
|
|
5
|
+
flattenObject,
|
|
6
|
+
getMemoizedObject,
|
|
7
|
+
getObject,
|
|
8
|
+
keysFormObject,
|
|
9
|
+
memoizeObject,
|
|
10
|
+
merge,
|
|
11
|
+
objectFromEntries,
|
|
12
|
+
omitObject,
|
|
13
|
+
pickObject,
|
|
14
|
+
replaceObject,
|
|
15
|
+
splitObject
|
|
16
|
+
} from "./chunk-A6J4FUU7.mjs";
|
|
17
|
+
import "./chunk-SLJ4M7XC.mjs";
|
|
18
|
+
import "./chunk-VYMGBE25.mjs";
|
|
19
|
+
import "./chunk-BZAW2D6U.mjs";
|
|
20
|
+
import "./chunk-PURW64JE.mjs";
|
|
21
|
+
import "./chunk-IVGIIDMV.mjs";
|
|
22
|
+
import "./chunk-R5OUKGQ5.mjs";
|
|
23
|
+
import "./chunk-FW7XS4NH.mjs";
|
|
24
|
+
import "./chunk-PF7LRFIA.mjs";
|
|
25
|
+
export {
|
|
26
|
+
assignAfter,
|
|
27
|
+
filterObject,
|
|
28
|
+
filterUndefined,
|
|
29
|
+
flattenObject,
|
|
30
|
+
getMemoizedObject,
|
|
31
|
+
getObject,
|
|
32
|
+
keysFormObject,
|
|
33
|
+
memoizeObject,
|
|
34
|
+
merge,
|
|
35
|
+
objectFromEntries,
|
|
36
|
+
omitObject,
|
|
37
|
+
pickObject,
|
|
38
|
+
replaceObject,
|
|
39
|
+
splitObject
|
|
40
|
+
};
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
type DOMElement = Element & HTMLOrSVGElement;
|
|
4
|
+
type DataAttributes = {
|
|
5
|
+
[dataAttr: string]: any;
|
|
6
|
+
};
|
|
7
|
+
type DOMAttributes<Y = DOMElement> = React.AriaAttributes & React.DOMAttributes<Y> & DataAttributes & {
|
|
8
|
+
id?: string;
|
|
9
|
+
role?: React.AriaRole;
|
|
10
|
+
tabIndex?: number;
|
|
11
|
+
style?: React.CSSProperties;
|
|
12
|
+
};
|
|
13
|
+
type Merge<Y, M> = M extends Record<string, unknown> ? Y : Omit<Y, keyof M> & M;
|
|
14
|
+
type PropGetter<Y = Record<string, unknown>, M = DOMAttributes> = (props?: Merge<DOMAttributes, Y>, ref?: React.Ref<any>) => M & React.RefAttributes<any>;
|
|
15
|
+
type RequiredPropGetter<Y = Record<string, unknown>, M = DOMAttributes> = (props: Merge<DOMAttributes, Y>, ref?: React.Ref<any>) => M & React.RefAttributes<any>;
|
|
16
|
+
type MaybeRenderProp<Y> = React.ReactNode | ((props: Y) => React.ReactNode);
|
|
17
|
+
type Options = {
|
|
18
|
+
strict?: boolean;
|
|
19
|
+
errorMessage?: string;
|
|
20
|
+
name?: string;
|
|
21
|
+
};
|
|
22
|
+
type CreateContextReturn<T> = [React.Provider<T>, () => T, React.Context<T>];
|
|
23
|
+
declare const createContext: <ContextType extends unknown = any>({ strict, errorMessage, name, }?: Options) => CreateContextReturn<ContextType>;
|
|
24
|
+
declare const useSafeLayoutEffect: typeof React.useLayoutEffect;
|
|
25
|
+
declare const useUnmountEffect: (callback: () => void) => void;
|
|
26
|
+
declare const useIsMounted: () => React.MutableRefObject<boolean>;
|
|
27
|
+
declare const getValidChildren: (children: React.ReactNode) => React.ReactElement[];
|
|
28
|
+
declare const isValidElement: (child: any) => child is React.ReactNode;
|
|
29
|
+
declare const findChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => [React.ReactElement | undefined, ...React.ReactElement[]];
|
|
30
|
+
declare const includesChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => boolean;
|
|
31
|
+
declare const omitChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => React.ReactElement[];
|
|
32
|
+
declare const pickChildren: (children: React.ReactElement<any, string | React.JSXElementConstructor<any>>[], ...types: React.JSXElementConstructor<any>[]) => React.ReactElement[];
|
|
33
|
+
declare const cx: (...classNames: (string | undefined)[]) => string;
|
|
34
|
+
type ReactRef<T> = React.Ref<T> | React.MutableRefObject<T>;
|
|
35
|
+
declare const isRefObject: (val: any) => val is {
|
|
36
|
+
current: any;
|
|
37
|
+
};
|
|
38
|
+
declare const assignRef: <T extends unknown = any>(ref: ReactRef<T> | undefined, value: T) => void;
|
|
39
|
+
declare const mergeRefs: <T extends unknown = any>(...refs: (ReactRef<T> | undefined)[]) => (node: T | null) => void;
|
|
40
|
+
declare const useMergeRefs: <T extends unknown = any>(...refs: (ReactRef<T> | undefined)[]) => (node: T | null) => void;
|
|
41
|
+
declare const useCallbackRef: <T extends (...args: any[]) => any>(callback: T | undefined, deps?: React.DependencyList) => T;
|
|
42
|
+
declare const useUpdateEffect: (callback: React.EffectCallback, deps: React.DependencyList) => void;
|
|
43
|
+
|
|
44
|
+
export { DOMAttributes, MaybeRenderProp, PropGetter, RequiredPropGetter, assignRef, createContext, cx, findChildren, getValidChildren, includesChildren, isRefObject, isValidElement, mergeRefs, omitChildren, pickChildren, useCallbackRef, useIsMounted, useMergeRefs, useSafeLayoutEffect, useUnmountEffect, useUpdateEffect };
|