@modern-js/utils 1.3.3 → 1.3.6
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 +18 -0
- package/dist/js/modern/constants.js +10 -6
- package/dist/js/modern/is/type.js +4 -5
- package/dist/js/node/constants.js +10 -6
- package/dist/js/node/is/type.js +4 -5
- package/dist/js/treeshaking/constants.js +10 -6
- package/dist/js/treeshaking/is/type.js +4 -5
- package/dist/types/constants.d.ts +9 -0
- package/dist/types/format.d.ts +1 -1
- package/dist/types/is/type.d.ts +3 -3
- package/package.json +2 -2
- package/tests/isType.test.ts +70 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @modern-js/utils
|
|
2
2
|
|
|
3
|
+
## 1.3.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c2046f37: fix: plugin unbundle schema define
|
|
8
|
+
|
|
9
|
+
## 1.3.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5bf5868d: fix: isObject should return false when input is null
|
|
14
|
+
|
|
15
|
+
## 1.3.4
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- db43dce6: expose plugin-unbundle configs
|
|
20
|
+
|
|
3
21
|
## 1.3.3
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -233,12 +233,7 @@ export const PLUGIN_SCHEMAS = {
|
|
|
233
233
|
}
|
|
234
234
|
}],
|
|
235
235
|
'@modern-js/plugin-unbundle': [{
|
|
236
|
-
target: '
|
|
237
|
-
schema: {
|
|
238
|
-
type: 'boolean'
|
|
239
|
-
}
|
|
240
|
-
}, {
|
|
241
|
-
target: 'server.https',
|
|
236
|
+
target: 'output.disableAutoImportStyle',
|
|
242
237
|
schema: {
|
|
243
238
|
type: 'boolean'
|
|
244
239
|
}
|
|
@@ -252,6 +247,15 @@ export const PLUGIN_SCHEMAS = {
|
|
|
252
247
|
items: {
|
|
253
248
|
type: 'string'
|
|
254
249
|
}
|
|
250
|
+
},
|
|
251
|
+
ignoreModuleCache: {
|
|
252
|
+
type: 'boolean'
|
|
253
|
+
},
|
|
254
|
+
clearPdnCache: {
|
|
255
|
+
type: 'boolean'
|
|
256
|
+
},
|
|
257
|
+
pdnHost: {
|
|
258
|
+
type: 'string'
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
261
|
}
|
|
@@ -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 */
|
|
@@ -252,12 +252,7 @@ const PLUGIN_SCHEMAS = {
|
|
|
252
252
|
}
|
|
253
253
|
}],
|
|
254
254
|
'@modern-js/plugin-unbundle': [{
|
|
255
|
-
target: '
|
|
256
|
-
schema: {
|
|
257
|
-
type: 'boolean'
|
|
258
|
-
}
|
|
259
|
-
}, {
|
|
260
|
-
target: 'server.https',
|
|
255
|
+
target: 'output.disableAutoImportStyle',
|
|
261
256
|
schema: {
|
|
262
257
|
type: 'boolean'
|
|
263
258
|
}
|
|
@@ -271,6 +266,15 @@ const PLUGIN_SCHEMAS = {
|
|
|
271
266
|
items: {
|
|
272
267
|
type: 'string'
|
|
273
268
|
}
|
|
269
|
+
},
|
|
270
|
+
ignoreModuleCache: {
|
|
271
|
+
type: 'boolean'
|
|
272
|
+
},
|
|
273
|
+
clearPdnCache: {
|
|
274
|
+
type: 'boolean'
|
|
275
|
+
},
|
|
276
|
+
pdnHost: {
|
|
277
|
+
type: 'string'
|
|
274
278
|
}
|
|
275
279
|
}
|
|
276
280
|
}
|
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) {
|
|
@@ -233,12 +233,7 @@ export var PLUGIN_SCHEMAS = {
|
|
|
233
233
|
}
|
|
234
234
|
}],
|
|
235
235
|
'@modern-js/plugin-unbundle': [{
|
|
236
|
-
target: '
|
|
237
|
-
schema: {
|
|
238
|
-
type: 'boolean'
|
|
239
|
-
}
|
|
240
|
-
}, {
|
|
241
|
-
target: 'server.https',
|
|
236
|
+
target: 'output.disableAutoImportStyle',
|
|
242
237
|
schema: {
|
|
243
238
|
type: 'boolean'
|
|
244
239
|
}
|
|
@@ -252,6 +247,15 @@ export var PLUGIN_SCHEMAS = {
|
|
|
252
247
|
items: {
|
|
253
248
|
type: 'string'
|
|
254
249
|
}
|
|
250
|
+
},
|
|
251
|
+
ignoreModuleCache: {
|
|
252
|
+
type: 'boolean'
|
|
253
|
+
},
|
|
254
|
+
clearPdnCache: {
|
|
255
|
+
type: 'boolean'
|
|
256
|
+
},
|
|
257
|
+
pdnHost: {
|
|
258
|
+
type: 'string'
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
261
|
}
|
|
@@ -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.6",
|
|
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
|
});
|