@mudbean/is 2.0.2 → 2.0.3

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/cjs/error.js +211 -1
  3. package/cjs/index.js +76 -1
  4. package/cjs/intl.js +152 -1
  5. package/cjs/isArray.js +340 -1
  6. package/cjs/isBoolean.js +71 -1
  7. package/cjs/isFunction.js +120 -1
  8. package/cjs/isNull.js +49 -1
  9. package/cjs/isNumber.js +148 -1
  10. package/cjs/isObject.js +200 -1
  11. package/cjs/isString.js +121 -1
  12. package/cjs/isSymbol.js +36 -1
  13. package/cjs/isType.js +16 -1
  14. package/cjs/typeOf.js +72 -1
  15. package/es/error.js +202 -1
  16. package/es/index.js +12 -1
  17. package/es/intl.js +145 -1
  18. package/es/isArray.js +323 -1
  19. package/es/isBoolean.js +67 -1
  20. package/es/isFunction.js +114 -1
  21. package/es/isNull.js +46 -1
  22. package/es/isNumber.js +141 -1
  23. package/es/isObject.js +193 -1
  24. package/es/isString.js +116 -1
  25. package/es/isSymbol.js +34 -1
  26. package/es/isType.js +14 -1
  27. package/es/typeOf.js +70 -1
  28. package/package.json +16 -23
  29. /package/es/{types/error.d.ts → error.d.ts} +0 -0
  30. /package/es/{types/index.d.ts → index.d.ts} +0 -0
  31. /package/es/{types/intl.d.ts → intl.d.ts} +0 -0
  32. /package/es/{types/isArray.d.ts → isArray.d.ts} +0 -0
  33. /package/es/{types/isBoolean.d.ts → isBoolean.d.ts} +0 -0
  34. /package/es/{types/isFunction.d.ts → isFunction.d.ts} +0 -0
  35. /package/es/{types/isNull.d.ts → isNull.d.ts} +0 -0
  36. /package/es/{types/isNumber.d.ts → isNumber.d.ts} +0 -0
  37. /package/es/{types/isObject.d.ts → isObject.d.ts} +0 -0
  38. /package/es/{types/isString.d.ts → isString.d.ts} +0 -0
  39. /package/es/{types/isSymbol.d.ts → isSymbol.d.ts} +0 -0
  40. /package/es/{types/isType.d.ts → isType.d.ts} +0 -0
  41. /package/es/{types/typeOf.d.ts → typeOf.d.ts} +0 -0
  42. /package/es/{types/types.d.ts → types.d.ts} +0 -0
package/es/isSymbol.js CHANGED
@@ -1 +1,34 @@
1
- import{typeOf as o}from"./typeOf.js";function r(r){return"symbol"===o(r)}export{r as isSymbol};
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
- function n(n,o){return void 0===o||("function"==typeof o?o(n):o)}export{n as isType};
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
- 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};
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.2",
4
+ "version": "2.0.3",
5
5
  "main": "cjs/index.js",
6
6
  "module": "es/index.js",
7
- "types": "es/types/index.d.ts",
7
+ "types": "es/index.d.ts",
8
8
  "author": {
9
9
  "name": "泥豆君",
10
10
  "email": "Mr.MudBean@outlook.com",
11
- "url": "https://lmssee.com"
11
+ "url": "https://mudbean.cn"
12
12
  },
13
13
  "description": "JavaScript/TypeScript 的类型检测工具,支持 TypeScript 类型收缩",
14
14
  "sideEffects": false,
@@ -19,7 +19,6 @@
19
19
  "files": [
20
20
  "cjs",
21
21
  "es",
22
- "es/types",
23
22
  "CHANGELOG.md",
24
23
  "README.md",
25
24
  "LICENSE"
@@ -29,85 +28,79 @@
29
28
  "import": "./es/index.js",
30
29
  "default": "./es/index.js",
31
30
  "require": "./cjs/index.js",
32
- "types": "./es/types/index.d.ts"
31
+ "types": "./es/index.d.ts"
33
32
  },
34
33
  "./error": {
35
34
  "default": "./es/error.js",
36
35
  "import": "./es/error.js",
37
36
  "require": "./cjs/error.js",
38
- "types": "./es/types/error.d.ts"
39
- },
40
- "./index": {
41
- "default": "./es/index.js",
42
- "import": "./es/index.js",
43
- "require": "./cjs/index.js",
44
- "types": "./es/types/index.d.ts"
37
+ "types": "./es/error.d.ts"
45
38
  },
46
39
  "./intl": {
47
40
  "default": "./es/intl.js",
48
41
  "import": "./es/intl.js",
49
42
  "require": "./cjs/intl.js",
50
- "types": "./es/types/intl.d.ts"
43
+ "types": "./es/intl.d.ts"
51
44
  },
52
45
  "./isArray": {
53
46
  "default": "./es/isArray.js",
54
47
  "import": "./es/isArray.js",
55
48
  "require": "./cjs/isArray.js",
56
- "types": "./es/types/isArray.d.ts"
49
+ "types": "./es/isArray.d.ts"
57
50
  },
58
51
  "./isBoolean": {
59
52
  "default": "./es/isBoolean.js",
60
53
  "import": "./es/isBoolean.js",
61
54
  "require": "./cjs/isBoolean.js",
62
- "types": "./es/types/isBoolean.d.ts"
55
+ "types": "./es/isBoolean.d.ts"
63
56
  },
64
57
  "./isFunction": {
65
58
  "default": "./es/isFunction.js",
66
59
  "import": "./es/isFunction.js",
67
60
  "require": "./cjs/isFunction.js",
68
- "types": "./es/types/isFunction.d.ts"
61
+ "types": "./es/isFunction.d.ts"
69
62
  },
70
63
  "./isNull": {
71
64
  "default": "./es/isNull.js",
72
65
  "import": "./es/isNull.js",
73
66
  "require": "./cjs/isNull.js",
74
- "types": "./es/types/isNull.d.ts"
67
+ "types": "./es/isNull.d.ts"
75
68
  },
76
69
  "./isNumber": {
77
70
  "default": "./es/isNumber.js",
78
71
  "import": "./es/isNumber.js",
79
72
  "require": "./cjs/isNumber.js",
80
- "types": "./es/types/isNumber.d.ts"
73
+ "types": "./es/isNumber.d.ts"
81
74
  },
82
75
  "./isObject": {
83
76
  "default": "./es/isObject.js",
84
77
  "import": "./es/isObject.js",
85
78
  "require": "./cjs/isObject.js",
86
- "types": "./es/types/isObject.d.ts"
79
+ "types": "./es/isObject.d.ts"
87
80
  },
88
81
  "./isString": {
89
82
  "default": "./es/isString.js",
90
83
  "import": "./es/isString.js",
91
84
  "require": "./cjs/isString.js",
92
- "types": "./es/types/isString.d.ts"
85
+ "types": "./es/isString.d.ts"
93
86
  },
94
87
  "./isSymbol": {
95
88
  "default": "./es/isSymbol.js",
96
89
  "import": "./es/isSymbol.js",
97
90
  "require": "./cjs/isSymbol.js",
98
- "types": "./es/types/isSymbol.d.ts"
91
+ "types": "./es/isSymbol.d.ts"
99
92
  },
100
93
  "./isType": {
101
94
  "default": "./es/isType.js",
102
95
  "import": "./es/isType.js",
103
96
  "require": "./cjs/isType.js",
104
- "types": "./es/types/isType.d.ts"
97
+ "types": "./es/isType.d.ts"
105
98
  },
106
99
  "./typeOf": {
107
100
  "default": "./es/typeOf.js",
108
101
  "import": "./es/typeOf.js",
109
102
  "require": "./cjs/typeOf.js",
110
- "types": "./es/types/typeOf.d.ts"
103
+ "types": "./es/typeOf.d.ts"
111
104
  }
112
105
  },
113
106
  "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