@sybz-components/utils 0.0.5 → 0.0.6
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/base.cjs +33 -14
- package/dist/base.d.cts +555 -1
- package/dist/base.d.mts +555 -1
- package/dist/base.d.ts +555 -1
- package/dist/base.mjs +6 -60
- package/dist/day.cjs +38 -13
- package/dist/day.d.cts +81 -1
- package/dist/day.d.mts +81 -1
- package/dist/day.d.ts +81 -1
- package/dist/day.mjs +28 -21
- package/dist/format.cjs +17 -14
- package/dist/format.d.cts +208 -1
- package/dist/format.d.mts +208 -1
- package/dist/format.d.ts +208 -1
- package/dist/format.mjs +6 -27
- package/dist/index.cjs +75 -14
- package/dist/index.d.cts +10 -1
- package/dist/index.d.mts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.mjs +11 -101
- package/dist/is.cjs +63 -13
- package/dist/is.d.cts +248 -1
- package/dist/is.d.mts +248 -1
- package/dist/is.d.ts +248 -1
- package/dist/is.mjs +41 -38
- package/dist/shared/utils.DrwfWQ1C.cjs +957 -0
- package/dist/shared/utils.SMYVKGgi.mjs +923 -0
- package/dist/test.cjs +5 -14
- package/dist/test.d.cts +14 -1
- package/dist/test.d.mts +14 -1
- package/dist/test.d.ts +14 -1
- package/dist/test.mjs +4 -17
- package/dist/ws.cjs +171 -12
- package/dist/ws.d.cts +165 -1
- package/dist/ws.d.mts +165 -1
- package/dist/ws.d.ts +165 -1
- package/dist/ws.mjs +165 -14
- package/package.json +1 -1
package/dist/is.d.ts
CHANGED
|
@@ -1 +1,248 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `Object.prototype.toString` 的别名,适合在需要手动调用 `call` 时直接复用。
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* objectToString.call([])
|
|
6
|
+
* // => '[object Array]'
|
|
7
|
+
*/
|
|
8
|
+
declare const objectToString: () => string;
|
|
9
|
+
/**
|
|
10
|
+
* 获取对象的完整类型字符串。
|
|
11
|
+
*
|
|
12
|
+
* @param value 需要判断的值。
|
|
13
|
+
* @returns 形如 `[object Array]` 的类型结果。
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* toTypeString([])
|
|
17
|
+
* // => '[object Array]'
|
|
18
|
+
*/
|
|
19
|
+
declare const toTypeString: (value: unknown) => string;
|
|
20
|
+
/**
|
|
21
|
+
* 获取对象的原始类型名称。
|
|
22
|
+
*
|
|
23
|
+
* @param value 需要判断的值。
|
|
24
|
+
* @returns 形如 `Array`、`Date`、`Map` 的类型名。
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* toRawType(new Map())
|
|
28
|
+
* // => 'Map'
|
|
29
|
+
*/
|
|
30
|
+
declare const toRawType: (value: unknown) => string;
|
|
31
|
+
/**
|
|
32
|
+
* 判断值是否为数组。
|
|
33
|
+
*
|
|
34
|
+
* @param value 需要判断的值。
|
|
35
|
+
* @returns 是否为数组。
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* isArray([1, 2, 3])
|
|
39
|
+
* // => true
|
|
40
|
+
*/
|
|
41
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
42
|
+
/**
|
|
43
|
+
* 判断值是否为 `Map`。
|
|
44
|
+
*
|
|
45
|
+
* @param val 需要判断的值。
|
|
46
|
+
* @returns 是否为 `Map`。
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* isMap(new Map())
|
|
50
|
+
* // => true
|
|
51
|
+
*/
|
|
52
|
+
declare const isMap: (val: unknown) => val is Map<any, any>;
|
|
53
|
+
/**
|
|
54
|
+
* 判断值是否为 `Set`。
|
|
55
|
+
*
|
|
56
|
+
* @param val 需要判断的值。
|
|
57
|
+
* @returns 是否为 `Set`。
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* isSet(new Set([1, 2, 3]))
|
|
61
|
+
* // => true
|
|
62
|
+
*/
|
|
63
|
+
declare const isSet: (val: unknown) => val is Set<any>;
|
|
64
|
+
/**
|
|
65
|
+
* 判断值是否为 `Date` 对象。
|
|
66
|
+
*
|
|
67
|
+
* @param val 需要判断的值。
|
|
68
|
+
* @returns 是否为 `Date`。
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* isDate(new Date())
|
|
72
|
+
* // => true
|
|
73
|
+
*/
|
|
74
|
+
declare const isDate: (val: unknown) => val is Date;
|
|
75
|
+
/**
|
|
76
|
+
* 判断值是否为正则对象。
|
|
77
|
+
*
|
|
78
|
+
* @param val 需要判断的值。
|
|
79
|
+
* @returns 是否为 `RegExp`。
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* isRegExp(/sybz/i)
|
|
83
|
+
* // => true
|
|
84
|
+
*/
|
|
85
|
+
declare const isRegExp: (val: unknown) => val is RegExp;
|
|
86
|
+
/**
|
|
87
|
+
* 判断值是否为函数。
|
|
88
|
+
*
|
|
89
|
+
* @param val 需要判断的值。
|
|
90
|
+
* @returns 是否为函数。
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* isFunction(() => {})
|
|
94
|
+
* // => true
|
|
95
|
+
*/
|
|
96
|
+
declare const isFunction: (val: unknown) => val is Function;
|
|
97
|
+
/**
|
|
98
|
+
* 判断值是否为字符串。
|
|
99
|
+
*
|
|
100
|
+
* @param val 需要判断的值。
|
|
101
|
+
* @returns 是否为字符串。
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* isString('sybz')
|
|
105
|
+
* // => true
|
|
106
|
+
*/
|
|
107
|
+
declare const isString: (val: unknown) => val is string;
|
|
108
|
+
/**
|
|
109
|
+
* 判断字符串是否可以被转换成有效数字。
|
|
110
|
+
*
|
|
111
|
+
* @param val 需要判断的字符串。
|
|
112
|
+
* @returns 是否可以安全转换成数字。
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* isStringNumber('12.5')
|
|
116
|
+
* // => true
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* isStringNumber('12px')
|
|
120
|
+
* // => false
|
|
121
|
+
*/
|
|
122
|
+
declare const isStringNumber: (val: string) => boolean;
|
|
123
|
+
/**
|
|
124
|
+
* 判断值是否为数字类型。
|
|
125
|
+
*
|
|
126
|
+
* @param val 需要判断的值。
|
|
127
|
+
* @returns 是否为 `number`。
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* isNumber(12)
|
|
131
|
+
* // => true
|
|
132
|
+
*/
|
|
133
|
+
declare const isNumber: (val: unknown) => val is number;
|
|
134
|
+
/**
|
|
135
|
+
* 判断值是否为 `Symbol`。
|
|
136
|
+
*
|
|
137
|
+
* @param val 需要判断的值。
|
|
138
|
+
* @returns 是否为 `Symbol`。
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* isSymbol(Symbol('id'))
|
|
142
|
+
* // => true
|
|
143
|
+
*/
|
|
144
|
+
declare const isSymbol: (val: unknown) => val is symbol;
|
|
145
|
+
/**
|
|
146
|
+
* 判断值是否为布尔值。
|
|
147
|
+
*
|
|
148
|
+
* @param val 需要判断的值。
|
|
149
|
+
* @returns 是否为 `boolean`。
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* isBoolean(false)
|
|
153
|
+
* // => true
|
|
154
|
+
*/
|
|
155
|
+
declare const isBoolean: (val: unknown) => val is boolean;
|
|
156
|
+
/**
|
|
157
|
+
* 判断值是否为对象且不为 `null`。
|
|
158
|
+
*
|
|
159
|
+
* @param val 需要判断的值。
|
|
160
|
+
* @returns 是否为对象。
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* isObject({ id: 1 })
|
|
164
|
+
* // => true
|
|
165
|
+
*/
|
|
166
|
+
declare const isObject: (val: unknown) => val is Record<string | number | symbol, any>;
|
|
167
|
+
/**
|
|
168
|
+
* 判断值是否为 Promise 风格对象。
|
|
169
|
+
*
|
|
170
|
+
* @param val 需要判断的值。
|
|
171
|
+
* @returns 是否为 Promise。
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* isPromise(Promise.resolve(1))
|
|
175
|
+
* // => true
|
|
176
|
+
*/
|
|
177
|
+
declare const isPromise: <T = any>(val: unknown) => val is Promise<T>;
|
|
178
|
+
/**
|
|
179
|
+
* 判断值是否为普通对象。
|
|
180
|
+
*
|
|
181
|
+
* @param val 需要判断的值。
|
|
182
|
+
* @returns 是否为普通对象。
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* isPlainObject({ id: 1 })
|
|
186
|
+
* // => true
|
|
187
|
+
*/
|
|
188
|
+
declare const isPlainObject: (val: unknown) => val is Record<string | number | symbol, any>;
|
|
189
|
+
/**
|
|
190
|
+
* 判断值是否为空普通对象。
|
|
191
|
+
*
|
|
192
|
+
* @param val 需要判断的值。
|
|
193
|
+
* @returns 是否为空对象。
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* isEmptyObject({})
|
|
197
|
+
* // => true
|
|
198
|
+
*/
|
|
199
|
+
declare const isEmptyObject: (val: unknown) => val is Record<string | number | symbol, any>;
|
|
200
|
+
/**
|
|
201
|
+
* 判断字符串是否为合法链接。
|
|
202
|
+
*
|
|
203
|
+
* @param url 需要判断的链接。
|
|
204
|
+
* @returns 是否为合法 URL。
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* isUrl('https://sybz-components.com')
|
|
208
|
+
* // => true
|
|
209
|
+
*/
|
|
210
|
+
declare function isUrl(url: string): url is string;
|
|
211
|
+
/**
|
|
212
|
+
* 判断节点是否为 `SVGElement`。
|
|
213
|
+
*
|
|
214
|
+
* @param tag 需要判断的节点。
|
|
215
|
+
* @returns 是否为 `SVGElement`。
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
* const svg = document.querySelector('svg')
|
|
219
|
+
* isSVGElement(svg)
|
|
220
|
+
*/
|
|
221
|
+
declare const isSVGElement: (tag: unknown) => tag is SVGElement;
|
|
222
|
+
/**
|
|
223
|
+
* 判断对象是否为 Vue 组件配置。
|
|
224
|
+
*
|
|
225
|
+
* @param val 需要判断的值。
|
|
226
|
+
* @returns 是否像一个 Vue 组件。
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* isComponent({
|
|
230
|
+
* render() {
|
|
231
|
+
* return null
|
|
232
|
+
* },
|
|
233
|
+
* })
|
|
234
|
+
*/
|
|
235
|
+
declare const isComponent: (val: unknown) => boolean;
|
|
236
|
+
/**
|
|
237
|
+
* 判断当前运行环境是否为 iOS。
|
|
238
|
+
*
|
|
239
|
+
* @returns 是否为 iOS 设备。
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* if (isIOS()) {
|
|
243
|
+
* console.log('当前设备是 iOS')
|
|
244
|
+
* }
|
|
245
|
+
*/
|
|
246
|
+
declare function isIOS(): boolean;
|
|
247
|
+
|
|
248
|
+
export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString };
|
package/dist/is.mjs
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
const objectToString = Object.prototype.toString;
|
|
2
|
+
const toTypeString = (value) => objectToString.call(value);
|
|
3
|
+
const toRawType = (value) => {
|
|
4
|
+
return toTypeString(value).slice(8, -1);
|
|
5
|
+
};
|
|
6
|
+
const isArray = Array.isArray;
|
|
7
|
+
const isMap = (val) => toTypeString(val) === "[object Map]";
|
|
8
|
+
const isSet = (val) => toTypeString(val) === "[object Set]";
|
|
9
|
+
const isDate = (val) => toTypeString(val) === "[object Date]";
|
|
10
|
+
const isRegExp = (val) => toTypeString(val) === "[object RegExp]";
|
|
11
|
+
const isFunction = (val) => typeof val === "function";
|
|
12
|
+
const isString = (val) => typeof val === "string";
|
|
13
|
+
const isStringNumber = (val) => {
|
|
14
|
+
if (!isString(val)) {
|
|
15
|
+
return false;
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
+
return !Number.isNaN(Number(val));
|
|
18
|
+
};
|
|
19
|
+
const isNumber = (val) => typeof val === "number";
|
|
20
|
+
const isSymbol = (val) => typeof val === "symbol";
|
|
21
|
+
const isBoolean = (val) => typeof val === "boolean";
|
|
22
|
+
const isObject = (val) => val !== null && typeof val === "object";
|
|
23
|
+
const isPromise = (val) => {
|
|
24
|
+
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
|
|
25
|
+
};
|
|
26
|
+
const isPlainObject = (val) => toTypeString(val) === "[object Object]";
|
|
27
|
+
const isEmptyObject = (val) => isPlainObject(val) && Object.keys(val).length === 0;
|
|
28
|
+
function isUrl(url) {
|
|
29
|
+
const regex = new RegExp(
|
|
30
|
+
"^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$",
|
|
31
|
+
"i"
|
|
32
|
+
);
|
|
33
|
+
return regex.test(url);
|
|
34
|
+
}
|
|
35
|
+
const isSVGElement = (tag) => typeof SVGElement !== "undefined" && tag instanceof SVGElement;
|
|
36
|
+
const isComponent = (val) => isPlainObject(val) && (isFunction(val.render) || isFunction(val.setup));
|
|
37
|
+
function isIOS() {
|
|
38
|
+
const isIphone = navigator.userAgent.includes("iPhone");
|
|
39
|
+
const isIpad = navigator.userAgent.includes("iPad");
|
|
40
|
+
return isIphone || isIpad;
|
|
41
|
+
}
|
|
17
42
|
|
|
18
|
-
export
|
|
19
|
-
export const toTypeString = _module.toTypeString;
|
|
20
|
-
export const toRawType = _module.toRawType;
|
|
21
|
-
export const isArray = _module.isArray;
|
|
22
|
-
export const isMap = _module.isMap;
|
|
23
|
-
export const any = _module.any;
|
|
24
|
-
export const isSet = _module.isSet;
|
|
25
|
-
export const isDate = _module.isDate;
|
|
26
|
-
export const isRegExp = _module.isRegExp;
|
|
27
|
-
export const isFunction = _module.isFunction;
|
|
28
|
-
export const isString = _module.isString;
|
|
29
|
-
export const isStringNumber = _module.isStringNumber;
|
|
30
|
-
export const isNumber = _module.isNumber;
|
|
31
|
-
export const isSymbol = _module.isSymbol;
|
|
32
|
-
export const isBoolean = _module.isBoolean;
|
|
33
|
-
export const isObject = _module.isObject;
|
|
34
|
-
export const isPromise = _module.isPromise;
|
|
35
|
-
export const isPlainObject = _module.isPlainObject;
|
|
36
|
-
export const isEmptyObject = _module.isEmptyObject;
|
|
37
|
-
export const isUrl = _module.isUrl;
|
|
38
|
-
export const isSVGElement = _module.isSVGElement;
|
|
39
|
-
export const isComponent = _module.isComponent;
|
|
40
|
-
export const isIOS = _module.isIOS;
|
|
43
|
+
export { isArray, isBoolean, isComponent, isDate, isEmptyObject, isFunction, isIOS, isMap, isNumber, isObject, isPlainObject, isPromise, isRegExp, isSVGElement, isSet, isString, isStringNumber, isSymbol, isUrl, objectToString, toRawType, toTypeString };
|