@mudbean/is 2.0.2
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 +134 -0
- package/LICENSE +16 -0
- package/README.md +136 -0
- package/cjs/error.js +1 -0
- package/cjs/index.js +1 -0
- package/cjs/intl.js +1 -0
- package/cjs/isArray.js +1 -0
- package/cjs/isBoolean.js +1 -0
- package/cjs/isFunction.js +1 -0
- package/cjs/isNull.js +1 -0
- package/cjs/isNumber.js +1 -0
- package/cjs/isObject.js +1 -0
- package/cjs/isString.js +1 -0
- package/cjs/isSymbol.js +1 -0
- package/cjs/isType.js +1 -0
- package/cjs/typeOf.js +1 -0
- package/es/error.js +1 -0
- package/es/index.js +1 -0
- package/es/intl.js +1 -0
- package/es/isArray.js +1 -0
- package/es/isBoolean.js +1 -0
- package/es/isFunction.js +1 -0
- package/es/isNull.js +1 -0
- package/es/isNumber.js +1 -0
- package/es/isObject.js +1 -0
- package/es/isString.js +1 -0
- package/es/isSymbol.js +1 -0
- package/es/isType.js +1 -0
- package/es/typeOf.js +1 -0
- package/es/types/error.d.ts +179 -0
- package/es/types/index.d.ts +13 -0
- package/es/types/intl.d.ts +120 -0
- package/es/types/isArray.d.ts +281 -0
- package/es/types/isBoolean.d.ts +54 -0
- package/es/types/isFunction.d.ts +97 -0
- package/es/types/isNull.d.ts +40 -0
- package/es/types/isNumber.d.ts +125 -0
- package/es/types/isObject.d.ts +174 -0
- package/es/types/isString.d.ts +101 -0
- package/es/types/isSymbol.d.ts +25 -0
- package/es/types/isType.d.ts +77 -0
- package/es/types/typeOf.d.ts +29 -0
- package/es/types/types.d.ts +4 -0
- package/package.json +133 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# 版本日志
|
|
2
|
+
|
|
3
|
+
## 2.0.2 (2026-6-9)
|
|
4
|
+
|
|
5
|
+
- 维护注释信息
|
|
6
|
+
|
|
7
|
+
## 2.0.1 (2026-3-24)
|
|
8
|
+
|
|
9
|
+
- 维护注释信息
|
|
10
|
+
|
|
11
|
+
## v2.0.0 (2025-12-24)
|
|
12
|
+
|
|
13
|
+
- 更新包信息
|
|
14
|
+
|
|
15
|
+
## v1.1.0 (2025-12-24)
|
|
16
|
+
|
|
17
|
+
一件超级尴尬的事,打包的构建 package.json 文件没有包含 `sideEffects: false` ,消费端无法进行正确的 Tree Shaking
|
|
18
|
+
|
|
19
|
+
## v1.0.8-beta.0 (2025-9-7)
|
|
20
|
+
|
|
21
|
+
- for WechatMiniprogram
|
|
22
|
+
|
|
23
|
+
## v1.0.7 (2025-7-25)
|
|
24
|
+
|
|
25
|
+
- 修复文档
|
|
26
|
+
|
|
27
|
+
## v1.0.6 (2025-7-25)
|
|
28
|
+
|
|
29
|
+
- 修复文档
|
|
30
|
+
|
|
31
|
+
## v1.0.6-test.0 (2025-7-24)
|
|
32
|
+
|
|
33
|
+
- 么事
|
|
34
|
+
|
|
35
|
+
## v1.0.5 (2025-7-14)
|
|
36
|
+
|
|
37
|
+
- no unknown
|
|
38
|
+
|
|
39
|
+
## v1.0.4 (2025-7-9)
|
|
40
|
+
|
|
41
|
+
- 移除了 `isEmptyArray` 的类型检测
|
|
42
|
+
|
|
43
|
+
## v1.0.3 (2025-7-4)
|
|
44
|
+
|
|
45
|
+
- `isEmptyArray` 添加了范性,在数组为空数组时依旧保持原类型
|
|
46
|
+
|
|
47
|
+
## v1.0.2 (2025-6-16)
|
|
48
|
+
|
|
49
|
+
- 文档维护
|
|
50
|
+
|
|
51
|
+
## v1.0.1 (2025-5-29)
|
|
52
|
+
|
|
53
|
+
- `isType` 的第二参数现可接受一个参数,该参数可被用于判断后的该值类型来使用(见函数注释)
|
|
54
|
+
|
|
55
|
+
## v1.0.0 (5 🈷️ 24 日 2025 年)
|
|
56
|
+
|
|
57
|
+
由于版本号长期处于 1 一下,导致同一个项目多个版本
|
|
58
|
+
|
|
59
|
+
- 添加了 `isZero`
|
|
60
|
+
- 添加了 `isNegativeInteger`
|
|
61
|
+
- 添加了 `isPositiveInteger`
|
|
62
|
+
|
|
63
|
+
这三个看似有用实则没用的东西
|
|
64
|
+
|
|
65
|
+
## v0.3.1-beta.0 (5 🈷️ 10 日 2025 年)
|
|
66
|
+
|
|
67
|
+
- 好想一不小心就
|
|
68
|
+
|
|
69
|
+
## v0.3.0 (5 🈷️ 9 日 2025 年)
|
|
70
|
+
|
|
71
|
+
### ✨ 新增函数
|
|
72
|
+
|
|
73
|
+
- 添加了 `isTrue` 函数,用于判断值是否是 `true`
|
|
74
|
+
- 添加了 `isFalse` 函数,用于判断值是否是 `false`
|
|
75
|
+
- 添加了 `isEmptyArray` 函数,用于判断值是否是空数组
|
|
76
|
+
- 添加了 `isEmptyObject` 函数,用于判断值是否是空对象
|
|
77
|
+
|
|
78
|
+
## v0.2.1 (5 🈷️ 9 日 20
|
|
79
|
+
|
|
80
|
+
- 文档修复
|
|
81
|
+
|
|
82
|
+
## 0.2.0(4 月 9 日 2025 年)
|
|
83
|
+
|
|
84
|
+
### 功能添加 ✨
|
|
85
|
+
|
|
86
|
+
- 添加了 `isEmptyString` 函数,用于判断字符串是否为空字符串,且不包含空格
|
|
87
|
+
- 添加了 `isBusinessEmptyString`,用于判断字符串是否为空字符串,且包含空格
|
|
88
|
+
|
|
89
|
+
## 0.1.5(3 月 27 日 2025 年)
|
|
90
|
+
|
|
91
|
+
- 多次折腾,回归中文注释
|
|
92
|
+
|
|
93
|
+
## 0.1.4(3 月 21 日 2025 年)
|
|
94
|
+
|
|
95
|
+
- 通过 github actions 构建和发布包
|
|
96
|
+
|
|
97
|
+
## 0.1.0(3 月 21 日 2025 年)
|
|
98
|
+
|
|
99
|
+
- 修改了测试率徽章的显示方式
|
|
100
|
+
|
|
101
|
+
## 0.0.7 (3 月 19 日 2025 年)
|
|
102
|
+
|
|
103
|
+
- 维护了注释
|
|
104
|
+
|
|
105
|
+
## 0.0.6 (3 月 19 日 2025 年)
|
|
106
|
+
|
|
107
|
+
- 修复了 `isEvalError`、`isRangeError`、`isReferenceError`、`isSyntaxError`、`isTypeError`、`isURIError`、`isAggregateError` 返回值不准确的问题
|
|
108
|
+
- 添加了 `isType` 函数
|
|
109
|
+
|
|
110
|
+
## 0.0.5 (3 月 16 日 2025 年)
|
|
111
|
+
|
|
112
|
+
- 上一个版本意外移除了打包的依赖 `tslib` 导致打包异常而未察觉,已修复
|
|
113
|
+
|
|
114
|
+
## 0.0.4 (3 月 13 日 2025 年)
|
|
115
|
+
|
|
116
|
+
- 添加测试率的徽章
|
|
117
|
+
|
|
118
|
+
## 0.0.3 (3 月 13 日 2025 年)
|
|
119
|
+
|
|
120
|
+
- 修复了已知 bug
|
|
121
|
+
|
|
122
|
+
## 0.0.2 (3 月 7 日 2025 年)
|
|
123
|
+
|
|
124
|
+
- 使用 [shields](https://img.shields.io) 构建徽章
|
|
125
|
+
|
|
126
|
+
## 0.0.1 (3 月 7 日 2025 年)
|
|
127
|
+
|
|
128
|
+
- 移除了 `isAtomics` 函数。因为 `Atomics` 仅是一个函数集合,没有实例。同样的还有 `Math、JSON、Reflect、Intl`
|
|
129
|
+
- 移除了 `isWindow` 函数
|
|
130
|
+
- 优化了 `typeOf` 函数,检测 `asyncFunction`、`generator`、`generatorFunction` 更精准
|
|
131
|
+
|
|
132
|
+
## 0.0.0 (3 月 4 日 2025 年)
|
|
133
|
+
|
|
134
|
+
- 初始化项目
|
package/LICENSE
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) <2025> <Mr.MudBean>
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# is
|
|
2
|
+
|
|
3
|
+
[&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/@mudbean/is) [?logo=github>)](https://github.com/MrMudBean/is/issues)
|
|
4
|
+
|
|
5
|
+
一个简单的类型判断工具
|
|
6
|
+
|
|
7
|
+
## 使用
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { typeOf } from '@mudbean/is';
|
|
11
|
+
|
|
12
|
+
const num = 1;
|
|
13
|
+
|
|
14
|
+
if (typeOf(num) === 'number') {
|
|
15
|
+
console.log('num is number');
|
|
16
|
+
} else {
|
|
17
|
+
console.log('num is not number');
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 使用 `ts` 中的 is 类型判断来进行类型安全收缩
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { isString, isNumber } from '@mudbean/is';
|
|
25
|
+
|
|
26
|
+
function doSomething(value: string | number) {
|
|
27
|
+
if (isString(value)) {
|
|
28
|
+
value.toLocaleUpperCase();
|
|
29
|
+
} else if (isNumber(value)) {
|
|
30
|
+
value.toFixed(2);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
doSomething('hello'); // HELLO
|
|
35
|
+
doSomething(1); // 1.00
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 向 `as` 说 'no'
|
|
39
|
+
|
|
40
|
+
vitest
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { isType } from '@mudbean/is';
|
|
44
|
+
|
|
45
|
+
interface Person {
|
|
46
|
+
name: string;
|
|
47
|
+
age: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function doSomething(value: string | number | boolean | ) {
|
|
52
|
+
|
|
53
|
+
// 将判断用作类型判断
|
|
54
|
+
if (isType<Person>(value, () => (value && value.name === 'Tom' && value.age === 18))) {
|
|
55
|
+
console.log('value is Person');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// 作为类型判定
|
|
60
|
+
if (isType<string>(value)) {
|
|
61
|
+
value.toLocaleUpperCase();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// 使用判断力
|
|
66
|
+
if (isType<boolean>(value, Boolean(value) === true )) {
|
|
67
|
+
console.log('value is true');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 文档提供类型检测
|
|
74
|
+
|
|
75
|
+
- `isString` 字符串、`String` 对象构建的字符串
|
|
76
|
+
- `isEmptyString` 空字符串
|
|
77
|
+
- `isBusinessEmptyString` 空字符串(去除首尾空格)
|
|
78
|
+
- `isNumber` 数字、`Number` 对象构建的数字
|
|
79
|
+
- `isBoolean` 布尔值、`Boolean` 对象构建的布尔值
|
|
80
|
+
- `isTrue` 是否为 true
|
|
81
|
+
- `isFalse` 是否为 false
|
|
82
|
+
- `isNull` null
|
|
83
|
+
- `isUndefined` undefined
|
|
84
|
+
- `isNaN` `NaN`(`NaN` 是一个特殊的数值 `NaN !== NaN` 即便 `typeof NaN` 返回的是 `number`)
|
|
85
|
+
- `isFunction` 函数
|
|
86
|
+
- `isArray` 数组、`Array` 对象构建的数组
|
|
87
|
+
- `isEmptyArray` 是否是空数组
|
|
88
|
+
- `isSymbol` symbol
|
|
89
|
+
- `isBigInt` 大整数
|
|
90
|
+
- `isPlainObject` 对象(普通对象,非其他内置对象类型)
|
|
91
|
+
- `isEmptyObject` 是否为空对象(没有私有键的对象)
|
|
92
|
+
- `isPromise` Promise
|
|
93
|
+
- `isAsyncFunction` 异步函数
|
|
94
|
+
- `isDate` 时间
|
|
95
|
+
- `isMap` Map
|
|
96
|
+
- `isSet` Set
|
|
97
|
+
- `isWeakMap` WeakMap
|
|
98
|
+
- `isWeakSet` WeakSet
|
|
99
|
+
- `isGenerator` 生成器
|
|
100
|
+
- `isGeneratorFunction` 生成器函数
|
|
101
|
+
- `isBigInt64Array` BigInt64Array
|
|
102
|
+
- `isBigUint64Array` BigUint64Array
|
|
103
|
+
- `isDataView` DataView
|
|
104
|
+
- `isArrayBuffer` ArrayBuffer
|
|
105
|
+
- `isRegExp` 正则、`RegExp` 对象构建的正则
|
|
106
|
+
- `isSharedArrayBuffer` SharedArrayBuffer
|
|
107
|
+
- `isUint8ClampedArray` Uint8ClampedArray
|
|
108
|
+
- `isInt8Array` Int8Array
|
|
109
|
+
- `isUint8Array` Uint8Array
|
|
110
|
+
- `isTypedArray` TypedArray
|
|
111
|
+
- `isInt16Array` Int16Array
|
|
112
|
+
- `isUint16Array` Uint16Array
|
|
113
|
+
- `isInt32Array` Int32Array
|
|
114
|
+
- `isUint32Array` Uint32Array
|
|
115
|
+
- `isFloat32Array` Float32Array
|
|
116
|
+
- `isFloat64Array` Float64Array
|
|
117
|
+
- `isIntlCollator` Intl.Collator
|
|
118
|
+
- `isIntlDateTimeFormat` Intl.DateTimeFormat
|
|
119
|
+
- `isIntlDisplayNames` Intl.DisplayNames
|
|
120
|
+
- `isIntlListFormat` Intl.ListFormat
|
|
121
|
+
- `isIntlLocale` Intl.Locale
|
|
122
|
+
- `isIntlNumberFormat` Intl.NumberFormat
|
|
123
|
+
- `isError` 错误
|
|
124
|
+
- `isEvalError` eval 错误
|
|
125
|
+
- `isRangeError` range 错误
|
|
126
|
+
- `isReferenceError` reference 错误
|
|
127
|
+
- `isSyntaxError` syntax 错误
|
|
128
|
+
- `isTypeError` type 错误
|
|
129
|
+
- `isURIError` uri 错误
|
|
130
|
+
- `isAggregateError` aggregate 错误
|
|
131
|
+
|
|
132
|
+
## 状态
|
|
133
|
+
|
|
134
|
+
此软件包是 `@mudbean` 生态系统的一部分。
|
|
135
|
+
它使用严格的 TypeScript 编写,并通过 Rollup 构建进行验证。
|
|
136
|
+
虽然单元测试较少,但 API 稳定,并在生产环境中大量使用。
|
package/cjs/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./typeOf.js");exports.isAggregateError=function(e){return"aggregateerror"===r.typeOf(e)},exports.isError=function(e){return"error"===r.typeOf(e)},exports.isEvalError=function(e){return"evalerror"===r.typeOf(e)},exports.isRangeError=function(e){return"rangeerror"===r.typeOf(e)},exports.isReferenceError=function(e){return"referenceerror"===r.typeOf(e)},exports.isSyntaxError=function(e){return"syntaxerror"===r.typeOf(e)},exports.isTypeError=function(e){return"typeerror"===r.typeOf(e)},exports.isURIError=function(e){return"urierror"===r.typeOf(e)};
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./typeOf.js"),s=require("./isString.js"),i=require("./isNumber.js"),e=require("./isBoolean.js"),t=require("./isNull.js"),o=require("./isFunction.js"),a=require("./isArray.js"),p=require("./isObject.js"),n=require("./isSymbol.js"),x=require("./intl.js"),y=require("./error.js"),l=require("./isType.js");exports.typeOf=r.typeOf,exports.isBusinessEmptyString=s.isBusinessEmptyString,exports.isEmptyString=s.isEmptyString,exports.isRegExp=s.isRegExp,exports.isString=s.isString,exports.isBigInt=i.isBigInt,exports.isNaN=i.isNaN,exports.isNegativeInteger=i.isNegativeInteger,exports.isNumber=i.isNumber,exports.isPositiveInteger=i.isPositiveInteger,exports.isZero=i.isZero,exports.isBoolean=e.isBoolean,exports.isFalse=e.isFalse,exports.isTrue=e.isTrue,exports.isNull=t.isNull,exports.isUndefined=t.isUndefined,exports.isAsyncFunction=o.isAsyncFunction,exports.isFunction=o.isFunction,exports.isGenerator=o.isGenerator,exports.isGeneratorFunction=o.isGeneratorFunction,exports.isPromise=o.isPromise,exports.isArray=a.isArray,exports.isArrayBuffer=a.isArrayBuffer,exports.isBigInt64Array=a.isBigInt64Array,exports.isBigUint64Array=a.isBigUint64Array,exports.isEmptyArray=a.isEmptyArray,exports.isFloat32Array=a.isFloat32Array,exports.isFloat64Array=a.isFloat64Array,exports.isInt16Array=a.isInt16Array,exports.isInt8Array=a.isInt8Array,exports.isSet=a.isSet,exports.isSharedArrayBuffer=a.isSharedArrayBuffer,exports.isUint16Array=a.isUint16Array,exports.isUint32Array=a.isUint32Array,exports.isUint8Array=a.isUint8Array,exports.isUint8ClampedArray=a.isUint8ClampedArray,exports.isWeakSet=a.isWeakSet,exports.isDataView=p.isDataView,exports.isDate=p.isDate,exports.isEmptyObject=p.isEmptyObject,exports.isMap=p.isMap,exports.isPlainObject=p.isPlainObject,exports.isWeakMap=p.isWeakMap,exports.isSymbol=n.isSymbol,exports.isIntlCollator=x.isIntlCollator,exports.isIntlDateTimeFormat=x.isIntlDateTimeFormat,exports.isIntlDisplayNames=x.isIntlDisplayNames,exports.isIntlListFormat=x.isIntlListFormat,exports.isIntlLocale=x.isIntlLocale,exports.isIntlNumberFormat=x.isIntlNumberFormat,exports.isAggregateError=y.isAggregateError,exports.isError=y.isError,exports.isEvalError=y.isEvalError,exports.isRangeError=y.isRangeError,exports.isReferenceError=y.isReferenceError,exports.isSyntaxError=y.isSyntaxError,exports.isTypeError=y.isTypeError,exports.isURIError=y.isURIError,exports.isType=l.isType;
|
package/cjs/intl.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("./typeOf.js");exports.isIntlCollator=function(e){return"intl.collator"===t.typeOf(e)},exports.isIntlDateTimeFormat=function(e){return"intl.datetimeformat"===t.typeOf(e)},exports.isIntlDisplayNames=function(e){return"intl.displaynames"===t.typeOf(e)},exports.isIntlListFormat=function(e){return"intl.listformat"===t.typeOf(e)},exports.isIntlLocale=function(e){return"intl.locale"===t.typeOf(e)},exports.isIntlNumberFormat=function(e){return"intl.numberformat"===t.typeOf(e)};
|
package/cjs/isArray.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var r=require("./typeOf.js");function t(r){return Array.isArray(r)}exports.isArray=t,exports.isArrayBuffer=function(t){return"arraybuffer"===r.typeOf(t)},exports.isBigInt64Array=function(t){return"bigint64array"===r.typeOf(t)},exports.isBigUint64Array=function(t){return"biguint64array"===r.typeOf(t)},exports.isEmptyArray=function(r){if(t(r))return 0===r.length;throw new TypeError("参数必须为数组")},exports.isFloat32Array=function(t){return"float32array"===r.typeOf(t)},exports.isFloat64Array=function(t){return"float64array"===r.typeOf(t)},exports.isInt16Array=function(t){return"int16array"===r.typeOf(t)},exports.isInt8Array=function(t){return"int8array"===r.typeOf(t)},exports.isSet=function(t){return"set"===r.typeOf(t)},exports.isSharedArrayBuffer=function(t){return"sharedarraybuffer"===r.typeOf(t)},exports.isUint16Array=function(t){return"uint16array"===r.typeOf(t)},exports.isUint32Array=function(t){return"uint32array"===r.typeOf(t)},exports.isUint8Array=function(t){return"uint8array"===r.typeOf(t)},exports.isUint8ClampedArray=function(t){return"uint8clampedarray"===r.typeOf(t)},exports.isWeakSet=function(t){return"weakset"===r.typeOf(t)};
|
package/cjs/isBoolean.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./typeOf.js");exports.isBoolean=function(r){return"boolean"===e.typeOf(r)},exports.isFalse=function(e){return!1===e},exports.isTrue=function(e){return!0===e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n=require("./typeOf.js");exports.isAsyncFunction=function(t){return"asyncfunction"===n.typeOf(t)},exports.isFunction=function(t){return"function"===n.typeOf(t)},exports.isGenerator=function(t){return"generator"===n.typeOf(t)},exports.isGeneratorFunction=function(t){return"generatorfunction"===n.typeOf(t)},exports.isPromise=function(t){return"promise"===n.typeOf(t)};
|
package/cjs/isNull.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.isNull=function(n){return null===n},exports.isUndefined=function(n){return void 0===n};
|
package/cjs/isNumber.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./typeOf.js");function r(r){return"number"===e.typeOf(r)}exports.isBigInt=function(r){return"bigint"===e.typeOf(r)},exports.isNaN=function(e){return Number.isNaN(e)},exports.isNegativeInteger=function(e){return Number.isInteger(e)&&r(e)&&e<0},exports.isNumber=r,exports.isPositiveInteger=function(e){return Number.isInteger(e)&&r(e)&&e>0},exports.isZero=function(e){return 0===e};
|
package/cjs/isObject.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("./typeOf.js");function e(e){return"object"===t.typeOf(e)}exports.isDataView=function(e){return"dataview"===t.typeOf(e)},exports.isDate=function(e){return"date"===t.typeOf(e)},exports.isEmptyObject=function(t){return e(t)&&0===Reflect.ownKeys(t).length},exports.isMap=function(e){return"map"===t.typeOf(e)},exports.isPlainObject=e,exports.isWeakMap=function(e){return"weakmap"===t.typeOf(e)};
|
package/cjs/isString.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("./typeOf.js");function r(r){return"string"===t.typeOf(r)}exports.isBusinessEmptyString=function(t){return r(t)&&""===t.valueOf().trim()},exports.isEmptyString=function(t){return r(t)&&""===t.valueOf()},exports.isRegExp=function(r){return"regexp"===t.typeOf(r)},exports.isString=r;
|
package/cjs/isSymbol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("./typeOf.js");exports.isSymbol=function(r){return"symbol"===e.typeOf(r)};
|
package/cjs/isType.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.isType=function(t,e){return void 0===e||("function"==typeof e?e(t):e)};
|
package/cjs/typeOf.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";exports.typeOf=function(r){const e=typeof r;if("object"!==e&&"function"!==e)return e;const o=Reflect.apply(Object.prototype.toString,r,[]).replace(/^.*\s(.*)]$/,"$1").toLowerCase();return"error"!==o?o:r instanceof SyntaxError?"syntaxerror":r instanceof TypeError?"typeerror":r instanceof URIError?"urierror":r instanceof ReferenceError?"referenceerror":r instanceof AggregateError?"aggregateerror":r instanceof RangeError?"rangeerror":r instanceof EvalError?"evalerror":"error"};
|
package/es/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as r}from"./typeOf.js";function e(e){return"error"===r(e)}function n(e){return"evalerror"===r(e)}function t(e){return"rangeerror"===r(e)}function o(e){return"referenceerror"===r(e)}function u(e){return"syntaxerror"===r(e)}function f(e){return"typeerror"===r(e)}function i(e){return"urierror"===r(e)}function c(e){return"aggregateerror"===r(e)}export{c as isAggregateError,e as isError,n as isEvalError,t as isRangeError,o as isReferenceError,u as isSyntaxError,f as isTypeError,i as isURIError};
|
package/es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{typeOf}from"./typeOf.js";export{isBusinessEmptyString,isEmptyString,isRegExp,isString}from"./isString.js";export{isBigInt,isNaN,isNegativeInteger,isNumber,isPositiveInteger,isZero}from"./isNumber.js";export{isBoolean,isFalse,isTrue}from"./isBoolean.js";export{isNull,isUndefined}from"./isNull.js";export{isAsyncFunction,isFunction,isGenerator,isGeneratorFunction,isPromise}from"./isFunction.js";export{isArray,isArrayBuffer,isBigInt64Array,isBigUint64Array,isEmptyArray,isFloat32Array,isFloat64Array,isInt16Array,isInt8Array,isSet,isSharedArrayBuffer,isUint16Array,isUint32Array,isUint8Array,isUint8ClampedArray,isWeakSet}from"./isArray.js";export{isDataView,isDate,isEmptyObject,isMap,isPlainObject,isWeakMap}from"./isObject.js";export{isSymbol}from"./isSymbol.js";export{isIntlCollator,isIntlDateTimeFormat,isIntlDisplayNames,isIntlListFormat,isIntlLocale,isIntlNumberFormat}from"./intl.js";export{isAggregateError,isError,isEvalError,isRangeError,isReferenceError,isSyntaxError,isTypeError,isURIError}from"./error.js";export{isType}from"./isType.js";
|
package/es/intl.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as t}from"./typeOf.js";function n(n){return"intl.collator"===t(n)}function r(n){return"intl.datetimeformat"===t(n)}function i(n){return"intl.displaynames"===t(n)}function o(n){return"intl.listformat"===t(n)}function e(n){return"intl.locale"===t(n)}function u(n){return"intl.numberformat"===t(n)}export{n as isIntlCollator,r as isIntlDateTimeFormat,i as isIntlDisplayNames,o as isIntlListFormat,e as isIntlLocale,u as isIntlNumberFormat};
|
package/es/isArray.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as r}from"./typeOf.js";function n(r){return Array.isArray(r)}function t(r){if(n(r))return 0===r.length;throw new TypeError("参数必须为数组")}function u(n){return"set"===r(n)}function a(n){return"weakset"===r(n)}function i(n){return"bigint64array"===r(n)}function e(n){return"biguint64array"===r(n)}function f(n){return"arraybuffer"===r(n)}function o(n){return"int8array"===r(n)}function c(n){return"uint8array"===r(n)}function y(n){return"int16array"===r(n)}function p(n){return"uint16array"===r(n)}function s(n){return"uint32array"===r(n)}function b(n){return"float32array"===r(n)}function l(n){return"float64array"===r(n)}function g(n){return"sharedarraybuffer"===r(n)}function h(n){return"uint8clampedarray"===r(n)}export{n as isArray,f as isArrayBuffer,i as isBigInt64Array,e as isBigUint64Array,t as isEmptyArray,b as isFloat32Array,l as isFloat64Array,y as isInt16Array,o as isInt8Array,u as isSet,g as isSharedArrayBuffer,p as isUint16Array,s as isUint32Array,c as isUint8Array,h as isUint8ClampedArray,a as isWeakSet};
|
package/es/isBoolean.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as n}from"./typeOf.js";function r(r){return"boolean"===n(r)}function t(n){return!0===n}function o(n){return!1===n}export{r as isBoolean,o as isFalse,t as isTrue};
|
package/es/isFunction.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as n}from"./typeOf.js";function r(r){return"function"===n(r)}function t(r){return"promise"===n(r)}function o(r){return"asyncfunction"===n(r)}function u(r){return"generatorfunction"===n(r)}function e(r){return"generator"===n(r)}export{o as isAsyncFunction,r as isFunction,e as isGenerator,u as isGeneratorFunction,t as isPromise};
|
package/es/isNull.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(n){return null===n}function r(n){return void 0===n}export{n as isNull,r as isUndefined};
|
package/es/isNumber.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as n}from"./typeOf.js";function r(r){return"number"===n(r)}function t(r){return"bigint"===n(r)}function e(n){return Number.isNaN(n)}function u(n){return Number.isInteger(n)&&r(n)&&n>0}function i(n){return Number.isInteger(n)&&r(n)&&n<0}function o(n){return 0===n}export{t as isBigInt,e as isNaN,i as isNegativeInteger,r as isNumber,u as isPositiveInteger,o as isZero};
|
package/es/isObject.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as n}from"./typeOf.js";function t(t){return"object"===n(t)}function e(n){return t(n)&&0===Reflect.ownKeys(n).length}function r(t){return"date"===n(t)}function u(t){return"dataview"===n(t)}function o(t){return"map"===n(t)}function f(t){return"weakmap"===n(t)}export{u as isDataView,r as isDate,e as isEmptyObject,o as isMap,t as isPlainObject,f as isWeakMap};
|
package/es/isString.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as r}from"./typeOf.js";function n(n){return"string"===r(n)}function t(n){return"regexp"===r(n)}function e(r){return n(r)&&""===r.valueOf()}function u(r){return n(r)&&""===r.valueOf().trim()}export{u as isBusinessEmptyString,e as isEmptyString,t as isRegExp,n as isString};
|
package/es/isSymbol.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{typeOf as o}from"./typeOf.js";function r(r){return"symbol"===o(r)}export{r as isSymbol};
|
package/es/isType.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function n(n,o){return void 0===o||("function"==typeof o?o(n):o)}export{n as isType};
|
package/es/typeOf.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(r){const e=typeof r;if("object"!==e&&"function"!==e)return e;const o=Reflect.apply(Object.prototype.toString,r,[]).replace(/^.*\s(.*)]$/,"$1").toLowerCase();return"error"!==o?o:r instanceof SyntaxError?"syntaxerror":r instanceof TypeError?"typeerror":r instanceof URIError?"urierror":r instanceof ReferenceError?"referenceerror":r instanceof AggregateError?"aggregateerror":r instanceof RangeError?"rangeerror":r instanceof EvalError?"evalerror":"error"}export{r as typeOf};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # 检测 `input` 是否是 `Error` 类型
|
|
3
|
+
*
|
|
4
|
+
* @param input - 待检测的数据,任意类型
|
|
5
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `Error` ,且在 Typescript 中进行类型收缩
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { isError } from '@mudbean/is';
|
|
10
|
+
*
|
|
11
|
+
* console.log(isError(new Error('test'))); // true
|
|
12
|
+
*
|
|
13
|
+
* // false (类型不符)
|
|
14
|
+
* console.log(isError(new EvalError('test')));
|
|
15
|
+
* // false (类型不符)
|
|
16
|
+
* console.log(isError(new RangeError('test')));
|
|
17
|
+
* // false (类型不符)
|
|
18
|
+
* console.log(isError(new ReferenceError('test')));
|
|
19
|
+
*
|
|
20
|
+
* // false (类型不符)
|
|
21
|
+
* console.log(isError({ message: 'test' }));
|
|
22
|
+
* ```
|
|
23
|
+
* @since 0.1.4
|
|
24
|
+
*/
|
|
25
|
+
export declare function isError(input: any): input is Error;
|
|
26
|
+
/**
|
|
27
|
+
* # 检测 `input` 是否是 `EvalError` 类型
|
|
28
|
+
*
|
|
29
|
+
* @param input - 待检测的数据,任意类型
|
|
30
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `EvalError` ,且在 Typescript 中进行类型收缩
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { isEvalError } from '@mudbean/is';
|
|
35
|
+
*
|
|
36
|
+
* console.log(isEvalError(new EvalError('test'))); // true
|
|
37
|
+
*
|
|
38
|
+
* // false (类型非 EvalError)
|
|
39
|
+
* console.log(isEvalError(new Error('test')));
|
|
40
|
+
* // false (类型非 EvalError)
|
|
41
|
+
* console.log(isEvalError(new TypeError('test')));
|
|
42
|
+
* // false (类型非 EvalError)
|
|
43
|
+
* console.log(isEvalError(new RangeError('test')));
|
|
44
|
+
*
|
|
45
|
+
* // false (类型非 EvalError)
|
|
46
|
+
* console.log(isEvalError({ message: 'test' }));
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function isEvalError(input: any): input is EvalError;
|
|
50
|
+
/**
|
|
51
|
+
* # 检测 `input 是否是 `RangeError` 类型
|
|
52
|
+
*
|
|
53
|
+
* @param input - 待检测的数据,任意类型
|
|
54
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `RangeError` ,且在 Typescript 中进行类型收缩
|
|
55
|
+
* @example
|
|
56
|
+
*
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { isRangeError } from '@mudbean/is';
|
|
59
|
+
*
|
|
60
|
+
* console.log(isRangeError(new RangeError('test'))); // true
|
|
61
|
+
*
|
|
62
|
+
* // false (类型非 RangeError
|
|
63
|
+
* console.log(isRangeError(new Error('test')));
|
|
64
|
+
* // false (类型非 RangeError)
|
|
65
|
+
* console.log(isRangeError(new TypeError('test')));
|
|
66
|
+
* // false (类型非 RangeError)
|
|
67
|
+
* console.log(isRangeError(new SyntaxError('test')));
|
|
68
|
+
*
|
|
69
|
+
* // false (类型非 RangeError)
|
|
70
|
+
* console.log(isRangeError('test'));
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function isRangeError(input: any): input is RangeError;
|
|
74
|
+
/**
|
|
75
|
+
* # 检测 `input` 是否是 `ReferenceError` 类型
|
|
76
|
+
*
|
|
77
|
+
* @param input - 待检测的数据,任意类型
|
|
78
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `ReferenceError` ,且在 Typescript 中进行类型收缩
|
|
79
|
+
* @example
|
|
80
|
+
*
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { isReferenceError } from '@mudbean/is';
|
|
83
|
+
*
|
|
84
|
+
* console.log(isReferenceError(new ReferenceError('test'))); // true
|
|
85
|
+
*
|
|
86
|
+
* // false (类型非 ReferenceError)
|
|
87
|
+
* console.log(isReferenceError(new Error('test')));
|
|
88
|
+
* // false (类型非 ReferenceError)
|
|
89
|
+
* console.log(isReferenceError(new TypeError('test')));
|
|
90
|
+
* // false (类型非 ReferenceError)
|
|
91
|
+
* console.log(isReferenceError(new SyntaxError('test')));
|
|
92
|
+
*
|
|
93
|
+
* // false (类型非 ReferenceError)
|
|
94
|
+
* console.log(isReferenceError('test');
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function isReferenceError(input: any): input is ReferenceError;
|
|
98
|
+
/**
|
|
99
|
+
* # 检测 `input` 是否是 `SyntaxError` 类型
|
|
100
|
+
*
|
|
101
|
+
* @param input - 待检测的数据,任意类型
|
|
102
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `SyntaxError` ,且在 Typescript 中进行类型收缩
|
|
103
|
+
* @example
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { isSyntaxError } from '@mudbean/is';
|
|
107
|
+
*
|
|
108
|
+
* console.log(isSyntaxError(new SyntaxError('test'))); // true
|
|
109
|
+
*
|
|
110
|
+
* // false (类型非 SyntaxError)
|
|
111
|
+
* console.log(isSyntaxError(new Error('test')));
|
|
112
|
+
* // false (类型非 SyntaxError)
|
|
113
|
+
* console.log(isSyntaxError(new TypeError('test')));
|
|
114
|
+
* // false (类型非 SyntaxError)
|
|
115
|
+
* console.log(isSyntaxError(new ReferenceError('test')));
|
|
116
|
+
*
|
|
117
|
+
* // false (类型非 SyntaxError)
|
|
118
|
+
* console.log(isSyntaxError('test'));
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function isSyntaxError(input: any): input is SyntaxError;
|
|
122
|
+
/**
|
|
123
|
+
* # 检测 `input` 是否是 `TypeError` 类型
|
|
124
|
+
*
|
|
125
|
+
* @param input - 待检测的数据,任意类型
|
|
126
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `TypeError` ,且在 Typescript 中进行类型收缩
|
|
127
|
+
* @example
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { isTypeError } from '@mudbean/is';
|
|
131
|
+
*
|
|
132
|
+
* console.log(isTypeError(new TypeError('test'))); // true
|
|
133
|
+
*
|
|
134
|
+
* // false (类型非 TypeError)
|
|
135
|
+
* console.log(isTypeError(new Error('test')));
|
|
136
|
+
* // false (类型非 TypeError)
|
|
137
|
+
* console.log(isTypeError(new SyntaxError('test')));
|
|
138
|
+
* // false (类型非 TypeError)
|
|
139
|
+
* console.log(isTypeError(new ReferenceError('test')));
|
|
140
|
+
* // false (类型非 TypeError)
|
|
141
|
+
* console.log(isTypeError(new EvalError('test')));
|
|
142
|
+
*
|
|
143
|
+
* // false (类型非 TypeError)
|
|
144
|
+
* console.log(isTypeError('test');
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export declare function isTypeError(input: any): input is TypeError;
|
|
148
|
+
/**
|
|
149
|
+
* # 检测 `input` 是否是 `URIError` 类型
|
|
150
|
+
*
|
|
151
|
+
* @param input - 待检测的数据,任意类型
|
|
152
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `URIError` ,且在 Typescript 中进行类型收缩
|
|
153
|
+
* @example
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* import { isURIError } from '@mudbean/is';
|
|
157
|
+
*
|
|
158
|
+
* console.log(isURIError(new URIError('test'))); // true
|
|
159
|
+
*
|
|
160
|
+
* console.log(isURIError(new Error('test'))); // false
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export declare function isURIError(input: any): input is URIError;
|
|
164
|
+
/**
|
|
165
|
+
* # 检测 `input` 是否是 `AggregateError` 类型
|
|
166
|
+
*
|
|
167
|
+
* @param input - 待检测的数据,任意类型
|
|
168
|
+
* @returns 返回 `true` 则说明该数据 `input` 类型为 `AggregateError` ,且在 Typescript 中进行类型收缩
|
|
169
|
+
* @example
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { isAggregateError } from '@mudbean/is';
|
|
173
|
+
*
|
|
174
|
+
* console.log(isAggregateError(new AggregateError([]))); // true
|
|
175
|
+
*
|
|
176
|
+
* console.log(isAggregateError(new Error('test'))); // false
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function isAggregateError(input: any): input is AggregateError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { typeOf } from './typeOf';
|
|
2
|
+
export type { Typeof } from './types';
|
|
3
|
+
export { isString, isRegExp, isEmptyString, isBusinessEmptyString, } from './isString';
|
|
4
|
+
export { isNumber, isNaN, isBigInt, isZero, isNegativeInteger, isPositiveInteger, } from './isNumber';
|
|
5
|
+
export { isBoolean, isTrue, isFalse } from './isBoolean';
|
|
6
|
+
export { isNull, isUndefined } from './isNull';
|
|
7
|
+
export { isFunction, isPromise, isAsyncFunction, isGenerator, isGeneratorFunction, } from './isFunction';
|
|
8
|
+
export { isArray, isEmptyArray, isSet, isWeakSet, isBigInt64Array, isBigUint64Array, isArrayBuffer, isFloat32Array, isFloat64Array, isInt16Array, isInt8Array, isUint16Array, isUint32Array, isUint8Array, isSharedArrayBuffer, isUint8ClampedArray, } from './isArray';
|
|
9
|
+
export { isPlainObject, isEmptyObject, isDate, isDataView, isMap, isWeakMap, } from './isObject';
|
|
10
|
+
export { isSymbol } from './isSymbol';
|
|
11
|
+
export { isIntlCollator, isIntlDateTimeFormat, isIntlDisplayNames, isIntlListFormat, isIntlLocale, isIntlNumberFormat, } from './intl';
|
|
12
|
+
export { isError, isEvalError, isRangeError, isReferenceError, isSyntaxError, isTypeError, isURIError, isAggregateError, } from './error';
|
|
13
|
+
export { isType } from './isType';
|