Sanakey
5 天以前 2af71bcf522c485ea005184c977986374a7dcc4a
提交 | 用户 | age
f91d77 1 export {
KL 2   isArguments,
3   isArrayBuffer,
4   isArrayLike,
5   isArrayLikeObject,
6   isBuffer,
7   isBoolean,
8   isDate,
9   isElement,
10   isEmpty,
11   isEqual,
12   isEqualWith,
13   isError,
14   isFunction,
15   isFinite,
16   isLength,
17   isMap,
18   isMatch,
19   isMatchWith,
20   isNative,
21   isNil,
22   isNumber,
23   isNull,
24   isObjectLike,
25   isPlainObject,
26   isRegExp,
27   isSafeInteger,
28   isSet,
29   isString,
30   isSymbol,
31   isTypedArray,
32   isUndefined,
33   isWeakMap,
34   isWeakSet,
35 } from 'lodash-es';
2f6253 36 const toString = Object.prototype.toString;
37
38 export function is(val: unknown, type: string) {
39   return toString.call(val) === `[object ${type}]`;
40 }
41
144ab5 42 export function isDef<T = unknown>(val?: T): val is T {
2f6253 43   return typeof val !== 'undefined';
144ab5 44 }
2f6253 45
f91d77 46 // TODO 此处 isObject 存在歧义
144ab5 47 export function isObject(val: any): val is Record<any, any> {
2f6253 48   return val !== null && is(val, 'Object');
144ab5 49 }
V 50
f91d77 51 // TODO 此处 isArray 存在歧义
c774a6 52 export function isArray(val: any): val is Array<any> {
2f6253 53   return val && Array.isArray(val);
54 }
55
144ab5 56 export function isWindow(val: any): val is Window {
2f6253 57   return typeof window !== 'undefined' && is(val, 'Window');
144ab5 58 }
2f6253 59
60 export const isServer = typeof window === 'undefined';
61
581007 62 export const isClient = !isServer;
88f4a3 63
f91d77 64 export function isHttpUrl(path: string): boolean {
ba2415 65   const reg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/;
88f4a3 66   return reg.test(path);
144ab5 67 }
98e2e4 68
X 69 export function isPascalCase(str: string): boolean {
70   const regex = /^[A-Z][A-Za-z]*$/;
71   return regex.test(str);
72 }