Skip to content

Commit a17486a

Browse files
author
Simon he
committed
feature: add Type judgment function
1 parent 0c1883e commit a17486a

19 files changed

+67
-8
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
'family.name': 'familyName',
1919
'family.age': 'familyAge'
2020
})
21+
- isStr // 判断是否是字符串
22+
- isNum // 判断是否是数字
23+
- isPlainObject // 判断是否是对象
24+
- isArray // 判断是否是数组
25+
- isFn // 判断是否是函数
26+
- isUndef // 判断是否是undefined
27+
- isNull // 判断是否是null
28+
- isPromise // 判断是否是Promise
29+
- isSymbol // 判断是否是Symbol
30+
- isNaN // 判断是否是NaN
31+
- isReg // 判断是否是正则表达式
2132

2233
## 使用方法
2334
### deepMerge

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"eslint": "^8.16.0",
5757
"eslint-plugin-n": "^15.2.1",
5858
"pkgroll": "^1.3.1",
59+
"simon-js-tool": "workspace:^1.0.8",
5960
"typescript": "^4.7.2",
6061
"vitest": "^0.14.2"
6162
}

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
const _toString = Object.prototype.toString
2-
3-
export function isPlainObject(obj: any): boolean {
4-
return _toString.call(obj) === '[object Object]'
5-
}
1+
export const _toString = Object.prototype.toString

src/deepCompare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isPlainObject } from './common'
1+
import { isPlainObject } from './isPlainObject'
22

33
// 深比较
44
export function deepCompare(comp1: any, comp2: any, error: string[] = [], errorMsg: string[] = [], name?: string, index?: string) {

src/deepMerge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isPlainObject } from './common'
1+
import { isPlainObject } from './isPlainObject'
22

33
export function deepMerge(target: Record<any, any>, ...sources: Record<any, any>[]) {
44
if (!isPlainObject(target))

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ export { debounce } from './debounce'
1111
export { throttle } from './throttle'
1212
export { traverse } from './traverse'
1313
export { transformKey } from './transformKey'
14+
export { isFn } from './isFn'
15+
export { isStr } from './isStr'
16+
export { isNum } from './isNum'
17+
export { isPlainObject } from './isPlainObject'
18+
export { isUndef } from './isUndef'
19+
export { isArray } from './isArray'
20+
export { isPromise } from './isPromise'
21+
export { isNaN } from './isNaN'
22+
export { isSymbol } from './isSymbol'
23+
export { isNull } from './isNull'
24+
export { isReg } from './isReg'

src/isArray.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function isArray(o: any): boolean {
2+
return Array.isArray(o)
3+
}

src/isFn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function isFn(o: any): boolean {
2+
return typeof o === 'function'
3+
}

src/isNaN.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function isNaN(o: any): boolean {
2+
return typeof o !== 'number'
3+
? false
4+
: isNaN(o)
5+
}

0 commit comments

Comments
 (0)