@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/CHANGELOG.md
CHANGED
package/cjs/error.js
CHANGED
|
@@ -1 +1,211 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typeOf = require('./typeOf.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 检测 Javascript 数据类型工具之: error
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* # 检测 `input` 是否是 `Error` 类型
|
|
10
|
+
*
|
|
11
|
+
* @param input - 待检测的数据,任意类型
|
|
12
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Error` ,且在 Typescript 中进行类型收缩
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { isError } from '@mudbean/is';
|
|
17
|
+
*
|
|
18
|
+
* console.log(isError(new Error('test'))); // true
|
|
19
|
+
*
|
|
20
|
+
* // false (类型不符)
|
|
21
|
+
* console.log(isError(new EvalError('test')));
|
|
22
|
+
* // false (类型不符)
|
|
23
|
+
* console.log(isError(new RangeError('test')));
|
|
24
|
+
* // false (类型不符)
|
|
25
|
+
* console.log(isError(new ReferenceError('test')));
|
|
26
|
+
*
|
|
27
|
+
* // false (类型不符)
|
|
28
|
+
* console.log(isError({ message: 'test' }));
|
|
29
|
+
* ```
|
|
30
|
+
* @since 0.1.4
|
|
31
|
+
*/
|
|
32
|
+
function isError(input) {
|
|
33
|
+
return typeOf.typeOf(input) === 'error';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* # 检测 `input` 是否是 `EvalError` 类型
|
|
37
|
+
*
|
|
38
|
+
* @param input - 待检测的数据,任意类型
|
|
39
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `EvalError` ,且在 Typescript 中进行类型收缩
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { isEvalError } from '@mudbean/is';
|
|
44
|
+
*
|
|
45
|
+
* console.log(isEvalError(new EvalError('test'))); // true
|
|
46
|
+
*
|
|
47
|
+
* // false (类型非 EvalError)
|
|
48
|
+
* console.log(isEvalError(new Error('test')));
|
|
49
|
+
* // false (类型非 EvalError)
|
|
50
|
+
* console.log(isEvalError(new TypeError('test')));
|
|
51
|
+
* // false (类型非 EvalError)
|
|
52
|
+
* console.log(isEvalError(new RangeError('test')));
|
|
53
|
+
*
|
|
54
|
+
* // false (类型非 EvalError)
|
|
55
|
+
* console.log(isEvalError({ message: 'test' }));
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
function isEvalError(input) {
|
|
59
|
+
return typeOf.typeOf(input) === 'evalerror';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* # 检测 `input 是否是 `RangeError` 类型
|
|
63
|
+
*
|
|
64
|
+
* @param input - 待检测的数据,任意类型
|
|
65
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `RangeError` ,且在 Typescript 中进行类型收缩
|
|
66
|
+
* @example
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* import { isRangeError } from '@mudbean/is';
|
|
70
|
+
*
|
|
71
|
+
* console.log(isRangeError(new RangeError('test'))); // true
|
|
72
|
+
*
|
|
73
|
+
* // false (类型非 RangeError
|
|
74
|
+
* console.log(isRangeError(new Error('test')));
|
|
75
|
+
* // false (类型非 RangeError)
|
|
76
|
+
* console.log(isRangeError(new TypeError('test')));
|
|
77
|
+
* // false (类型非 RangeError)
|
|
78
|
+
* console.log(isRangeError(new SyntaxError('test')));
|
|
79
|
+
*
|
|
80
|
+
* // false (类型非 RangeError)
|
|
81
|
+
* console.log(isRangeError('test'));
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function isRangeError(input) {
|
|
85
|
+
return typeOf.typeOf(input) === 'rangeerror';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* # 检测 `input` 是否是 `ReferenceError` 类型
|
|
89
|
+
*
|
|
90
|
+
* @param input - 待检测的数据,任意类型
|
|
91
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `ReferenceError` ,且在 Typescript 中进行类型收缩
|
|
92
|
+
* @example
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { isReferenceError } from '@mudbean/is';
|
|
96
|
+
*
|
|
97
|
+
* console.log(isReferenceError(new ReferenceError('test'))); // true
|
|
98
|
+
*
|
|
99
|
+
* // false (类型非 ReferenceError)
|
|
100
|
+
* console.log(isReferenceError(new Error('test')));
|
|
101
|
+
* // false (类型非 ReferenceError)
|
|
102
|
+
* console.log(isReferenceError(new TypeError('test')));
|
|
103
|
+
* // false (类型非 ReferenceError)
|
|
104
|
+
* console.log(isReferenceError(new SyntaxError('test')));
|
|
105
|
+
*
|
|
106
|
+
* // false (类型非 ReferenceError)
|
|
107
|
+
* console.log(isReferenceError('test');
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
function isReferenceError(input) {
|
|
111
|
+
return typeOf.typeOf(input) === 'referenceerror';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* # 检测 `input` 是否是 `SyntaxError` 类型
|
|
115
|
+
*
|
|
116
|
+
* @param input - 待检测的数据,任意类型
|
|
117
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `SyntaxError` ,且在 Typescript 中进行类型收缩
|
|
118
|
+
* @example
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { isSyntaxError } from '@mudbean/is';
|
|
122
|
+
*
|
|
123
|
+
* console.log(isSyntaxError(new SyntaxError('test'))); // true
|
|
124
|
+
*
|
|
125
|
+
* // false (类型非 SyntaxError)
|
|
126
|
+
* console.log(isSyntaxError(new Error('test')));
|
|
127
|
+
* // false (类型非 SyntaxError)
|
|
128
|
+
* console.log(isSyntaxError(new TypeError('test')));
|
|
129
|
+
* // false (类型非 SyntaxError)
|
|
130
|
+
* console.log(isSyntaxError(new ReferenceError('test')));
|
|
131
|
+
*
|
|
132
|
+
* // false (类型非 SyntaxError)
|
|
133
|
+
* console.log(isSyntaxError('test'));
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
function isSyntaxError(input) {
|
|
137
|
+
return typeOf.typeOf(input) === 'syntaxerror';
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* # 检测 `input` 是否是 `TypeError` 类型
|
|
141
|
+
*
|
|
142
|
+
* @param input - 待检测的数据,任意类型
|
|
143
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `TypeError` ,且在 Typescript 中进行类型收缩
|
|
144
|
+
* @example
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* import { isTypeError } from '@mudbean/is';
|
|
148
|
+
*
|
|
149
|
+
* console.log(isTypeError(new TypeError('test'))); // true
|
|
150
|
+
*
|
|
151
|
+
* // false (类型非 TypeError)
|
|
152
|
+
* console.log(isTypeError(new Error('test')));
|
|
153
|
+
* // false (类型非 TypeError)
|
|
154
|
+
* console.log(isTypeError(new SyntaxError('test')));
|
|
155
|
+
* // false (类型非 TypeError)
|
|
156
|
+
* console.log(isTypeError(new ReferenceError('test')));
|
|
157
|
+
* // false (类型非 TypeError)
|
|
158
|
+
* console.log(isTypeError(new EvalError('test')));
|
|
159
|
+
*
|
|
160
|
+
* // false (类型非 TypeError)
|
|
161
|
+
* console.log(isTypeError('test');
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
function isTypeError(input) {
|
|
165
|
+
return typeOf.typeOf(input) === 'typeerror';
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* # 检测 `input` 是否是 `URIError` 类型
|
|
169
|
+
*
|
|
170
|
+
* @param input - 待检测的数据,任意类型
|
|
171
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `URIError` ,且在 Typescript 中进行类型收缩
|
|
172
|
+
* @example
|
|
173
|
+
*
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { isURIError } from '@mudbean/is';
|
|
176
|
+
*
|
|
177
|
+
* console.log(isURIError(new URIError('test'))); // true
|
|
178
|
+
*
|
|
179
|
+
* console.log(isURIError(new Error('test'))); // false
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function isURIError(input) {
|
|
183
|
+
return typeOf.typeOf(input) === 'urierror';
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* # 检测 `input` 是否是 `AggregateError` 类型
|
|
187
|
+
*
|
|
188
|
+
* @param input - 待检测的数据,任意类型
|
|
189
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `AggregateError` ,且在 Typescript 中进行类型收缩
|
|
190
|
+
* @example
|
|
191
|
+
*
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { isAggregateError } from '@mudbean/is';
|
|
194
|
+
*
|
|
195
|
+
* console.log(isAggregateError(new AggregateError([]))); // true
|
|
196
|
+
*
|
|
197
|
+
* console.log(isAggregateError(new Error('test'))); // false
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
function isAggregateError(input) {
|
|
201
|
+
return typeOf.typeOf(input) === 'aggregateerror';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
exports.isAggregateError = isAggregateError;
|
|
205
|
+
exports.isError = isError;
|
|
206
|
+
exports.isEvalError = isEvalError;
|
|
207
|
+
exports.isRangeError = isRangeError;
|
|
208
|
+
exports.isReferenceError = isReferenceError;
|
|
209
|
+
exports.isSyntaxError = isSyntaxError;
|
|
210
|
+
exports.isTypeError = isTypeError;
|
|
211
|
+
exports.isURIError = isURIError;
|
package/cjs/index.js
CHANGED
|
@@ -1 +1,76 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typeOf = require('./typeOf.js');
|
|
4
|
+
var isString = require('./isString.js');
|
|
5
|
+
var isNumber = require('./isNumber.js');
|
|
6
|
+
var isBoolean = require('./isBoolean.js');
|
|
7
|
+
var isNull = require('./isNull.js');
|
|
8
|
+
var isFunction = require('./isFunction.js');
|
|
9
|
+
var isArray = require('./isArray.js');
|
|
10
|
+
var isObject = require('./isObject.js');
|
|
11
|
+
var isSymbol = require('./isSymbol.js');
|
|
12
|
+
var intl = require('./intl.js');
|
|
13
|
+
var error = require('./error.js');
|
|
14
|
+
var isType = require('./isType.js');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.typeOf = typeOf.typeOf;
|
|
19
|
+
exports.isBusinessEmptyString = isString.isBusinessEmptyString;
|
|
20
|
+
exports.isEmptyString = isString.isEmptyString;
|
|
21
|
+
exports.isRegExp = isString.isRegExp;
|
|
22
|
+
exports.isString = isString.isString;
|
|
23
|
+
exports.isBigInt = isNumber.isBigInt;
|
|
24
|
+
exports.isNaN = isNumber.isNaN;
|
|
25
|
+
exports.isNegativeInteger = isNumber.isNegativeInteger;
|
|
26
|
+
exports.isNumber = isNumber.isNumber;
|
|
27
|
+
exports.isPositiveInteger = isNumber.isPositiveInteger;
|
|
28
|
+
exports.isZero = isNumber.isZero;
|
|
29
|
+
exports.isBoolean = isBoolean.isBoolean;
|
|
30
|
+
exports.isFalse = isBoolean.isFalse;
|
|
31
|
+
exports.isTrue = isBoolean.isTrue;
|
|
32
|
+
exports.isNull = isNull.isNull;
|
|
33
|
+
exports.isUndefined = isNull.isUndefined;
|
|
34
|
+
exports.isAsyncFunction = isFunction.isAsyncFunction;
|
|
35
|
+
exports.isFunction = isFunction.isFunction;
|
|
36
|
+
exports.isGenerator = isFunction.isGenerator;
|
|
37
|
+
exports.isGeneratorFunction = isFunction.isGeneratorFunction;
|
|
38
|
+
exports.isPromise = isFunction.isPromise;
|
|
39
|
+
exports.isArray = isArray.isArray;
|
|
40
|
+
exports.isArrayBuffer = isArray.isArrayBuffer;
|
|
41
|
+
exports.isBigInt64Array = isArray.isBigInt64Array;
|
|
42
|
+
exports.isBigUint64Array = isArray.isBigUint64Array;
|
|
43
|
+
exports.isEmptyArray = isArray.isEmptyArray;
|
|
44
|
+
exports.isFloat32Array = isArray.isFloat32Array;
|
|
45
|
+
exports.isFloat64Array = isArray.isFloat64Array;
|
|
46
|
+
exports.isInt16Array = isArray.isInt16Array;
|
|
47
|
+
exports.isInt8Array = isArray.isInt8Array;
|
|
48
|
+
exports.isSet = isArray.isSet;
|
|
49
|
+
exports.isSharedArrayBuffer = isArray.isSharedArrayBuffer;
|
|
50
|
+
exports.isUint16Array = isArray.isUint16Array;
|
|
51
|
+
exports.isUint32Array = isArray.isUint32Array;
|
|
52
|
+
exports.isUint8Array = isArray.isUint8Array;
|
|
53
|
+
exports.isUint8ClampedArray = isArray.isUint8ClampedArray;
|
|
54
|
+
exports.isWeakSet = isArray.isWeakSet;
|
|
55
|
+
exports.isDataView = isObject.isDataView;
|
|
56
|
+
exports.isDate = isObject.isDate;
|
|
57
|
+
exports.isEmptyObject = isObject.isEmptyObject;
|
|
58
|
+
exports.isMap = isObject.isMap;
|
|
59
|
+
exports.isPlainObject = isObject.isPlainObject;
|
|
60
|
+
exports.isWeakMap = isObject.isWeakMap;
|
|
61
|
+
exports.isSymbol = isSymbol.isSymbol;
|
|
62
|
+
exports.isIntlCollator = intl.isIntlCollator;
|
|
63
|
+
exports.isIntlDateTimeFormat = intl.isIntlDateTimeFormat;
|
|
64
|
+
exports.isIntlDisplayNames = intl.isIntlDisplayNames;
|
|
65
|
+
exports.isIntlListFormat = intl.isIntlListFormat;
|
|
66
|
+
exports.isIntlLocale = intl.isIntlLocale;
|
|
67
|
+
exports.isIntlNumberFormat = intl.isIntlNumberFormat;
|
|
68
|
+
exports.isAggregateError = error.isAggregateError;
|
|
69
|
+
exports.isError = error.isError;
|
|
70
|
+
exports.isEvalError = error.isEvalError;
|
|
71
|
+
exports.isRangeError = error.isRangeError;
|
|
72
|
+
exports.isReferenceError = error.isReferenceError;
|
|
73
|
+
exports.isSyntaxError = error.isSyntaxError;
|
|
74
|
+
exports.isTypeError = error.isTypeError;
|
|
75
|
+
exports.isURIError = error.isURIError;
|
|
76
|
+
exports.isType = isType.isType;
|
package/cjs/intl.js
CHANGED
|
@@ -1 +1,152 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var typeOf = require('./typeOf.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 检测 Javascript 数据类型工具之: Intl
|
|
7
|
+
* @author Mr.MudBean <Mr.MudBean@outlook.com>
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* # 检测 `input` 是否是 `Intl.Collator` 类型
|
|
11
|
+
*
|
|
12
|
+
* @param input - 待检测的数据,任意类型
|
|
13
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Intl.Collator` ,且在 Typescript 中进行类型收缩
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { isIntlCollator } from '@mudbean/is';
|
|
18
|
+
*
|
|
19
|
+
* console.log(isIntlCollator(new Intl.Collator())); // true
|
|
20
|
+
*
|
|
21
|
+
* console.log(isIntlCollator(new Intl.DateTimeFormat())); // false
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function isIntlCollator(input) {
|
|
25
|
+
return typeOf.typeOf(input) === 'intl.collator';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* # 检测 `input` 是否是 `Intl.DateTimeFormat` 类型
|
|
29
|
+
*
|
|
30
|
+
* @param input - 待检测的数据,任意类型
|
|
31
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Intl.DateTimeFormat` ,且在 Typescript 中进行类型收缩
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { isIntlDateTimeFormat } from '@mudbean/is';
|
|
37
|
+
*
|
|
38
|
+
* console.log(isIntlDateTimeFormat(new Intl.DateTimeFormat())); // true
|
|
39
|
+
*
|
|
40
|
+
* console.log(isIntlDateTimeFormat('hello')); // false
|
|
41
|
+
* console.log(isIntlDateTimeFormat(1)); // false
|
|
42
|
+
* console.log(isIntlDateTimeFormat(true)); // false
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function isIntlDateTimeFormat(input) {
|
|
46
|
+
return typeOf.typeOf(input) === 'intl.datetimeformat';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* # 检测 `input` 是否是 `Intl.DisplayNames` 类型
|
|
50
|
+
*
|
|
51
|
+
* @param input - 待检测的数据,任意类型
|
|
52
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Intl.DisplayNames` ,且在 Typescript 中进行类型收缩
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { isIntlDisplayNames } from '@mudbean/is';
|
|
57
|
+
*
|
|
58
|
+
* console.log(isIntlDisplayNames(new Intl.DisplayNames())); // true
|
|
59
|
+
*
|
|
60
|
+
* console.log(isIntlDisplayNames(new Intl.Locale())); // false
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
function isIntlDisplayNames(input) {
|
|
64
|
+
return typeOf.typeOf(input) === 'intl.displaynames';
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* #检测 `input` 是否是 `Intl.DurationFormat` 类型
|
|
68
|
+
*
|
|
69
|
+
* @param input - 待检测的数据,任意类型
|
|
70
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Intl.DurationFormat` ,且在 Typescript 中进行类型收缩
|
|
71
|
+
* @example
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { isIntlDurationFormat } from '@mudbean/is';
|
|
75
|
+
*
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
*/
|
|
79
|
+
// export function isIntlDurationFormat(
|
|
80
|
+
// input: any,
|
|
81
|
+
// ): input is Intl.DurationFormat {
|
|
82
|
+
// return typeOf(input) === 'intl.durationformat';
|
|
83
|
+
// }
|
|
84
|
+
/**
|
|
85
|
+
* # 检测 `input` 是否是 `Intl.ListFormat` 类型
|
|
86
|
+
* @param input - 待检测的数据,任意类型
|
|
87
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Intl.ListFormat` ,且在 Typescript 中进行类型收缩
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { isIntlListFormat } from '@mudbean/is';
|
|
92
|
+
*
|
|
93
|
+
* console.log(isIntlListFormat(new Intl.ListFormat())); // true
|
|
94
|
+
*
|
|
95
|
+
* console.log(isIntlListFormat(new Intl.DateTimeFormat())); // false
|
|
96
|
+
* console.log(isIntlListFormat(1)); // false
|
|
97
|
+
* console.log(isIntlListFormat('1')); // false
|
|
98
|
+
* console.log(isIntlListFormat(null)); // false
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
function isIntlListFormat(input) {
|
|
102
|
+
return typeOf.typeOf(input) === 'intl.listformat';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* # 检测 `input` 是否是 `Intl.Locale` 类型
|
|
106
|
+
*
|
|
107
|
+
* @param input - 待检测的数据,任意类型
|
|
108
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Intl.Locale` ,且在 Typescript 中进行类型收缩
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { isIntlLocale } from '@mudbean/is';
|
|
114
|
+
*
|
|
115
|
+
* console.log(isIntlLocale(new Intl.Locale())); // true
|
|
116
|
+
*
|
|
117
|
+
* console.log(isIntlLocale('en')); // false
|
|
118
|
+
* console.log(isIntlLocale(1)); // false
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
function isIntlLocale(input) {
|
|
122
|
+
return typeOf.typeOf(input) === 'intl.locale';
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* # 检测 `input` 是否是 `Intl.NumberFormat` 类型
|
|
126
|
+
*
|
|
127
|
+
* @param input - 待检测的数据,任意类型
|
|
128
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Intl.NumberFormat` ,且在 Typescript 中进行类型收缩
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
*
|
|
132
|
+
* ```ts
|
|
133
|
+
* import { isIntlNumberFormat } from '@mudbean/is';
|
|
134
|
+
*
|
|
135
|
+
* console.log(isIntlNumberFormat(new Intl.NumberFormat())); // true
|
|
136
|
+
*
|
|
137
|
+
* console.log(isIntlNumberFormat(123)); // false
|
|
138
|
+
* console.log(isIntlNumberFormat('123')); // false
|
|
139
|
+
* console.log(isIntlNumberFormat(new Date())); // false
|
|
140
|
+
* console.log(isIntlNumberFormat(new Date(0))); // false
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
function isIntlNumberFormat(input) {
|
|
144
|
+
return typeOf.typeOf(input) === 'intl.numberformat';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
exports.isIntlCollator = isIntlCollator;
|
|
148
|
+
exports.isIntlDateTimeFormat = isIntlDateTimeFormat;
|
|
149
|
+
exports.isIntlDisplayNames = isIntlDisplayNames;
|
|
150
|
+
exports.isIntlListFormat = isIntlListFormat;
|
|
151
|
+
exports.isIntlLocale = isIntlLocale;
|
|
152
|
+
exports.isIntlNumberFormat = isIntlNumberFormat;
|