@mudbean/is 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/cjs/error.js +211 -1
- package/cjs/index.js +76 -1
- package/cjs/intl.js +152 -1
- package/cjs/isArray.js +340 -1
- package/cjs/isBoolean.js +71 -1
- package/cjs/isFunction.js +120 -1
- package/cjs/isNull.js +49 -1
- package/cjs/isNumber.js +148 -1
- package/cjs/isObject.js +200 -1
- package/cjs/isString.js +121 -1
- package/cjs/isSymbol.js +36 -1
- package/cjs/isType.js +16 -1
- package/cjs/typeOf.js +72 -1
- package/es/error.js +202 -1
- package/es/index.js +12 -1
- package/es/intl.js +145 -1
- package/es/isArray.js +323 -1
- package/es/isBoolean.js +67 -1
- package/es/isFunction.js +114 -1
- package/es/isNull.js +46 -1
- package/es/isNumber.js +141 -1
- package/es/isObject.js +193 -1
- package/es/isString.js +116 -1
- package/es/isSymbol.js +34 -1
- package/es/isType.js +14 -1
- package/es/typeOf.js +70 -1
- package/package.json +107 -62
- /package/es/{types/error.d.ts → error.d.ts} +0 -0
- /package/es/{types/index.d.ts → index.d.ts} +0 -0
- /package/es/{types/intl.d.ts → intl.d.ts} +0 -0
- /package/es/{types/isArray.d.ts → isArray.d.ts} +0 -0
- /package/es/{types/isBoolean.d.ts → isBoolean.d.ts} +0 -0
- /package/es/{types/isFunction.d.ts → isFunction.d.ts} +0 -0
- /package/es/{types/isNull.d.ts → isNull.d.ts} +0 -0
- /package/es/{types/isNumber.d.ts → isNumber.d.ts} +0 -0
- /package/es/{types/isObject.d.ts → isObject.d.ts} +0 -0
- /package/es/{types/isString.d.ts → isString.d.ts} +0 -0
- /package/es/{types/isSymbol.d.ts → isSymbol.d.ts} +0 -0
- /package/es/{types/isType.d.ts → isType.d.ts} +0 -0
- /package/es/{types/typeOf.d.ts → typeOf.d.ts} +0 -0
- /package/es/{types/types.d.ts → types.d.ts} +0 -0
package/es/isSymbol.js
CHANGED
|
@@ -1 +1,34 @@
|
|
|
1
|
-
import{typeOf
|
|
1
|
+
import { typeOf } from './typeOf.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 检测 Javascript 数据类型工具之: symbol
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* # 检测 `input` 是否是 `Symbol` 类型
|
|
8
|
+
*
|
|
9
|
+
* @param input - 待检测的数据,任意类型
|
|
10
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `symbol` ,且在 Typescript 中进行类型收缩
|
|
11
|
+
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { isSymbol } from '@mudbean/is';
|
|
15
|
+
*
|
|
16
|
+
* console.log(isSymbol(Symbol('test'))); // true
|
|
17
|
+
*
|
|
18
|
+
* // false (string 非 symbol)
|
|
19
|
+
* console.log(isSymbol('test'));
|
|
20
|
+
* // false (number 非 symbol)
|
|
21
|
+
* console.log(isSymbol(123));
|
|
22
|
+
* // false (boolean 非 symbol)
|
|
23
|
+
* console.log(isSymbol(true));
|
|
24
|
+
* // false (null 非 symbol)
|
|
25
|
+
* console.log(isSymbol(null));
|
|
26
|
+
* // false (undefined 非 symbol)
|
|
27
|
+
* console.log(isSymbol(undefined));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function isSymbol(input) {
|
|
31
|
+
return typeOf(input) === 'symbol';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { isSymbol };
|
package/es/isType.js
CHANGED
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `input` 类型收缩
|
|
3
|
+
*/
|
|
4
|
+
/** */
|
|
5
|
+
function isType(input, judgingConditions) {
|
|
6
|
+
if (judgingConditions === undefined)
|
|
7
|
+
return true;
|
|
8
|
+
if (typeof judgingConditions === 'function') {
|
|
9
|
+
return judgingConditions(input);
|
|
10
|
+
}
|
|
11
|
+
return judgingConditions;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { isType };
|
package/es/typeOf.js
CHANGED
|
@@ -1 +1,70 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* # 数据类型检测
|
|
3
|
+
*
|
|
4
|
+
* @param input - 待检测的数据,任意类型
|
|
5
|
+
* @returns 检测数据类型的字符串表示(小写字母)
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { typeOf } from '@mudbean/is';
|
|
9
|
+
*
|
|
10
|
+
* console.log(typeOf(1) === 'number'); // true
|
|
11
|
+
* console.log(typeOf('1') === 'string'); // true
|
|
12
|
+
* console.log(typeOf(null) === 'null'); // true
|
|
13
|
+
* console.log(typeOf(undefined) === 'undefined'); // true
|
|
14
|
+
* console.log(typeOf(true) === 'boolean'); // true
|
|
15
|
+
* console.log(typeOf(Symbol()) === 'symbol');
|
|
16
|
+
* console.log(typeOf(new Date()) === 'date');
|
|
17
|
+
* console.log(typeOf([]) === 'array');
|
|
18
|
+
* console.log(typeOf(new Set()) === 'set');
|
|
19
|
+
* console.log(typeOf(new Map()) === 'map');
|
|
20
|
+
* console.log(typeOf(new Error()) === 'error');
|
|
21
|
+
* console.log(typeOf(new Promise(() => {})) === 'promise');
|
|
22
|
+
* ...
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function typeOf(input) {
|
|
26
|
+
/**
|
|
27
|
+
* 使用 typeof 判断数据类型
|
|
28
|
+
*/
|
|
29
|
+
const typeofValue = typeof input;
|
|
30
|
+
// 检验出原始数据类型
|
|
31
|
+
if ('object' !== typeofValue && 'function' !== typeofValue) {
|
|
32
|
+
return typeofValue;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* # 通过 Object.prototype.toString.call(o) 判断数据类型
|
|
36
|
+
*/
|
|
37
|
+
const toStringCallValue = Reflect.apply(Object.prototype.toString, input, [])
|
|
38
|
+
.replace(/^.*\s(.*)]$/, '$1')
|
|
39
|
+
.toLowerCase();
|
|
40
|
+
if ('error' !== toStringCallValue) {
|
|
41
|
+
return toStringCallValue;
|
|
42
|
+
}
|
|
43
|
+
if (input instanceof SyntaxError) {
|
|
44
|
+
return 'syntaxerror';
|
|
45
|
+
}
|
|
46
|
+
if (input instanceof TypeError) {
|
|
47
|
+
return 'typeerror';
|
|
48
|
+
}
|
|
49
|
+
if (input instanceof URIError) {
|
|
50
|
+
return 'urierror';
|
|
51
|
+
}
|
|
52
|
+
if (input instanceof ReferenceError) {
|
|
53
|
+
return 'referenceerror';
|
|
54
|
+
}
|
|
55
|
+
// if (input instanceof InternalError) {
|
|
56
|
+
// return 'internalerror';
|
|
57
|
+
// }
|
|
58
|
+
if (input instanceof AggregateError) {
|
|
59
|
+
return 'aggregateerror';
|
|
60
|
+
}
|
|
61
|
+
if (input instanceof RangeError) {
|
|
62
|
+
return 'rangeerror';
|
|
63
|
+
}
|
|
64
|
+
if (input instanceof EvalError) {
|
|
65
|
+
return 'evalerror';
|
|
66
|
+
}
|
|
67
|
+
return 'error';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { typeOf };
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mudbean/is",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.4",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
|
-
"types": "es/
|
|
7
|
+
"types": "es/index.d.ts",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "泥豆君",
|
|
10
10
|
"email": "Mr.MudBean@outlook.com",
|
|
11
|
-
"url": "https://
|
|
11
|
+
"url": "https://mudbean.cn"
|
|
12
12
|
},
|
|
13
13
|
"description": "JavaScript/TypeScript 的类型检测工具,支持 TypeScript 类型收缩",
|
|
14
14
|
"sideEffects": false,
|
|
@@ -19,95 +19,140 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"cjs",
|
|
21
21
|
"es",
|
|
22
|
-
"es/types",
|
|
23
22
|
"CHANGELOG.md",
|
|
24
23
|
"README.md",
|
|
25
24
|
"LICENSE"
|
|
26
25
|
],
|
|
27
26
|
"exports": {
|
|
28
27
|
".": {
|
|
29
|
-
"import":
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
"import": {
|
|
29
|
+
"require": "./cjs/index.js",
|
|
30
|
+
"types": "./es/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"default": "./cjs/index.js",
|
|
34
|
+
"types": "./es/index.d.ts"
|
|
35
|
+
}
|
|
33
36
|
},
|
|
34
37
|
"./error": {
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"require": "./cjs/index.js",
|
|
44
|
-
"types": "./es/types/index.d.ts"
|
|
38
|
+
"import": {
|
|
39
|
+
"default": "./es/error.js",
|
|
40
|
+
"types": "./es/error.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"default": "./cjs/error.js",
|
|
44
|
+
"types": "./es/error.d.ts"
|
|
45
|
+
}
|
|
45
46
|
},
|
|
46
47
|
"./intl": {
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
"import": {
|
|
49
|
+
"default": "./es/intl.js",
|
|
50
|
+
"types": "./es/intl.d.ts"
|
|
51
|
+
},
|
|
52
|
+
"require": {
|
|
53
|
+
"default": "./cjs/intl.js",
|
|
54
|
+
"types": "./es/intl.d.ts"
|
|
55
|
+
}
|
|
51
56
|
},
|
|
52
57
|
"./isArray": {
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
58
|
+
"import": {
|
|
59
|
+
"default": "./es/isArray.js",
|
|
60
|
+
"types": "./es/isArray.d.ts"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"default": "./cjs/isArray.js",
|
|
64
|
+
"types": "./es/isArray.d.ts"
|
|
65
|
+
}
|
|
57
66
|
},
|
|
58
67
|
"./isBoolean": {
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
"import": {
|
|
69
|
+
"default": "./es/isBoolean.js",
|
|
70
|
+
"types": "./es/isBoolean.d.ts"
|
|
71
|
+
},
|
|
72
|
+
"require": {
|
|
73
|
+
"default": "./cjs/isBoolean.js",
|
|
74
|
+
"types": "./es/isBoolean.d.ts"
|
|
75
|
+
}
|
|
63
76
|
},
|
|
64
77
|
"./isFunction": {
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
78
|
+
"import": {
|
|
79
|
+
"default": "./es/isFunction.js",
|
|
80
|
+
"types": "./es/isFunction.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"require": {
|
|
83
|
+
"default": "./cjs/isFunction.js",
|
|
84
|
+
"types": "./es/isFunction.d.ts"
|
|
85
|
+
}
|
|
69
86
|
},
|
|
70
87
|
"./isNull": {
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
"import": {
|
|
89
|
+
"default": "./es/isNull.js",
|
|
90
|
+
"types": "./es/isNull.d.ts"
|
|
91
|
+
},
|
|
92
|
+
"require": {
|
|
93
|
+
"default": "./cjs/isNull.js",
|
|
94
|
+
"types": "./es/isNull.d.ts"
|
|
95
|
+
}
|
|
75
96
|
},
|
|
76
97
|
"./isNumber": {
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
98
|
+
"import": {
|
|
99
|
+
"default": "./es/isNumber.js",
|
|
100
|
+
"types": "./es/isNumber.d.ts"
|
|
101
|
+
},
|
|
102
|
+
"require": {
|
|
103
|
+
"default": "./cjs/isNumber.js",
|
|
104
|
+
"types": "./es/isNumber.d.ts"
|
|
105
|
+
}
|
|
81
106
|
},
|
|
82
107
|
"./isObject": {
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
108
|
+
"import": {
|
|
109
|
+
"default": "./es/isObject.js",
|
|
110
|
+
"types": "./es/isObject.d.ts"
|
|
111
|
+
},
|
|
112
|
+
"require": {
|
|
113
|
+
"default": "./cjs/isObject.js",
|
|
114
|
+
"types": "./es/isObject.d.ts"
|
|
115
|
+
}
|
|
87
116
|
},
|
|
88
117
|
"./isString": {
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
118
|
+
"import": {
|
|
119
|
+
"default": "./es/isString.js",
|
|
120
|
+
"types": "./es/isString.d.ts"
|
|
121
|
+
},
|
|
122
|
+
"require": {
|
|
123
|
+
"default": "./cjs/isString.js",
|
|
124
|
+
"types": "./es/isString.d.ts"
|
|
125
|
+
}
|
|
93
126
|
},
|
|
94
127
|
"./isSymbol": {
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
128
|
+
"import": {
|
|
129
|
+
"default": "./es/isSymbol.js",
|
|
130
|
+
"types": "./es/isSymbol.d.ts"
|
|
131
|
+
},
|
|
132
|
+
"require": {
|
|
133
|
+
"default": "./cjs/isSymbol.js",
|
|
134
|
+
"types": "./es/isSymbol.d.ts"
|
|
135
|
+
}
|
|
99
136
|
},
|
|
100
137
|
"./isType": {
|
|
101
|
-
"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
138
|
+
"import": {
|
|
139
|
+
"default": "./es/isType.js",
|
|
140
|
+
"types": "./es/isType.d.ts"
|
|
141
|
+
},
|
|
142
|
+
"require": {
|
|
143
|
+
"default": "./cjs/isType.js",
|
|
144
|
+
"types": "./es/isType.d.ts"
|
|
145
|
+
}
|
|
105
146
|
},
|
|
106
147
|
"./typeOf": {
|
|
107
|
-
"
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
148
|
+
"import": {
|
|
149
|
+
"default": "./es/typeOf.js",
|
|
150
|
+
"types": "./es/typeOf.d.ts"
|
|
151
|
+
},
|
|
152
|
+
"require": {
|
|
153
|
+
"default": "./cjs/typeOf.js",
|
|
154
|
+
"types": "./es/typeOf.d.ts"
|
|
155
|
+
}
|
|
111
156
|
}
|
|
112
157
|
},
|
|
113
158
|
"keywords": [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|