// eslint-disable-next-line vue/prefer-import-from-vue import { isArray, isFunction, isObject, isString } from '@vue/shared'; import { isBoolean, isEqual, isNil, isNull, isNumber } from 'lodash-es'; function isUndefined(value: unknown): value is undefined { return typeof value === 'undefined'; } function isEmpty(value: T): value is T { if (value == null || value === undefined) { return true; } if (isArray(value) || isString(value)) { return value.length === 0; } if (value instanceof Map || value instanceof Set) { return value.size === 0; } if (isObject(value)) { return Object.keys(value).length === 0; } return false; } /** * @description 判断所给字符串是否为url类型,这里只判断是否 http/http,其他格式不支持 * @param pathname * @returns */ function isHttpUrl(url: string) { // Regular expression to match HTTP(S) URL const httpRegex = /^https?:\/\/.*$/; return httpRegex.test(url); } function isWindow(value: any): value is Window { return typeof window !== 'undefined' && value != null && value === value.window; } function isElement(val: unknown): val is Element { return isObject(val) && !!val.tagName; } const isServer = typeof window === 'undefined'; const isClient = !isServer; function isUrl(path: string): boolean { // eslint-disable-next-line regexp/no-unused-capturing-group, regexp/strict const reg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/; return reg.test(path); } // eslint-disable-next-line vue/prefer-import-from-vue export * from '@vue/shared'; export { isArray, isBoolean, isClient, isElement, isEmpty, isEqual, isFunction, isHttpUrl, isNil, isNull, isNumber, isObject, isServer, isString, isUndefined, isUrl, isWindow, };