refactor: fix type check
parent
5defcbd8f7
commit
28b21bb466
|
@ -10,7 +10,7 @@ import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { buildShortUUID } from '@/utils/uuid'
|
import { buildShortUUID } from '@/utils/uuid'
|
||||||
import { getAccessToken, getTenantId } from '@/utils/auth'
|
import { getAccessToken, getTenantId } from '@/utils/auth'
|
||||||
import { isArray, isNotEmpty, isUrl } from '@/utils/is'
|
import { isArray, isHttpUrl, isNil } from '@/utils/is'
|
||||||
import { useRuleFormItem } from '@/hooks/component/useFormItem'
|
import { useRuleFormItem } from '@/hooks/component/useFormItem'
|
||||||
import { useAttrs } from '@/hooks/core/useAttrs'
|
import { useAttrs } from '@/hooks/core/useAttrs'
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ watch(
|
||||||
(v) => {
|
(v) => {
|
||||||
fileState.newList = v
|
fileState.newList = v
|
||||||
.filter((item: any) => {
|
.filter((item: any) => {
|
||||||
return item?.url && item.status === 'done' && isUrl(item?.url)
|
return item?.url && item.status === 'done' && isHttpUrl(item?.url)
|
||||||
})
|
})
|
||||||
.map((item: any) => item?.url)
|
.map((item: any) => item?.url)
|
||||||
fileState.newStr = join(fileState.newList)
|
fileState.newStr = join(fileState.newList)
|
||||||
|
@ -97,7 +97,7 @@ function changeFileValue(value: any) {
|
||||||
fileState.oldStr = stateStr
|
fileState.oldStr = stateStr
|
||||||
let list: string[] = []
|
let list: string[] = []
|
||||||
if (props.multiple) {
|
if (props.multiple) {
|
||||||
if (isNotEmpty(value)) {
|
if (!isNil(value)) {
|
||||||
if (isArray(value))
|
if (isArray(value))
|
||||||
list = value as string[]
|
list = value as string[]
|
||||||
else
|
else
|
||||||
|
@ -105,7 +105,7 @@ function changeFileValue(value: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (isNotEmpty(value))
|
if (!isNil(value))
|
||||||
list.push(value as string)
|
list.push(value as string)
|
||||||
}
|
}
|
||||||
fileList.value = list.map((item) => {
|
fileList.value = list.map((item) => {
|
||||||
|
|
|
@ -4,15 +4,7 @@ import { nextTick, toRaw, unref } from 'vue'
|
||||||
import { cloneDeep, get, set, uniqBy } from 'lodash-es'
|
import { cloneDeep, get, set, uniqBy } from 'lodash-es'
|
||||||
import type { FormActionType, FormProps, FormSchemaInner as FormSchema } from '../types/form'
|
import type { FormActionType, FormProps, FormSchemaInner as FormSchema } from '../types/form'
|
||||||
import { dateItemType, defaultValueComponents, handleInputNumberValue } from '../helper'
|
import { dateItemType, defaultValueComponents, handleInputNumberValue } from '../helper'
|
||||||
import {
|
import { isArray, isDef, isEmpty, isFunction, isNil, isObject, isString } from '@/utils/is'
|
||||||
isArray,
|
|
||||||
isDef,
|
|
||||||
isEmpty,
|
|
||||||
isFunction,
|
|
||||||
isNullOrUnDef,
|
|
||||||
isObject,
|
|
||||||
isString,
|
|
||||||
} from '@/utils/is'
|
|
||||||
import { deepMerge } from '@/utils'
|
import { deepMerge } from '@/utils'
|
||||||
import { dateUtil } from '@/utils/dateUtil'
|
import { dateUtil } from '@/utils/dateUtil'
|
||||||
import { error } from '@/utils/log'
|
import { error } from '@/utils/log'
|
||||||
|
@ -317,9 +309,9 @@ export function useFormEvents({
|
||||||
item.component !== 'Divider'
|
item.component !== 'Divider'
|
||||||
&& Reflect.has(item, 'field')
|
&& Reflect.has(item, 'field')
|
||||||
&& item.field
|
&& item.field
|
||||||
&& !isNullOrUnDef(item.defaultValue)
|
&& !isNil(item.defaultValue)
|
||||||
&& (!(item.field in currentFieldsValue)
|
&& (!(item.field in currentFieldsValue)
|
||||||
|| isNullOrUnDef(currentFieldsValue[item.field])
|
|| isNil(currentFieldsValue[item.field])
|
||||||
|| isEmpty(currentFieldsValue[item.field]))
|
|| isEmpty(currentFieldsValue[item.field]))
|
||||||
)
|
)
|
||||||
obj[item.field] = item.defaultValue
|
obj[item.field] = item.defaultValue
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type { ComputedRef, Ref } from 'vue'
|
||||||
import { cloneDeep, get, set, unset } from 'lodash-es'
|
import { cloneDeep, get, set, unset } from 'lodash-es'
|
||||||
import type { FormProps, FormSchemaInner as FormSchema } from '../types/form'
|
import type { FormProps, FormSchemaInner as FormSchema } from '../types/form'
|
||||||
import { dateUtil } from '@/utils/dateUtil'
|
import { dateUtil } from '@/utils/dateUtil'
|
||||||
import { isArray, isFunction, isNotEmpty, isNullOrUnDef, isObject, isString } from '@/utils/is'
|
import { isArray, isEmpty, isFunction, isNil, isObject, isString } from '@/utils/is'
|
||||||
|
|
||||||
interface UseFormValuesContext {
|
interface UseFormValuesContext {
|
||||||
defaultValueRef: Ref<any>
|
defaultValueRef: Ref<any>
|
||||||
|
@ -113,10 +113,10 @@ export function useFormValues({
|
||||||
|
|
||||||
const [startTimeFormat, endTimeFormat] = Array.isArray(format) ? format : [format, format]
|
const [startTimeFormat, endTimeFormat] = Array.isArray(format) ? format : [format, format]
|
||||||
|
|
||||||
if (isNotEmpty(startTime))
|
if (!isNil(startTime) && !isEmpty(startTime))
|
||||||
set(values, startTimeKey, formatTime(startTime, startTimeFormat))
|
set(values, startTimeKey, formatTime(startTime, startTimeFormat))
|
||||||
|
|
||||||
if (isNotEmpty(endTime))
|
if (!isNil(startTime) && !isEmpty(startTime))
|
||||||
set(values, endTimeKey, formatTime(endTime, endTimeFormat))
|
set(values, endTimeKey, formatTime(endTime, endTimeFormat))
|
||||||
|
|
||||||
unset(values, field)
|
unset(values, field)
|
||||||
|
@ -149,7 +149,7 @@ export function useFormValues({
|
||||||
formModel[field] = defaultValueObj![field]
|
formModel[field] = defaultValueObj![field]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (!isNullOrUnDef(defaultValue)) {
|
if (!isNil(defaultValue)) {
|
||||||
obj[item.field] = defaultValue
|
obj[item.field] = defaultValue
|
||||||
|
|
||||||
if (formModel[item.field] === undefined)
|
if (formModel[item.field] === undefined)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { useDesign } from '@/hooks/web/useDesign'
|
||||||
import { listenerRouteChange } from '@/logics/mitt/routeChange'
|
import { listenerRouteChange } from '@/logics/mitt/routeChange'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { REDIRECT_NAME } from '@/router/constant'
|
import { REDIRECT_NAME } from '@/router/constant'
|
||||||
import { isFunction, isUrl } from '@/utils/is'
|
import { isFunction, isHttpUrl } from '@/utils/is'
|
||||||
import { openWindow } from '@/utils'
|
import { openWindow } from '@/utils'
|
||||||
|
|
||||||
defineOptions({ name: 'SimpleMenu', inheritAttrs: false })
|
defineOptions({ name: 'SimpleMenu', inheritAttrs: false })
|
||||||
|
@ -99,7 +99,7 @@ async function handleMenuChange(route?: RouteLocationNormalizedLoaded) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleSelect(key: string) {
|
async function handleSelect(key: string) {
|
||||||
if (isUrl(key)) {
|
if (isHttpUrl(key)) {
|
||||||
openWindow(key)
|
openWindow(key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import { ScrollContainer } from '@/components/Container'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
|
||||||
import { isFunction, isNullAndUnDef } from '@/utils/is'
|
import { isFunction, isNil } from '@/utils/is'
|
||||||
import { getPopupContainer as getParentContainer } from '@/utils'
|
import { getPopupContainer as getParentContainer } from '@/utils'
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
|
@ -208,7 +208,7 @@ function handleOpenChange() {
|
||||||
handle: '.table-column-drag-icon ',
|
handle: '.table-column-drag-icon ',
|
||||||
onEnd: (evt) => {
|
onEnd: (evt) => {
|
||||||
const { oldIndex, newIndex } = evt
|
const { oldIndex, newIndex } = evt
|
||||||
if (isNullAndUnDef(oldIndex) || isNullAndUnDef(newIndex) || oldIndex === newIndex)
|
if (isNil(oldIndex) || isNil(newIndex) || oldIndex === newIndex)
|
||||||
return
|
return
|
||||||
|
|
||||||
// Sort column
|
// Sort column
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { ScrollContainer } from '@/components/Container'
|
||||||
import { useGo } from '@/hooks/web/usePage'
|
import { useGo } from '@/hooks/web/usePage'
|
||||||
import { openWindow } from '@/utils'
|
import { openWindow } from '@/utils'
|
||||||
import { propTypes } from '@/utils/propTypes'
|
import { propTypes } from '@/utils/propTypes'
|
||||||
import { isUrl } from '@/utils/is'
|
import { isHttpUrl } from '@/utils/is'
|
||||||
import { useRootSetting } from '@/hooks/setting/useRootSetting'
|
import { useRootSetting } from '@/hooks/setting/useRootSetting'
|
||||||
import { useAppInject } from '@/hooks/web/useAppInject'
|
import { useAppInject } from '@/hooks/web/useAppInject'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
@ -115,7 +115,7 @@ export default defineComponent({
|
||||||
* @param path
|
* @param path
|
||||||
*/
|
*/
|
||||||
async function beforeMenuClickFn(path: string) {
|
async function beforeMenuClickFn(path: string) {
|
||||||
if (!isUrl(path))
|
if (!isHttpUrl(path))
|
||||||
return true
|
return true
|
||||||
|
|
||||||
openWindow(path)
|
openWindow(path)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
import { useSortable } from '@/hooks/web/useSortable'
|
import { useSortable } from '@/hooks/web/useSortable'
|
||||||
import { useMultipleTabStore } from '@/store/modules/multipleTab'
|
import { useMultipleTabStore } from '@/store/modules/multipleTab'
|
||||||
import { isNullAndUnDef } from '@/utils/is'
|
import { isNil } from '@/utils/is'
|
||||||
import projectSetting from '@/settings/projectSetting'
|
import projectSetting from '@/settings/projectSetting'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
@ -70,7 +70,7 @@ export function useTabsDrag(affixTextList: string[]) {
|
||||||
onEnd: (evt) => {
|
onEnd: (evt) => {
|
||||||
const { oldIndex, newIndex } = evt
|
const { oldIndex, newIndex } = evt
|
||||||
|
|
||||||
if (isNullAndUnDef(oldIndex) || isNullAndUnDef(newIndex) || oldIndex === newIndex)
|
if (isNil(oldIndex) || isNil(newIndex) || oldIndex === newIndex)
|
||||||
return
|
return
|
||||||
|
|
||||||
tabStore.sortTabs(oldIndex, newIndex)
|
tabStore.sortTabs(oldIndex, newIndex)
|
||||||
|
|
|
@ -3,7 +3,7 @@ import type { RouteParams } from 'vue-router'
|
||||||
import { toRaw } from 'vue'
|
import { toRaw } from 'vue'
|
||||||
import type { AppRouteModule, AppRouteRecordRaw, Menu, MenuModule } from '@/router/types'
|
import type { AppRouteModule, AppRouteRecordRaw, Menu, MenuModule } from '@/router/types'
|
||||||
import { findPath, treeMap } from '@/utils/helper/treeHelper'
|
import { findPath, treeMap } from '@/utils/helper/treeHelper'
|
||||||
import { isUrl } from '@/utils/is'
|
import { isHttpUrl } from '@/utils/is'
|
||||||
|
|
||||||
export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
|
export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
|
||||||
const menuList = findPath(treeData, n => n.path === path) as Menu[]
|
const menuList = findPath(treeData, n => n.path === path) as Menu[]
|
||||||
|
@ -19,7 +19,7 @@ function joinParentPath(menus: Menu[], parentPath = '') {
|
||||||
// 请注意,以 / 开头的嵌套路径将被视为根路径。
|
// 请注意,以 / 开头的嵌套路径将被视为根路径。
|
||||||
// This allows you to leverage the component nesting without having to use a nested URL.
|
// This allows you to leverage the component nesting without having to use a nested URL.
|
||||||
// 这允许你利用组件嵌套,而无需使用嵌套 URL。
|
// 这允许你利用组件嵌套,而无需使用嵌套 URL。
|
||||||
if (!(menu.path.startsWith('/') || isUrl(menu.path))) {
|
if (!(menu.path.startsWith('/') || isHttpUrl(menu.path))) {
|
||||||
// path doesn't start with /, nor is it a url, join parent path
|
// path doesn't start with /, nor is it a url, join parent path
|
||||||
// 路径不以 / 开头,也不是 url,加入父路径
|
// 路径不以 / 开头,也不是 url,加入父路径
|
||||||
menu.path = `${parentPath}/${menu.path}`
|
menu.path = `${parentPath}/${menu.path}`
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { cloneDeep, omit } from 'lodash-es'
|
||||||
import { EXCEPTION_COMPONENT, LAYOUT, getParentLayout } from '@/router/constant'
|
import { EXCEPTION_COMPONENT, LAYOUT, getParentLayout } from '@/router/constant'
|
||||||
import type { AppRouteModule, AppRouteRecordRaw } from '@/router/types'
|
import type { AppRouteModule, AppRouteRecordRaw } from '@/router/types'
|
||||||
import { warn } from '@/utils/log'
|
import { warn } from '@/utils/log'
|
||||||
import { isUrl } from '@/utils/is'
|
import { isHttpUrl } from '@/utils/is'
|
||||||
|
|
||||||
export type LayoutMapKey = 'LAYOUT'
|
export type LayoutMapKey = 'LAYOUT'
|
||||||
const IFRAME = () => import('@/views/base/iframe/FrameBlank.vue')
|
const IFRAME = () => import('@/views/base/iframe/FrameBlank.vue')
|
||||||
|
@ -77,7 +77,7 @@ function dynamicImport(dynamicViewsModules: Record<string, () => Promise<Recorda
|
||||||
// 将背景对象变成路由对象
|
// 将背景对象变成路由对象
|
||||||
export function transformObjToRoute<T = AppRouteModule>(routeList: AppRouteModule[]): T[] {
|
export function transformObjToRoute<T = AppRouteModule>(routeList: AppRouteModule[]): T[] {
|
||||||
routeList.forEach((route) => {
|
routeList.forEach((route) => {
|
||||||
if (isUrl(route.path))
|
if (isHttpUrl(route.path))
|
||||||
route.component = 'IFrame'
|
route.component = 'IFrame'
|
||||||
else if (route.children && route.parentId === 0)
|
else if (route.children && route.parentId === 0)
|
||||||
route.component = 'LAYOUT'
|
route.component = 'LAYOUT'
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { useAppStoreWithOut } from '@/store/modules/app'
|
||||||
import { usePermissionStore } from '@/store/modules/permission'
|
import { usePermissionStore } from '@/store/modules/permission'
|
||||||
import { getAllParentPath, transformMenuModule } from '@/router/helper/menuHelper'
|
import { getAllParentPath, transformMenuModule } from '@/router/helper/menuHelper'
|
||||||
import { filter } from '@/utils/helper/treeHelper'
|
import { filter } from '@/utils/helper/treeHelper'
|
||||||
import { isUrl } from '@/utils/is'
|
import { isHttpUrl } from '@/utils/is'
|
||||||
import { router } from '@/router'
|
import { router } from '@/router'
|
||||||
import { PermissionModeEnum } from '@/enums/appEnum'
|
import { PermissionModeEnum } from '@/enums/appEnum'
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ export async function getChildrenMenus(parentPath: string) {
|
||||||
function basicFilter(routes: RouteRecordNormalized[]) {
|
function basicFilter(routes: RouteRecordNormalized[]) {
|
||||||
return (menu: Menu) => {
|
return (menu: Menu) => {
|
||||||
const matchRoute = routes.find((route) => {
|
const matchRoute = routes.find((route) => {
|
||||||
if (isUrl(menu.path))
|
if (isHttpUrl(menu.path))
|
||||||
return true
|
return true
|
||||||
|
|
||||||
if (route.meta?.carryParam)
|
if (route.meta?.carryParam)
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class Memory<T = any, V = any> {
|
||||||
// get<K extends keyof T>(key: K) {
|
// get<K extends keyof T>(key: K) {
|
||||||
// const item = this.getItem(key);
|
// const item = this.getItem(key);
|
||||||
// const time = item?.time;
|
// const time = item?.time;
|
||||||
// if (!isNullOrUnDef(time) && time < new Date().getTime()) {
|
// if (!isNil(time) && time < new Date().getTime()) {
|
||||||
// this.remove(key);
|
// this.remove(key);
|
||||||
// }
|
// }
|
||||||
// return item?.value ?? undefined;
|
// return item?.value ?? undefined;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { cacheCipher } from '@/settings/encryptionSetting'
|
import { cacheCipher } from '@/settings/encryptionSetting'
|
||||||
import { isNullOrUnDef } from '@/utils/is'
|
import { isNil } from '@/utils/is'
|
||||||
import type { Encryption, EncryptionParams } from '@/utils/cipher'
|
import type { Encryption, EncryptionParams } from '@/utils/cipher'
|
||||||
import { EncryptionFactory } from '@/utils/cipher'
|
import { EncryptionFactory } from '@/utils/cipher'
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ export function createStorage({
|
||||||
const stringData = JSON.stringify({
|
const stringData = JSON.stringify({
|
||||||
value,
|
value,
|
||||||
time: Date.now(),
|
time: Date.now(),
|
||||||
expire: !isNullOrUnDef(expire) ? new Date().getTime() + expire * 1000 : null,
|
expire: !isNil(expire) ? new Date().getTime() + expire * 1000 : null,
|
||||||
})
|
})
|
||||||
const stringifyValue = this.hasEncrypt ? this.encryption.encrypt(stringData) : stringData
|
const stringifyValue = this.hasEncrypt ? this.encryption.encrypt(stringData) : stringData
|
||||||
this.storage.setItem(this.getKey(key), stringifyValue)
|
this.storage.setItem(this.getKey(key), stringifyValue)
|
||||||
|
@ -79,7 +79,7 @@ export function createStorage({
|
||||||
const decVal = this.hasEncrypt ? this.encryption.decrypt(val) : val
|
const decVal = this.hasEncrypt ? this.encryption.decrypt(val) : val
|
||||||
const data = JSON.parse(decVal)
|
const data = JSON.parse(decVal)
|
||||||
const { value, expire } = data
|
const { value, expire } = data
|
||||||
if (isNullOrUnDef(expire) || expire >= new Date().getTime())
|
if (isNil(expire) || expire >= new Date().getTime())
|
||||||
return value
|
return value
|
||||||
|
|
||||||
this.remove(key)
|
this.remove(key)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import type { RequestOptions, Result } from '@/types/axios'
|
||||||
import { useGlobSetting } from '@/hooks/setting'
|
import { useGlobSetting } from '@/hooks/setting'
|
||||||
import { useMessage } from '@/hooks/web/useMessage'
|
import { useMessage } from '@/hooks/web/useMessage'
|
||||||
import { ContentTypeEnum, RequestEnum, ResultEnum } from '@/enums/httpEnum'
|
import { ContentTypeEnum, RequestEnum, ResultEnum } from '@/enums/httpEnum'
|
||||||
import { isEmpty, isNull, isString, isUnDef } from '@/utils/is'
|
import { isEmpty, isNull, isString, isUndefined } from '@/utils/is'
|
||||||
import { getAccessToken, getTenantId } from '@/utils/auth'
|
import { getAccessToken, getTenantId } from '@/utils/auth'
|
||||||
import { deepMerge, setObjToUrlParams } from '@/utils'
|
import { deepMerge, setObjToUrlParams } from '@/utils'
|
||||||
import { useErrorLogStoreWithOut } from '@/store/modules/errorLog'
|
import { useErrorLogStoreWithOut } from '@/store/modules/errorLog'
|
||||||
|
@ -67,7 +67,7 @@ const transform: AxiosTransform = {
|
||||||
if (successMsg === null || successMsg === undefined || successMsg === '')
|
if (successMsg === null || successMsg === undefined || successMsg === '')
|
||||||
successMsg = t('sys.api.operationSuccess')
|
successMsg = t('sys.api.operationSuccess')
|
||||||
|
|
||||||
if (isNull(successMsg) || isUnDef(successMsg) || isEmpty(successMsg))
|
if (isNull(successMsg) || isUndefined(successMsg) || isEmpty(successMsg))
|
||||||
successMsg = t('sys.api.operationSuccess')
|
successMsg = t('sys.api.operationSuccess')
|
||||||
|
|
||||||
if (options.successMessageMode === 'modal')
|
if (options.successMessageMode === 'modal')
|
||||||
|
|
110
src/utils/is.ts
110
src/utils/is.ts
|
@ -1,4 +1,38 @@
|
||||||
import { isNil } from 'lodash-es'
|
export {
|
||||||
|
isArguments,
|
||||||
|
isArrayBuffer,
|
||||||
|
isArrayLike,
|
||||||
|
isArrayLikeObject,
|
||||||
|
isBuffer,
|
||||||
|
isBoolean,
|
||||||
|
isDate,
|
||||||
|
isElement,
|
||||||
|
isEmpty,
|
||||||
|
isEqual,
|
||||||
|
isEqualWith,
|
||||||
|
isError,
|
||||||
|
isFunction,
|
||||||
|
isFinite,
|
||||||
|
isLength,
|
||||||
|
isMap,
|
||||||
|
isMatch,
|
||||||
|
isMatchWith,
|
||||||
|
isNative,
|
||||||
|
isNil,
|
||||||
|
isNumber,
|
||||||
|
isNull,
|
||||||
|
isObjectLike,
|
||||||
|
isPlainObject,
|
||||||
|
isRegExp,
|
||||||
|
isSafeInteger,
|
||||||
|
isSet,
|
||||||
|
isString,
|
||||||
|
isSymbol,
|
||||||
|
isTypedArray,
|
||||||
|
isUndefined,
|
||||||
|
isWeakMap,
|
||||||
|
isWeakSet,
|
||||||
|
} from 'lodash-es'
|
||||||
|
|
||||||
const toString = Object.prototype.toString
|
const toString = Object.prototype.toString
|
||||||
|
|
||||||
|
@ -10,74 +44,10 @@ export function isDef<T = unknown>(val?: T): val is T {
|
||||||
return typeof val !== 'undefined'
|
return typeof val !== 'undefined'
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isUnDef<T = unknown>(val?: T): val is T {
|
|
||||||
return !isDef(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isObject(val: any): val is Record<any, any> {
|
export function isObject(val: any): val is Record<any, any> {
|
||||||
return val !== null && is(val, 'Object')
|
return val !== null && is(val, 'Object')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isNotEmpty(val: any): boolean {
|
|
||||||
return !isNil(val) && !isEmpty(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isEmpty<T = unknown>(val: T): val is T {
|
|
||||||
if (isNil(val))
|
|
||||||
return true
|
|
||||||
|
|
||||||
if (isArray(val) || isString(val))
|
|
||||||
return val.length === 0
|
|
||||||
|
|
||||||
if (val instanceof Map || val instanceof Set)
|
|
||||||
return val.size === 0
|
|
||||||
|
|
||||||
if (isObject(val))
|
|
||||||
return Object.keys(val).length === 0
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isDate(val: unknown): val is Date {
|
|
||||||
return is(val, 'Date')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isNull(val: unknown): val is null {
|
|
||||||
return val === null
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isNullAndUnDef(val: unknown): val is null | undefined {
|
|
||||||
return isUnDef(val) && isNull(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isNullOrUnDef(val: unknown): val is null | undefined {
|
|
||||||
return isUnDef(val) || isNull(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isNumber(val: unknown): val is number {
|
|
||||||
return is(val, 'Number')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isPromise<T = any>(val: unknown): val is Promise<T> {
|
|
||||||
return is(val, 'Promise') && isObject(val) && isFunction(val.then) && isFunction(val.catch)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isString(val: unknown): val is string {
|
|
||||||
return is(val, 'String')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isFunction(val: unknown): val is Function {
|
|
||||||
return typeof val === 'function'
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isBoolean(val: unknown): val is boolean {
|
|
||||||
return is(val, 'Boolean')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isRegExp(val: unknown): val is RegExp {
|
|
||||||
return is(val, 'RegExp')
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isArray(val: any): val is Array<any> {
|
export function isArray(val: any): val is Array<any> {
|
||||||
return val && Array.isArray(val)
|
return val && Array.isArray(val)
|
||||||
}
|
}
|
||||||
|
@ -86,19 +56,11 @@ export function isWindow(val: any): val is Window {
|
||||||
return typeof window !== 'undefined' && is(val, 'Window')
|
return typeof window !== 'undefined' && is(val, 'Window')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isElement(val: unknown): val is Element {
|
|
||||||
return isObject(val) && !!val.tagName
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isMap(val: unknown): val is Map<any, any> {
|
|
||||||
return is(val, 'Map')
|
|
||||||
}
|
|
||||||
|
|
||||||
export const isServer = typeof window === 'undefined'
|
export const isServer = typeof window === 'undefined'
|
||||||
|
|
||||||
export const isClient = !isServer
|
export const isClient = !isServer
|
||||||
|
|
||||||
export function isUrl(path: string): boolean {
|
export function isHttpUrl(path: string): boolean {
|
||||||
const reg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/
|
const reg = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- ./?%&=]*)?/
|
||||||
return reg.test(path)
|
return reg.test(path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue