@yh-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/dist/index.mjs ADDED
@@ -0,0 +1,329 @@
1
+ const isString = (val) => typeof val === "string";
2
+ const isNumber = (val) => typeof val === "number";
3
+ const isBoolean = (val) => typeof val === "boolean";
4
+ const isFunction = (val) => typeof val === "function";
5
+ const isObject = (val) => val !== null && typeof val === "object";
6
+ const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
7
+ const isArray = Array.isArray;
8
+ const isUndefined = (val) => val === void 0;
9
+ const isNil = (val) => val == null;
10
+ const isEmpty = (val) => {
11
+ if (isNil(val)) return true;
12
+ if (isArray(val)) return val.length === 0;
13
+ if (isString(val)) return val.trim().length === 0;
14
+ if (isObject(val)) return Object.keys(val).length === 0;
15
+ return false;
16
+ };
17
+ const isNumeric = (val) => !isNil(val) && !isNaN(parseFloat(String(val))) && isFinite(Number(val));
18
+
19
+ const isClient = typeof window !== "undefined";
20
+ const isServer = !isClient;
21
+ const getStyle = (element, styleName) => {
22
+ if (!isClient || !element || !styleName) return "";
23
+ try {
24
+ const style = element.style[styleName];
25
+ if (style) return style;
26
+ const computed = document.defaultView?.getComputedStyle(element, "");
27
+ return computed ? computed[styleName] : "";
28
+ } catch {
29
+ return element.style[styleName];
30
+ }
31
+ };
32
+ const setStyle = (element, styleName, value) => {
33
+ if (!element || !styleName) return;
34
+ if (typeof styleName === "object") {
35
+ Object.entries(styleName).forEach(([key, val]) => {
36
+ setStyle(element, key, val);
37
+ });
38
+ } else {
39
+ element.style[styleName] = value ?? "";
40
+ }
41
+ };
42
+ const hasClass = (el, cls) => {
43
+ if (!el || !cls) return false;
44
+ if (cls.includes(" ")) throw new Error("className should not contain space.");
45
+ return el.classList.contains(cls);
46
+ };
47
+ const addClass = (el, cls) => {
48
+ if (!el || !cls.trim()) return;
49
+ el.classList.add(...cls.split(" ").filter(Boolean));
50
+ };
51
+ const removeClass = (el, cls) => {
52
+ if (!el || !cls.trim()) return;
53
+ el.classList.remove(...cls.split(" ").filter(Boolean));
54
+ };
55
+ const toggleClass = (el, cls, force) => {
56
+ if (!el || !cls.trim()) return;
57
+ el.classList.toggle(cls, force);
58
+ };
59
+ const getScrollContainer = (el, isVertical) => {
60
+ if (!isClient) return void 0;
61
+ let parent = el;
62
+ while (parent) {
63
+ if ([document.documentElement, document.body].includes(parent)) {
64
+ return window;
65
+ }
66
+ const overflow = isVertical ? getStyle(parent, "overflowY") : getStyle(parent, "overflow");
67
+ if (/(scroll|auto)/.test(overflow)) {
68
+ return parent;
69
+ }
70
+ parent = parent.parentNode;
71
+ }
72
+ return void 0;
73
+ };
74
+ const isInViewport = (el) => {
75
+ if (!isClient || !el) return false;
76
+ const rect = el.getBoundingClientRect();
77
+ return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
78
+ };
79
+
80
+ const withInstall = (main, extra) => {
81
+ main.install = (app) => {
82
+ for (const comp of [main, ...Object.values(extra ?? {})]) {
83
+ const name = comp.name || comp.__name;
84
+ if (name) {
85
+ app.component(name, comp);
86
+ }
87
+ }
88
+ };
89
+ if (extra) {
90
+ for (const [key, comp] of Object.entries(extra)) {
91
+ main[key] = comp;
92
+ }
93
+ }
94
+ return main;
95
+ };
96
+ const withNoopInstall = (component) => {
97
+ component.install = () => {
98
+ };
99
+ return component;
100
+ };
101
+ const withInstallFunction = (fn, name) => {
102
+ const func = fn;
103
+ func.install = (app) => {
104
+ app.config.globalProperties[name] = fn;
105
+ };
106
+ return func;
107
+ };
108
+ const withInstallDirective = (directive, name) => {
109
+ const dir = directive;
110
+ dir.install = (app) => {
111
+ app.directive(name, dir);
112
+ };
113
+ return dir;
114
+ };
115
+ const withInstallAll = (components, directives) => {
116
+ return {
117
+ install(app) {
118
+ components.forEach((component) => {
119
+ const name = component.name || component.__name;
120
+ if (name) {
121
+ app.component(name, component);
122
+ }
123
+ });
124
+ if (directives) {
125
+ Object.entries(directives).forEach(([name, directive]) => {
126
+ app.directive(name, directive);
127
+ });
128
+ }
129
+ }
130
+ };
131
+ };
132
+
133
+ let idCounter = 0;
134
+ const generateId = (prefix = "yh") => {
135
+ return `${prefix}-${Date.now()}-${++idCounter}`;
136
+ };
137
+ const debounce = (fn, delay) => {
138
+ let timer = null;
139
+ const debounced = (...args) => {
140
+ if (timer) clearTimeout(timer);
141
+ timer = setTimeout(() => {
142
+ fn(...args);
143
+ timer = null;
144
+ }, delay);
145
+ };
146
+ debounced.cancel = () => {
147
+ if (timer) {
148
+ clearTimeout(timer);
149
+ timer = null;
150
+ }
151
+ };
152
+ return debounced;
153
+ };
154
+ const throttle = (fn, delay) => {
155
+ let lastTime = 0;
156
+ let timer = null;
157
+ const throttled = (...args) => {
158
+ const now = Date.now();
159
+ const remaining = delay - (now - lastTime);
160
+ if (remaining <= 0) {
161
+ if (timer) {
162
+ clearTimeout(timer);
163
+ timer = null;
164
+ }
165
+ fn(...args);
166
+ lastTime = now;
167
+ } else if (!timer) {
168
+ timer = setTimeout(() => {
169
+ fn(...args);
170
+ lastTime = Date.now();
171
+ timer = null;
172
+ }, remaining);
173
+ }
174
+ };
175
+ throttled.cancel = () => {
176
+ if (timer) {
177
+ clearTimeout(timer);
178
+ timer = null;
179
+ }
180
+ lastTime = 0;
181
+ };
182
+ return throttled;
183
+ };
184
+ const deepClone = (obj) => {
185
+ if (obj === null || typeof obj !== "object") return obj;
186
+ if (obj instanceof Date) return new Date(obj.getTime());
187
+ if (obj instanceof Array) {
188
+ return obj.map((item) => deepClone(item));
189
+ }
190
+ if (obj instanceof Object) {
191
+ const copy = {};
192
+ Object.keys(obj).forEach((key) => {
193
+ copy[key] = deepClone(obj[key]);
194
+ });
195
+ return copy;
196
+ }
197
+ return obj;
198
+ };
199
+ const deepMerge = (target, ...sources) => {
200
+ if (!sources.length) return target;
201
+ const source = sources.shift();
202
+ if (source === void 0) return target;
203
+ for (const key in source) {
204
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
205
+ const targetValue = target[key];
206
+ const sourceValue = source[key];
207
+ if (typeof targetValue === "object" && targetValue !== null && typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(targetValue) && !Array.isArray(sourceValue)) {
208
+ target[key] = deepMerge(
209
+ { ...targetValue },
210
+ sourceValue
211
+ );
212
+ } else {
213
+ target[key] = sourceValue;
214
+ }
215
+ }
216
+ }
217
+ return deepMerge(target, ...sources);
218
+ };
219
+ const toArray = (val) => {
220
+ return Array.isArray(val) ? val : [val];
221
+ };
222
+ const capitalize = (str) => {
223
+ return str.charAt(0).toUpperCase() + str.slice(1);
224
+ };
225
+ const kebabCase = (str) => {
226
+ return str.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
227
+ };
228
+ const camelCase = (str) => {
229
+ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
230
+ };
231
+ const sleep = (ms) => {
232
+ return new Promise((resolve) => setTimeout(resolve, ms));
233
+ };
234
+ const get = (obj, path, defaultValue) => {
235
+ const result = path.split(".").reduce((res, key) => {
236
+ if (res !== null && res !== void 0 && typeof res === "object") {
237
+ return res[key];
238
+ }
239
+ return void 0;
240
+ }, obj);
241
+ return result === void 0 ? defaultValue : result;
242
+ };
243
+ const set = (obj, path, value) => {
244
+ if (Object(obj) !== obj) return obj;
245
+ const keys = path.split(".");
246
+ const lastKey = keys.pop();
247
+ const node = keys.reduce(
248
+ (res, key) => {
249
+ if (res[key] === void 0) res[key] = {};
250
+ return res[key];
251
+ },
252
+ obj
253
+ );
254
+ node[lastKey] = value;
255
+ return obj;
256
+ };
257
+ const retry = async (fn, retries = 3, delay = 1e3) => {
258
+ try {
259
+ return await fn();
260
+ } catch (error) {
261
+ if (retries > 0) {
262
+ await sleep(delay);
263
+ return retry(fn, retries - 1, delay);
264
+ }
265
+ throw error;
266
+ }
267
+ };
268
+
269
+ const addUnit = (value, unit = "px") => {
270
+ if (value === void 0 || value === null || value === "") return void 0;
271
+ if (isNumeric(value)) {
272
+ return `${value}${unit}`;
273
+ }
274
+ return String(value);
275
+ };
276
+ const removeUnit = (value) => {
277
+ return parseFloat(value) || 0;
278
+ };
279
+ const hexToRgb = (hex) => {
280
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
281
+ return result ? {
282
+ r: parseInt(result[1], 16),
283
+ g: parseInt(result[2], 16),
284
+ b: parseInt(result[3], 16)
285
+ } : null;
286
+ };
287
+ const rgbToHex = (r, g, b) => {
288
+ const toHex = (c) => {
289
+ const hex = c.toString(16);
290
+ return hex.length === 1 ? "0" + hex : hex;
291
+ };
292
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
293
+ };
294
+ const adjustColorBrightness = (color, amount) => {
295
+ const rgb = hexToRgb(color);
296
+ if (!rgb) return color;
297
+ const adjust = (value) => {
298
+ const newValue = value + amount;
299
+ return Math.max(0, Math.min(255, newValue));
300
+ };
301
+ return rgbToHex(adjust(rgb.r), adjust(rgb.g), adjust(rgb.b));
302
+ };
303
+ const generateColorPalette = (baseColor, levels = [1, 2, 3, 4, 5, 6, 7, 8, 9]) => {
304
+ const palette = {};
305
+ const rgb = hexToRgb(baseColor);
306
+ if (!rgb) return palette;
307
+ levels.forEach((level) => {
308
+ const factor = (10 - level) / 10;
309
+ palette[level] = rgbToHex(
310
+ Math.round(rgb.r + (255 - rgb.r) * factor),
311
+ Math.round(rgb.g + (255 - rgb.g) * factor),
312
+ Math.round(rgb.b + (255 - rgb.b) * factor)
313
+ );
314
+ });
315
+ return palette;
316
+ };
317
+ const setCssVar = (name, value, element = document.documentElement) => {
318
+ element.style.setProperty(name, value);
319
+ };
320
+ const getCssVar = (name, element = document.documentElement) => {
321
+ return getComputedStyle(element).getPropertyValue(name).trim();
322
+ };
323
+ const setCssVars = (vars, element = document.documentElement) => {
324
+ Object.entries(vars).forEach(([name, value]) => {
325
+ setCssVar(name, value, element);
326
+ });
327
+ };
328
+
329
+ export { addClass, addUnit, adjustColorBrightness, camelCase, capitalize, debounce, deepClone, deepMerge, generateColorPalette, generateId, get, getCssVar, getScrollContainer, getStyle, hasClass, hexToRgb, isArray, isBoolean, isClient, isEmpty, isFunction, isInViewport, isNil, isNumber, isNumeric, isObject, isPromise, isServer, isString, isUndefined, kebabCase, removeClass, removeUnit, retry, rgbToHex, set, setCssVar, setCssVars, setStyle, sleep, throttle, toArray, toggleClass, withInstall, withInstallAll, withInstallDirective, withInstallFunction, withNoopInstall };
package/dist/style.cjs ADDED
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setCssVars = exports.setCssVar = exports.rgbToHex = exports.removeUnit = exports.hexToRgb = exports.getCssVar = exports.generateColorPalette = exports.adjustColorBrightness = exports.addUnit = void 0;
7
+ var _types = require("./types.cjs");
8
+ const addUnit = (value, unit = "px") => {
9
+ if (value === void 0 || value === null || value === "") return void 0;
10
+ if ((0, _types.isNumeric)(value)) {
11
+ return `${value}${unit}`;
12
+ }
13
+ return String(value);
14
+ };
15
+ exports.addUnit = addUnit;
16
+ const removeUnit = value => {
17
+ return parseFloat(value) || 0;
18
+ };
19
+ exports.removeUnit = removeUnit;
20
+ const hexToRgb = hex => {
21
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
22
+ return result ? {
23
+ r: parseInt(result[1], 16),
24
+ g: parseInt(result[2], 16),
25
+ b: parseInt(result[3], 16)
26
+ } : null;
27
+ };
28
+ exports.hexToRgb = hexToRgb;
29
+ const rgbToHex = (r, g, b) => {
30
+ const toHex = c => {
31
+ const hex = c.toString(16);
32
+ return hex.length === 1 ? "0" + hex : hex;
33
+ };
34
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
35
+ };
36
+ exports.rgbToHex = rgbToHex;
37
+ const adjustColorBrightness = (color, amount) => {
38
+ const rgb = hexToRgb(color);
39
+ if (!rgb) return color;
40
+ const adjust = value => {
41
+ const newValue = value + amount;
42
+ return Math.max(0, Math.min(255, newValue));
43
+ };
44
+ return rgbToHex(adjust(rgb.r), adjust(rgb.g), adjust(rgb.b));
45
+ };
46
+ exports.adjustColorBrightness = adjustColorBrightness;
47
+ const generateColorPalette = (baseColor, levels = [1, 2, 3, 4, 5, 6, 7, 8, 9]) => {
48
+ const palette = {};
49
+ const rgb = hexToRgb(baseColor);
50
+ if (!rgb) return palette;
51
+ levels.forEach(level => {
52
+ const factor = (10 - level) / 10;
53
+ palette[level] = rgbToHex(Math.round(rgb.r + (255 - rgb.r) * factor), Math.round(rgb.g + (255 - rgb.g) * factor), Math.round(rgb.b + (255 - rgb.b) * factor));
54
+ });
55
+ return palette;
56
+ };
57
+ exports.generateColorPalette = generateColorPalette;
58
+ const setCssVar = (name, value, element = document.documentElement) => {
59
+ element.style.setProperty(name, value);
60
+ };
61
+ exports.setCssVar = setCssVar;
62
+ const getCssVar = (name, element = document.documentElement) => {
63
+ return getComputedStyle(element).getPropertyValue(name).trim();
64
+ };
65
+ exports.getCssVar = getCssVar;
66
+ const setCssVars = (vars, element = document.documentElement) => {
67
+ Object.entries(vars).forEach(([name, value]) => {
68
+ setCssVar(name, value, element);
69
+ });
70
+ };
71
+ exports.setCssVars = setCssVars;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 添加单位
3
+ */
4
+ export declare const addUnit: (value?: string | number, unit?: string) => string | undefined;
5
+ /**
6
+ * 移除单位,返回数值
7
+ */
8
+ export declare const removeUnit: (value: string) => number;
9
+ /**
10
+ * 将十六进制颜色转换为 RGB
11
+ */
12
+ export declare const hexToRgb: (hex: string) => {
13
+ r: number;
14
+ g: number;
15
+ b: number;
16
+ } | null;
17
+ /**
18
+ * 将 RGB 转换为十六进制颜色
19
+ */
20
+ export declare const rgbToHex: (r: number, g: number, b: number) => string;
21
+ /**
22
+ * 调整颜色亮度
23
+ */
24
+ export declare const adjustColorBrightness: (color: string, amount: number) => string;
25
+ /**
26
+ * 生成颜色的色阶
27
+ */
28
+ export declare const generateColorPalette: (baseColor: string, levels?: number[]) => Record<number, string>;
29
+ /**
30
+ * 设置 CSS 变量
31
+ */
32
+ export declare const setCssVar: (name: string, value: string, element?: HTMLElement) => void;
33
+ /**
34
+ * 获取 CSS 变量
35
+ */
36
+ export declare const getCssVar: (name: string, element?: HTMLElement) => string;
37
+ /**
38
+ * 批量设置 CSS 变量
39
+ */
40
+ export declare const setCssVars: (vars: Record<string, string>, element?: HTMLElement) => void;
package/dist/style.mjs ADDED
@@ -0,0 +1,60 @@
1
+ import { isNumeric } from "./types.mjs";
2
+ export const addUnit = (value, unit = "px") => {
3
+ if (value === void 0 || value === null || value === "") return void 0;
4
+ if (isNumeric(value)) {
5
+ return `${value}${unit}`;
6
+ }
7
+ return String(value);
8
+ };
9
+ export const removeUnit = (value) => {
10
+ return parseFloat(value) || 0;
11
+ };
12
+ export const hexToRgb = (hex) => {
13
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
14
+ return result ? {
15
+ r: parseInt(result[1], 16),
16
+ g: parseInt(result[2], 16),
17
+ b: parseInt(result[3], 16)
18
+ } : null;
19
+ };
20
+ export const rgbToHex = (r, g, b) => {
21
+ const toHex = (c) => {
22
+ const hex = c.toString(16);
23
+ return hex.length === 1 ? "0" + hex : hex;
24
+ };
25
+ return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
26
+ };
27
+ export const adjustColorBrightness = (color, amount) => {
28
+ const rgb = hexToRgb(color);
29
+ if (!rgb) return color;
30
+ const adjust = (value) => {
31
+ const newValue = value + amount;
32
+ return Math.max(0, Math.min(255, newValue));
33
+ };
34
+ return rgbToHex(adjust(rgb.r), adjust(rgb.g), adjust(rgb.b));
35
+ };
36
+ export const generateColorPalette = (baseColor, levels = [1, 2, 3, 4, 5, 6, 7, 8, 9]) => {
37
+ const palette = {};
38
+ const rgb = hexToRgb(baseColor);
39
+ if (!rgb) return palette;
40
+ levels.forEach((level) => {
41
+ const factor = (10 - level) / 10;
42
+ palette[level] = rgbToHex(
43
+ Math.round(rgb.r + (255 - rgb.r) * factor),
44
+ Math.round(rgb.g + (255 - rgb.g) * factor),
45
+ Math.round(rgb.b + (255 - rgb.b) * factor)
46
+ );
47
+ });
48
+ return palette;
49
+ };
50
+ export const setCssVar = (name, value, element = document.documentElement) => {
51
+ element.style.setProperty(name, value);
52
+ };
53
+ export const getCssVar = (name, element = document.documentElement) => {
54
+ return getComputedStyle(element).getPropertyValue(name).trim();
55
+ };
56
+ export const setCssVars = (vars, element = document.documentElement) => {
57
+ Object.entries(vars).forEach(([name, value]) => {
58
+ setCssVar(name, value, element);
59
+ });
60
+ };
package/dist/types.cjs ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isUndefined = exports.isString = exports.isPromise = exports.isObject = exports.isNumeric = exports.isNumber = exports.isNil = exports.isFunction = exports.isEmpty = exports.isBoolean = exports.isArray = void 0;
7
+ const isString = val => typeof val === "string";
8
+ exports.isString = isString;
9
+ const isNumber = val => typeof val === "number";
10
+ exports.isNumber = isNumber;
11
+ const isBoolean = val => typeof val === "boolean";
12
+ exports.isBoolean = isBoolean;
13
+ const isFunction = val => typeof val === "function";
14
+ exports.isFunction = isFunction;
15
+ const isObject = val => val !== null && typeof val === "object";
16
+ exports.isObject = isObject;
17
+ const isPromise = val => isObject(val) && isFunction(val.then) && isFunction(val.catch);
18
+ exports.isPromise = isPromise;
19
+ const isArray = exports.isArray = Array.isArray;
20
+ const isUndefined = val => val === void 0;
21
+ exports.isUndefined = isUndefined;
22
+ const isNil = val => val == null;
23
+ exports.isNil = isNil;
24
+ const isEmpty = val => {
25
+ if (isNil(val)) return true;
26
+ if (isArray(val)) return val.length === 0;
27
+ if (isString(val)) return val.trim().length === 0;
28
+ if (isObject(val)) return Object.keys(val).length === 0;
29
+ return false;
30
+ };
31
+ exports.isEmpty = isEmpty;
32
+ const isNumeric = val => !isNil(val) && !isNaN(parseFloat(String(val))) && isFinite(Number(val));
33
+ exports.isNumeric = isNumeric;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Type utilities
3
+ * @description 基础类型工具库,彻底移除 any,支持更严谨的类型推断
4
+ */
5
+ import type { App, Plugin } from 'vue';
6
+ /**
7
+ * 可空类型
8
+ */
9
+ export type Nullable<T> = T | null;
10
+ /**
11
+ * 可异步类型
12
+ */
13
+ export type Awaitable<T> = T | Promise<T>;
14
+ /**
15
+ * 数组或单值类型
16
+ */
17
+ export type Arrayable<T> = T | T[];
18
+ /**
19
+ * 通用对象类型
20
+ */
21
+ export type Recordable<T = unknown> = Record<string, T>;
22
+ /**
23
+ * 组件尺寸标准
24
+ */
25
+ export type ComponentSize = 'large' | 'default' | 'small';
26
+ /**
27
+ * Vue 插件类型(带安装器)
28
+ */
29
+ export type SFCWithInstall<T> = T & Plugin & {
30
+ install: (app: App, options?: Record<string, unknown>) => void;
31
+ };
32
+ /**
33
+ * 类型判断工具函数
34
+ */
35
+ export declare const isString: (val: unknown) => val is string;
36
+ export declare const isNumber: (val: unknown) => val is number;
37
+ export declare const isBoolean: (val: unknown) => val is boolean;
38
+ export declare const isFunction: (val: unknown) => val is (...args: unknown[]) => unknown;
39
+ export declare const isObject: (val: unknown) => val is Record<string, unknown>;
40
+ export declare const isPromise: <T = unknown>(val: unknown) => val is Promise<T>;
41
+ export declare const isArray: (arg: any) => arg is any[];
42
+ export declare const isUndefined: (val: unknown) => val is undefined;
43
+ export declare const isNil: (val: unknown) => val is null | undefined;
44
+ /**
45
+ * 判断是否为空值(null, undefined, '', [], {})
46
+ */
47
+ export declare const isEmpty: (val: unknown) => boolean;
48
+ /**
49
+ * 判断是否为有效的数字字符串
50
+ */
51
+ export declare const isNumeric: (val: unknown) => val is string | number;
package/dist/types.mjs ADDED
@@ -0,0 +1,17 @@
1
+ export const isString = (val) => typeof val === "string";
2
+ export const isNumber = (val) => typeof val === "number";
3
+ export const isBoolean = (val) => typeof val === "boolean";
4
+ export const isFunction = (val) => typeof val === "function";
5
+ export const isObject = (val) => val !== null && typeof val === "object";
6
+ export const isPromise = (val) => isObject(val) && isFunction(val.then) && isFunction(val.catch);
7
+ export const isArray = Array.isArray;
8
+ export const isUndefined = (val) => val === void 0;
9
+ export const isNil = (val) => val == null;
10
+ export const isEmpty = (val) => {
11
+ if (isNil(val)) return true;
12
+ if (isArray(val)) return val.length === 0;
13
+ if (isString(val)) return val.trim().length === 0;
14
+ if (isObject(val)) return Object.keys(val).length === 0;
15
+ return false;
16
+ };
17
+ export const isNumeric = (val) => !isNil(val) && !isNaN(parseFloat(String(val))) && isFinite(Number(val));
package/dist/vue.cjs ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.withNoopInstall = exports.withInstallFunction = exports.withInstallDirective = exports.withInstallAll = exports.withInstall = void 0;
7
+ const withInstall = (main, extra) => {
8
+ ;
9
+ main.install = app => {
10
+ for (const comp of [main, ...Object.values(extra ?? {})]) {
11
+ const name = comp.name || comp.__name;
12
+ if (name) {
13
+ app.component(name, comp);
14
+ }
15
+ }
16
+ };
17
+ if (extra) {
18
+ for (const [key, comp] of Object.entries(extra)) {
19
+ ;
20
+ main[key] = comp;
21
+ }
22
+ }
23
+ return main;
24
+ };
25
+ exports.withInstall = withInstall;
26
+ const withNoopInstall = component => {
27
+ ;
28
+ component.install = () => {};
29
+ return component;
30
+ };
31
+ exports.withNoopInstall = withNoopInstall;
32
+ const withInstallFunction = (fn, name) => {
33
+ const func = fn;
34
+ func.install = app => {
35
+ app.config.globalProperties[name] = fn;
36
+ };
37
+ return func;
38
+ };
39
+ exports.withInstallFunction = withInstallFunction;
40
+ const withInstallDirective = (directive, name) => {
41
+ const dir = directive;
42
+ dir.install = app => {
43
+ app.directive(name, dir);
44
+ };
45
+ return dir;
46
+ };
47
+ exports.withInstallDirective = withInstallDirective;
48
+ const withInstallAll = (components, directives) => {
49
+ return {
50
+ install(app) {
51
+ components.forEach(component => {
52
+ const name = component.name || component.__name;
53
+ if (name) {
54
+ app.component(name, component);
55
+ }
56
+ });
57
+ if (directives) {
58
+ Object.entries(directives).forEach(([name, directive]) => {
59
+ app.directive(name, directive);
60
+ });
61
+ }
62
+ }
63
+ };
64
+ };
65
+ exports.withInstallAll = withInstallAll;