@modern-js/utils 1.3.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md
CHANGED
@@ -5,18 +5,17 @@ export function isUndefined(obj) {
|
|
5
5
|
return typeof obj === 'undefined';
|
6
6
|
}
|
7
7
|
export function isArray(obj) {
|
8
|
-
return
|
8
|
+
return Array.isArray(obj);
|
9
9
|
} // eslint-disable-next-line @typescript-eslint/ban-types
|
10
10
|
|
11
11
|
export function isFunction(func) {
|
12
12
|
return typeof func === 'function';
|
13
|
-
}
|
14
|
-
|
13
|
+
}
|
15
14
|
export function isObject(obj) {
|
16
|
-
return typeof obj === 'object';
|
15
|
+
return obj !== null && typeof obj === 'object';
|
17
16
|
}
|
18
17
|
export function isPlainObject(obj) {
|
19
|
-
return obj &&
|
18
|
+
return isObject(obj) && Object.prototype.toString.call(obj) === '[object Object]';
|
20
19
|
}
|
21
20
|
export function isPromise(obj) {
|
22
21
|
/* eslint-disable promise/prefer-await-to-then */
|
package/dist/js/node/is/type.js
CHANGED
@@ -21,21 +21,20 @@ function isUndefined(obj) {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
function isArray(obj) {
|
24
|
-
return
|
24
|
+
return Array.isArray(obj);
|
25
25
|
} // eslint-disable-next-line @typescript-eslint/ban-types
|
26
26
|
|
27
27
|
|
28
28
|
function isFunction(func) {
|
29
29
|
return typeof func === 'function';
|
30
|
-
}
|
31
|
-
|
30
|
+
}
|
32
31
|
|
33
32
|
function isObject(obj) {
|
34
|
-
return typeof obj === 'object';
|
33
|
+
return obj !== null && typeof obj === 'object';
|
35
34
|
}
|
36
35
|
|
37
36
|
function isPlainObject(obj) {
|
38
|
-
return obj &&
|
37
|
+
return isObject(obj) && Object.prototype.toString.call(obj) === '[object Object]';
|
39
38
|
}
|
40
39
|
|
41
40
|
function isPromise(obj) {
|
@@ -7,18 +7,17 @@ export function isUndefined(obj) {
|
|
7
7
|
return typeof obj === 'undefined';
|
8
8
|
}
|
9
9
|
export function isArray(obj) {
|
10
|
-
return
|
10
|
+
return Array.isArray(obj);
|
11
11
|
} // eslint-disable-next-line @typescript-eslint/ban-types
|
12
12
|
|
13
13
|
export function isFunction(func) {
|
14
14
|
return typeof func === 'function';
|
15
|
-
}
|
16
|
-
|
15
|
+
}
|
17
16
|
export function isObject(obj) {
|
18
|
-
return _typeof(obj) === 'object';
|
17
|
+
return obj !== null && _typeof(obj) === 'object';
|
19
18
|
}
|
20
19
|
export function isPlainObject(obj) {
|
21
|
-
return
|
20
|
+
return isObject(obj) && Object.prototype.toString.call(obj) === '[object Object]';
|
22
21
|
}
|
23
22
|
export function isPromise(obj) {
|
24
23
|
/* eslint-disable promise/prefer-await-to-then */
|
package/dist/types/format.d.ts
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
7
7
|
*/
|
8
8
|
import { StatsCompilation } from 'webpack';
|
9
|
-
import { ProxyDetail, ProxyOptions } from '@modern-js/types';
|
9
|
+
import type { ProxyDetail, ProxyOptions } from '@modern-js/types';
|
10
10
|
declare function formatWebpackMessages(json: StatsCompilation): {
|
11
11
|
errors: string[];
|
12
12
|
warnings: string[];
|
package/dist/types/is/type.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
export declare function isString(str: any): str is string;
|
2
2
|
export declare function isUndefined(obj: any): obj is undefined;
|
3
|
-
export declare function isArray(obj:
|
3
|
+
export declare function isArray(obj: unknown): obj is any[];
|
4
4
|
export declare function isFunction(func: any): func is Function;
|
5
|
-
export declare function isObject(obj:
|
6
|
-
export declare function isPlainObject(obj:
|
5
|
+
export declare function isObject(obj: unknown): obj is Record<string, any>;
|
6
|
+
export declare function isPlainObject(obj: unknown): obj is Record<string, any>;
|
7
7
|
export declare function isPromise(obj: any): obj is Promise<any>;
|
8
8
|
export declare function isRegExp(obj: any): obj is RegExp;
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.3.
|
14
|
+
"version": "1.3.5",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -76,7 +76,7 @@
|
|
76
76
|
"@scripts/build": "0.0.0",
|
77
77
|
"jest": "^27",
|
78
78
|
"@scripts/jest-config": "0.0.0",
|
79
|
-
"@modern-js/types": "^1.3.
|
79
|
+
"@modern-js/types": "^1.3.5"
|
80
80
|
},
|
81
81
|
"sideEffects": false,
|
82
82
|
"publishConfig": {
|
package/tests/isType.test.ts
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
isArray,
|
3
|
+
isObject,
|
4
|
+
isString,
|
5
|
+
isRegExp,
|
6
|
+
isPromise,
|
7
|
+
isUndefined,
|
8
|
+
isPlainObject,
|
9
|
+
} from '../src/is/type';
|
2
10
|
|
3
11
|
describe('validate type', () => {
|
4
12
|
it('should validate string correctly', () => {
|
@@ -8,10 +16,70 @@ describe('validate type', () => {
|
|
8
16
|
expect(isString(123)).toBeFalsy();
|
9
17
|
});
|
10
18
|
|
11
|
-
it('should validate
|
19
|
+
it('should validate undefined correctly', () => {
|
12
20
|
expect(isUndefined(undefined)).toBeTruthy();
|
13
21
|
expect(isUndefined(null)).toBeFalsy();
|
14
22
|
expect(isUndefined('')).toBeFalsy();
|
15
23
|
expect(isUndefined(123)).toBeFalsy();
|
16
24
|
});
|
25
|
+
|
26
|
+
it('should validate array correctly', () => {
|
27
|
+
expect(isArray(undefined)).toBeFalsy();
|
28
|
+
expect(isArray(null)).toBeFalsy();
|
29
|
+
expect(isArray('')).toBeFalsy();
|
30
|
+
expect(isArray(123)).toBeFalsy();
|
31
|
+
expect(isArray({})).toBeFalsy();
|
32
|
+
expect(isArray([])).toBeTruthy();
|
33
|
+
});
|
34
|
+
|
35
|
+
it('should validate object correctly', () => {
|
36
|
+
expect(isObject(1)).toBeFalsy();
|
37
|
+
expect(isObject('1')).toBeFalsy();
|
38
|
+
expect(isObject(undefined)).toBeFalsy();
|
39
|
+
expect(isObject(null)).toBeFalsy();
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
41
|
+
expect(isObject(() => {})).toBeFalsy();
|
42
|
+
expect(isObject({})).toBeTruthy();
|
43
|
+
expect(isObject([])).toBeTruthy();
|
44
|
+
expect(isObject(/foo/)).toBeTruthy();
|
45
|
+
});
|
46
|
+
|
47
|
+
it('should validate plain object correctly', () => {
|
48
|
+
expect(isPlainObject(1)).toBeFalsy();
|
49
|
+
expect(isPlainObject('1')).toBeFalsy();
|
50
|
+
expect(isPlainObject(undefined)).toBeFalsy();
|
51
|
+
expect(isPlainObject(null)).toBeFalsy();
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
53
|
+
expect(isPlainObject(() => {})).toBeFalsy();
|
54
|
+
expect(isPlainObject({})).toBeTruthy();
|
55
|
+
expect(isPlainObject([])).toBeFalsy();
|
56
|
+
expect(isPlainObject(/foo/)).toBeFalsy();
|
57
|
+
});
|
58
|
+
|
59
|
+
it('should validate RegExp correctly', () => {
|
60
|
+
expect(isRegExp(1)).toBeFalsy();
|
61
|
+
expect(isRegExp('1')).toBeFalsy();
|
62
|
+
expect(isRegExp(undefined)).toBeFalsy();
|
63
|
+
expect(isRegExp(null)).toBeFalsy();
|
64
|
+
expect(isRegExp({})).toBeFalsy();
|
65
|
+
expect(isRegExp([])).toBeFalsy();
|
66
|
+
expect(isRegExp(/foo/)).toBeTruthy();
|
67
|
+
});
|
68
|
+
|
69
|
+
it('should validate Promise correctly', () => {
|
70
|
+
expect(isPromise(1)).toBeFalsy();
|
71
|
+
expect(isPromise('1')).toBeFalsy();
|
72
|
+
expect(isPromise(undefined)).toBeFalsy();
|
73
|
+
expect(isPromise(null)).toBeFalsy();
|
74
|
+
expect(isPromise({})).toBeFalsy();
|
75
|
+
expect(isPromise([])).toBeFalsy();
|
76
|
+
expect(isPromise(/foo/)).toBeFalsy();
|
77
|
+
expect(
|
78
|
+
isPromise(
|
79
|
+
new Promise<void>(resolve => {
|
80
|
+
resolve();
|
81
|
+
}),
|
82
|
+
),
|
83
|
+
).toBeTruthy();
|
84
|
+
});
|
17
85
|
});
|