Browse Source

feat: 新增类型校验函数

MTrun 3 years ago
parent
commit
94672221e5
2 changed files with 25 additions and 1 deletions
  1. 2 1
      src/utils/index.ts
  2. 23 0
      src/utils/type.ts

+ 2 - 1
src/utils/index.ts

@@ -4,4 +4,5 @@ export * from '@/utils/router'
 export * from '@/utils/storage'
 export * from '@/utils/style'
 export * from '@/utils/plugin'
-export * from '@/utils/componets'
+export * from '@/utils/componets'
+export * from '@/utils/type'

+ 23 - 0
src/utils/type.ts

@@ -0,0 +1,23 @@
+export function isString(p: any): p is string {
+  return typeof p === 'string'
+}
+
+export function isNumber(p: any): p is number {
+  return typeof p === 'number'
+}
+
+export function isBoolean(p: any): p is boolean {
+  return typeof p === 'boolean'
+}
+
+export function isUndefined(p: any): p is undefined {
+  return typeof p === 'undefined'
+}
+
+export function isNull(p: any): p is null {
+  return p === null
+}
+
+export function isArray(p: any): p is [] {
+  return Array.isArray(p)
+}