mazey 3.3.0 → 3.3.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/README.md +29 -24
- package/README_CN.md +1 -1
- package/examples/index.ts +18 -0
- package/images/mazey-v1.4.39.svg +1 -0
- package/lib/index.cjs.js +1 -1
- package/lib/index.d.ts +15 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.esm.js +1 -1
- package/lib/mazey.min.js +1 -1
- package/package.json +27 -28
- package/scripts/github-helper.js +40 -0
- package/scripts/release.js +2 -23
- package/src/index.ts +22 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mazey",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4",
|
|
4
4
|
"description": "Mazey's library for front-end.",
|
|
5
5
|
"main": "lib/index.cjs.js",
|
|
6
6
|
"module": "lib/index.esm.js",
|
|
@@ -11,10 +11,9 @@
|
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"dev": "webpack-dev-server --config webpack.config.dev.js --open",
|
|
14
|
-
"build": "
|
|
14
|
+
"build": "rollup -c",
|
|
15
15
|
"test": "jest",
|
|
16
|
-
"
|
|
17
|
-
"docs": "npx typedoc",
|
|
16
|
+
"docs": "typedoc",
|
|
18
17
|
"lint-and-fix": "eslint ./src/index.ts --ext 'ts,tsx' --fix",
|
|
19
18
|
"preview": "npm run build && npm run test && npm run docs",
|
|
20
19
|
"release": "npm run preview && npm publish && node ./scripts/release.js"
|
|
@@ -59,42 +58,42 @@
|
|
|
59
58
|
},
|
|
60
59
|
"homepage": "https://github.com/mazeyqian/mazey#readme",
|
|
61
60
|
"devDependencies": {
|
|
62
|
-
"@babel/core": "7.8.4",
|
|
63
|
-
"@babel/plugin-proposal-class-properties": "7.10.4",
|
|
64
|
-
"@babel/plugin-proposal-object-rest-spread": "7.11.0",
|
|
65
|
-
"@babel/plugin-transform-runtime": "7.11.0",
|
|
66
|
-
"@babel/preset-env": "7.5.5",
|
|
67
|
-
"@babel/preset-typescript": "7.10.4",
|
|
61
|
+
"@babel/core": "^7.8.4",
|
|
62
|
+
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
|
63
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
|
|
64
|
+
"@babel/plugin-transform-runtime": "^7.11.0",
|
|
65
|
+
"@babel/preset-env": "^7.5.5",
|
|
66
|
+
"@babel/preset-typescript": "^7.10.4",
|
|
68
67
|
"@commitlint/cli": "^8.3.5",
|
|
69
68
|
"@commitlint/config-conventional": "^8.3.4",
|
|
70
69
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
|
71
70
|
"@typescript-eslint/parser": "^4.22.0",
|
|
72
|
-
"clean-webpack-plugin": "1.0.1",
|
|
73
|
-
"eslint": "6.8.0",
|
|
74
|
-
"eslint-config-standard": "14.1.0",
|
|
75
|
-
"eslint-plugin-import": "2.20.1",
|
|
76
|
-
"eslint-plugin-node": "11.0.0",
|
|
77
|
-
"eslint-plugin-promise": "4.2.1",
|
|
78
|
-
"eslint-plugin-standard": "4.0.1",
|
|
71
|
+
"clean-webpack-plugin": "^1.0.1",
|
|
72
|
+
"eslint": "^6.8.0",
|
|
73
|
+
"eslint-config-standard": "^14.1.0",
|
|
74
|
+
"eslint-plugin-import": "^2.20.1",
|
|
75
|
+
"eslint-plugin-node": "^11.0.0",
|
|
76
|
+
"eslint-plugin-promise": "^4.2.1",
|
|
77
|
+
"eslint-plugin-standard": "^4.0.1",
|
|
79
78
|
"execa": "^4.1.0",
|
|
80
|
-
"html-webpack-plugin": "3.2.0",
|
|
81
|
-
"husky": "4.3.8",
|
|
79
|
+
"html-webpack-plugin": "^3.2.0",
|
|
80
|
+
"husky": "^4.3.8",
|
|
82
81
|
"jest": "^27.5.1",
|
|
83
|
-
"lint-staged": "10.0.8",
|
|
84
|
-
"prettier": "1.19.1",
|
|
85
|
-
"prettier-eslint-cli": "5.0.0",
|
|
82
|
+
"lint-staged": "^10.0.8",
|
|
83
|
+
"prettier": "^1.19.1",
|
|
84
|
+
"prettier-eslint-cli": "^5.0.0",
|
|
86
85
|
"rollup": "^1.31.1",
|
|
87
86
|
"rollup-plugin-babel": "^4.3.3",
|
|
88
87
|
"rollup-plugin-cleaner": "^1.0.0",
|
|
89
88
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
90
89
|
"rollup-plugin-terser": "^7.0.2",
|
|
91
90
|
"rollup-plugin-typescript2": "^0.27.2",
|
|
92
|
-
"ts-loader": "8.0.2",
|
|
93
|
-
"typedoc": "0.18.0",
|
|
94
|
-
"typescript": "3.9.7",
|
|
95
|
-
"webpack": "4.30.0",
|
|
96
|
-
"webpack-cli": "3.3.2",
|
|
97
|
-
"webpack-dev-server": "3.10.3"
|
|
91
|
+
"ts-loader": "^8.0.2",
|
|
92
|
+
"typedoc": "^0.18.0",
|
|
93
|
+
"typescript": "^3.9.7",
|
|
94
|
+
"webpack": "^4.30.0",
|
|
95
|
+
"webpack-cli": "^3.3.2",
|
|
96
|
+
"webpack-dev-server": "^3.10.3"
|
|
98
97
|
},
|
|
99
98
|
"husky": {
|
|
100
99
|
"hooks": {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
/* eslint-disable no-undef */
|
|
3
|
+
// Github Helper
|
|
4
|
+
const execa = require('execa');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Release code.
|
|
8
|
+
*
|
|
9
|
+
* Example: Release code with version by `process.env.VERSION` or `package.json`.
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* const pkgVersion = process.env.VERSION || require('../package.json').version;
|
|
13
|
+
* release(pkgVersion);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
async function release (ver) {
|
|
17
|
+
const releaseVersion = `v${ver}`;
|
|
18
|
+
const { stdout: releaseStdout } = await execa('echo', [`Start release ${releaseVersion}...`]);
|
|
19
|
+
console.log(releaseStdout);
|
|
20
|
+
// Commit Stdout
|
|
21
|
+
const { stdout: diffStdout } = await execa('git', ['diff'], { stdio: 'pipe' });
|
|
22
|
+
if (diffStdout) {
|
|
23
|
+
console.log('Committing changes...');
|
|
24
|
+
await execa('git', ['add', '-A']);
|
|
25
|
+
await execa('git', ['commit', '-m', `release: ${releaseVersion}`]);
|
|
26
|
+
} else {
|
|
27
|
+
console.log('No changes to commit.');
|
|
28
|
+
}
|
|
29
|
+
// Push
|
|
30
|
+
console.log('Pushing to GitHub...');
|
|
31
|
+
await execa('git', ['tag', '-a', `${releaseVersion}`, '-m', `Release ${releaseVersion}`]);
|
|
32
|
+
await execa('git', ['push', 'origin', `refs/tags/${releaseVersion}`]);
|
|
33
|
+
await execa('git', ['push']);
|
|
34
|
+
|
|
35
|
+
console.log('All done.');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
release,
|
|
40
|
+
};
|
package/scripts/release.js
CHANGED
|
@@ -1,28 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
2
|
/* eslint-disable no-undef */
|
|
3
3
|
// release
|
|
4
|
-
const
|
|
4
|
+
const { release } = require('./github-helper');
|
|
5
5
|
const pkgVersion = process.env.VERSION || require('../package.json').version;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
(async () => {
|
|
9
|
-
const releaseVersion = `v${pkgVersion}`;
|
|
10
|
-
const { stdout: releaseStdout } = await execa('echo', [`Start release ${releaseVersion}...`]);
|
|
11
|
-
console.log(releaseStdout);
|
|
12
|
-
// Commit Stdout
|
|
13
|
-
const { stdout: diffStdout } = await execa('git', ['diff'], { stdio: 'pipe' });
|
|
14
|
-
if (diffStdout) {
|
|
15
|
-
console.log('Committing changes...');
|
|
16
|
-
await execa('git', ['add', '-A']);
|
|
17
|
-
await execa('git', ['commit', '-m', `release: ${releaseVersion}`]);
|
|
18
|
-
} else {
|
|
19
|
-
console.log('No changes to commit.');
|
|
20
|
-
}
|
|
21
|
-
// Push
|
|
22
|
-
console.log('Pushing to GitHub...');
|
|
23
|
-
await execa('git', ['tag', '-a', `${releaseVersion}`, '-m', `Release ${releaseVersion}`]);
|
|
24
|
-
await execa('git', ['push', 'origin', `refs/tags/${releaseVersion}`]);
|
|
25
|
-
await execa('git', ['push']);
|
|
26
|
-
|
|
27
|
-
console.log('All done.');
|
|
28
|
-
})();
|
|
7
|
+
release(pkgVersion);
|
package/src/index.ts
CHANGED
|
@@ -347,9 +347,10 @@ export function removeClass(obj: any, cls: string): void {
|
|
|
347
347
|
|
|
348
348
|
/**
|
|
349
349
|
* EN: Throttle
|
|
350
|
+
*
|
|
350
351
|
* ZH: 节流
|
|
351
352
|
*
|
|
352
|
-
*
|
|
353
|
+
* Reference: [Lodash](https://lodash.com/docs/4.17.15#throttle)
|
|
353
354
|
*/
|
|
354
355
|
export function throttle(func: any, wait: number, options: { leading?: boolean; trailing?: boolean; } = {}): any {
|
|
355
356
|
options = Object.assign(
|
|
@@ -402,6 +403,14 @@ export function throttle(func: any, wait: number, options: { leading?: boolean;
|
|
|
402
403
|
* EN: Debounce
|
|
403
404
|
*
|
|
404
405
|
* ZH: 去抖
|
|
406
|
+
*
|
|
407
|
+
* Usage:
|
|
408
|
+
*
|
|
409
|
+
* ```
|
|
410
|
+
* const foo = debounce(() => {
|
|
411
|
+
* console.log('The debounced function will only be invoked in 1000 milliseconds, the other invoking will disappear during the wait time.');
|
|
412
|
+
* }, 1000, true);
|
|
413
|
+
* ```
|
|
405
414
|
*/
|
|
406
415
|
export function debounce(func: any, wait: number, immediate?: any): any {
|
|
407
416
|
let context: any = null;
|
|
@@ -1501,24 +1510,28 @@ export function genCustomConsole(prefix = ''): Console {
|
|
|
1501
1510
|
|
|
1502
1511
|
/**
|
|
1503
1512
|
* Verify the validity of axios response.
|
|
1513
|
+
*
|
|
1514
|
+
* Reference: [Handling Errors](https://axios-http.com/docs/handling_errors)
|
|
1504
1515
|
*/
|
|
1505
1516
|
export function zAxiosIsValidRes(res: any, options: {
|
|
1506
|
-
|
|
1517
|
+
validStatusRange: number[];
|
|
1507
1518
|
validCode: number[];
|
|
1508
1519
|
} = {
|
|
1509
|
-
|
|
1520
|
+
validStatusRange: [200, 300],
|
|
1510
1521
|
validCode: [0],
|
|
1511
1522
|
}): boolean {
|
|
1512
|
-
const {
|
|
1523
|
+
const { validStatusRange, validCode } = Object.assign(
|
|
1513
1524
|
{
|
|
1514
|
-
|
|
1525
|
+
validStatusRange: [200, 300],
|
|
1515
1526
|
validCode: [0],
|
|
1516
1527
|
},
|
|
1517
1528
|
options,
|
|
1518
1529
|
);
|
|
1530
|
+
if (validStatusRange.length !== 2) {
|
|
1531
|
+
console.error('valid validStatusRange is required');
|
|
1532
|
+
}
|
|
1519
1533
|
let ret = false;
|
|
1520
|
-
if (res && res.status &&
|
|
1521
|
-
ret = true;
|
|
1534
|
+
if (res && res.status && validStatusRange.length === 2 && res.status >= validStatusRange[0] && res.status < validStatusRange[1]) {
|
|
1522
1535
|
const resData = res.data;
|
|
1523
1536
|
if (resData && validCode.includes(resData.code)) {
|
|
1524
1537
|
ret = true;
|
|
@@ -1563,7 +1576,7 @@ export function getFileSize(size: number): string {
|
|
|
1563
1576
|
/**
|
|
1564
1577
|
* Detect webp support.
|
|
1565
1578
|
*
|
|
1566
|
-
*
|
|
1579
|
+
* Reference: [Detect WEBP Support with JavaScript](https://davidwalsh.name/detect-webp)
|
|
1567
1580
|
*/
|
|
1568
1581
|
export function isSupportWebp(): Promise<boolean> {
|
|
1569
1582
|
const fn = (resolve: (v: boolean) => void) => {
|
|
@@ -1582,7 +1595,7 @@ export function isSupportWebp(): Promise<boolean> {
|
|
|
1582
1595
|
/**
|
|
1583
1596
|
* Generate a Hash Code from a string.
|
|
1584
1597
|
*
|
|
1585
|
-
*
|
|
1598
|
+
* Reference: [Generate a Hash from string in Javascript](https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery)
|
|
1586
1599
|
*/
|
|
1587
1600
|
export function genHashCode(str: string): number {
|
|
1588
1601
|
let hash = 0, i, chr;
|