@daysnap/utils 0.0.41 → 0.0.43
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 +24 -4
- package/docs/README.md +20 -4
- package/docs/modules.md +228 -93
- package/es/base64ToBlob.js +11 -17
- package/es/blobToBase64.js +10 -10
- package/es/canvasToBlob.js +4 -6
- package/es/clone.d.ts +4 -6
- package/es/clone.js +18 -8
- package/es/cloneSimple.d.ts +7 -0
- package/es/cloneSimple.js +9 -0
- package/es/compareVersion.js +27 -40
- package/es/compressImage.js +11 -13
- package/es/createHexColorByHash.js +59 -56
- package/es/debounce.d.ts +5 -0
- package/es/debounce.js +14 -0
- package/es/downloadFile.js +7 -7
- package/es/each.js +11 -10
- package/es/filterBankCardNo.js +4 -2
- package/es/filterCRLF.js +2 -2
- package/es/filterEmoji.js +13 -6
- package/es/filterIdCard.js +2 -2
- package/es/filterName.js +12 -12
- package/es/filterPhone.js +3 -4
- package/es/formatAmount.js +18 -20
- package/es/formatDate.js +28 -29
- package/es/getBlobByUrl.js +17 -18
- package/es/getDayMillisecond.js +3 -4
- package/es/getImageInfo.js +9 -9
- package/es/getRandomColor.js +2 -2
- package/es/getVideoInfo.js +11 -11
- package/es/inBrowser.js +2 -2
- package/es/index.d.ts +4 -0
- package/es/index.js +5 -1
- package/es/isAndroid.js +2 -2
- package/es/isArray.js +2 -2
- package/es/isBoolean.js +2 -2
- package/es/isEmail.js +2 -2
- package/es/isEmpty.js +2 -2
- package/es/isEmptyObject.js +2 -2
- package/es/isError.js +2 -2
- package/es/isFunction.js +2 -2
- package/es/isIOS.js +2 -2
- package/es/isIdCard.js +2 -2
- package/es/isJSONString.js +8 -7
- package/es/isLan.js +29 -28
- package/es/isLicenseCode.js +2 -2
- package/es/isMobile.js +7 -6
- package/es/isNull.js +2 -2
- package/es/isNumber.js +2 -2
- package/es/isObject.js +2 -2
- package/es/isPhone.js +2 -2
- package/es/isPromise.js +2 -2
- package/es/isRegExp.js +2 -2
- package/es/isString.js +2 -2
- package/es/isURL.d.ts +4 -0
- package/es/isURL.js +6 -0
- package/es/isUndefined.js +2 -2
- package/es/isWeixin.js +2 -2
- package/es/isWindow.js +2 -2
- package/es/loadResource.d.ts +1 -1
- package/es/loadResource.js +27 -23
- package/es/omit.js +7 -9
- package/es/padding.js +5 -5
- package/es/parseDate.js +7 -7
- package/es/parseError.js +15 -16
- package/es/parseObject.d.ts +2 -1
- package/es/parseObject.js +9 -8
- package/es/parsePath.js +7 -7
- package/es/parseQuery.d.ts +1 -1
- package/es/parseQuery.js +13 -24
- package/es/pick.js +7 -8
- package/es/replaceCrlf.js +2 -2
- package/es/reserve.js +2 -2
- package/es/round.js +38 -39
- package/es/sleep.d.ts +4 -2
- package/es/sleep.js +8 -7
- package/es/storage/factory.d.ts +2 -2
- package/es/storage/factory.js +44 -54
- package/es/storage/index.d.ts +4 -4
- package/es/storage/index.js +10 -10
- package/es/stringTrim.d.ts +3 -1
- package/es/stringTrim.js +17 -19
- package/es/stringifyQuery.d.ts +1 -1
- package/es/stringifyQuery.js +11 -8
- package/es/throttle.d.ts +5 -0
- package/es/throttle.js +17 -0
- package/es/typeOf.d.ts +1 -1
- package/es/typeOf.js +2 -2
- package/lib/base64ToBlob.js +14 -23
- package/lib/blobToBase64.js +13 -15
- package/lib/canvasToBlob.js +7 -11
- package/lib/clone.d.ts +4 -6
- package/lib/clone.js +21 -13
- package/lib/cloneSimple.d.ts +7 -0
- package/lib/cloneSimple.js +13 -0
- package/lib/compareVersion.js +30 -46
- package/lib/compressImage.js +15 -19
- package/lib/createHexColorByHash.js +60 -60
- package/lib/debounce.d.ts +5 -0
- package/lib/debounce.js +18 -0
- package/lib/downloadFile.js +10 -12
- package/lib/each.js +14 -15
- package/lib/filterBankCardNo.js +7 -7
- package/lib/filterCRLF.js +5 -7
- package/lib/filterEmoji.js +16 -11
- package/lib/filterIdCard.js +5 -7
- package/lib/filterName.js +15 -17
- package/lib/filterPhone.js +6 -9
- package/lib/formatAmount.js +21 -25
- package/lib/formatDate.js +32 -35
- package/lib/getBlobByUrl.js +20 -23
- package/lib/getDayMillisecond.js +6 -9
- package/lib/getImageInfo.js +12 -14
- package/lib/getRandomColor.js +5 -7
- package/lib/getVideoInfo.js +14 -16
- package/lib/inBrowser.js +5 -7
- package/lib/index.d.ts +4 -0
- package/lib/index.js +84 -708
- package/lib/isAndroid.js +5 -7
- package/lib/isArray.js +5 -7
- package/lib/isBoolean.js +5 -7
- package/lib/isEmail.js +5 -7
- package/lib/isEmpty.js +7 -9
- package/lib/isEmptyObject.js +5 -7
- package/lib/isError.js +5 -7
- package/lib/isFunction.js +5 -7
- package/lib/isIOS.js +5 -7
- package/lib/isIdCard.js +5 -7
- package/lib/isJSONString.js +12 -13
- package/lib/isLan.js +32 -33
- package/lib/isLicenseCode.js +5 -7
- package/lib/isMobile.js +10 -11
- package/lib/isNull.js +5 -7
- package/lib/isNumber.js +5 -7
- package/lib/isObject.js +5 -7
- package/lib/isPhone.js +5 -7
- package/lib/isPromise.js +5 -7
- package/lib/isRegExp.js +5 -7
- package/lib/isString.js +5 -7
- package/lib/isURL.d.ts +4 -0
- package/lib/isURL.js +10 -0
- package/lib/isUndefined.js +5 -7
- package/lib/isWeixin.js +5 -7
- package/lib/isWindow.js +5 -7
- package/lib/loadResource.d.ts +1 -1
- package/lib/loadResource.js +31 -29
- package/lib/omit.js +10 -15
- package/lib/padding.js +8 -10
- package/lib/parseDate.js +10 -12
- package/lib/parseError.js +21 -24
- package/lib/parseObject.d.ts +2 -1
- package/lib/parseObject.js +12 -13
- package/lib/parsePath.js +10 -12
- package/lib/parseQuery.d.ts +1 -1
- package/lib/parseQuery.js +17 -31
- package/lib/pick.js +10 -13
- package/lib/replaceCrlf.js +5 -7
- package/lib/reserve.js +6 -8
- package/lib/round.js +41 -44
- package/lib/sleep.d.ts +4 -2
- package/lib/sleep.js +11 -12
- package/lib/storage/factory.d.ts +2 -2
- package/lib/storage/factory.js +47 -60
- package/lib/storage/index.d.ts +4 -4
- package/lib/storage/index.js +12 -17
- package/lib/stringTrim.d.ts +3 -1
- package/lib/stringTrim.js +20 -24
- package/lib/stringifyQuery.d.ts +1 -1
- package/lib/stringifyQuery.js +15 -14
- package/lib/throttle.d.ts +5 -0
- package/lib/throttle.js +21 -0
- package/lib/typeOf.d.ts +1 -1
- package/lib/typeOf.js +5 -7
- package/package.json +23 -18
package/lib/formatDate.js
CHANGED
|
@@ -1,40 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.formatDate = formatDate;
|
|
7
|
-
var _isString = require("./isString");
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatDate = void 0;
|
|
4
|
+
const isString_1 = require("./isString");
|
|
8
5
|
/**
|
|
9
6
|
* 格式化日期
|
|
10
7
|
*/
|
|
11
|
-
function formatDate(val) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
fmt = fmt.replace(RegExp.$1, "".concat(date.getFullYear()).substr(4 - RegExp.$1.length));
|
|
31
|
-
}
|
|
32
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
33
|
-
for (var k in o) {
|
|
34
|
-
if (new RegExp("(".concat(k, ")")).test(fmt)) {
|
|
35
|
-
// eslint-disable-next-line no-param-reassign
|
|
36
|
-
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : "00".concat(o[k]).substr("".concat(o[k]).length));
|
|
8
|
+
function formatDate(val, fmt = 'yyyy-MM-dd hh:mm:ss') {
|
|
9
|
+
let v = val;
|
|
10
|
+
if ((0, isString_1.isString)(v)) {
|
|
11
|
+
// fix iOS new Date() 不支持 2020-01-01 格式,需转换为 2020/01/01
|
|
12
|
+
v = v.replace(/-/g, '/');
|
|
13
|
+
}
|
|
14
|
+
const date = new Date(v);
|
|
15
|
+
const o = {
|
|
16
|
+
'M+': date.getMonth() + 1,
|
|
17
|
+
'd+': date.getDate(),
|
|
18
|
+
'h+': date.getHours(),
|
|
19
|
+
'm+': date.getMinutes(),
|
|
20
|
+
's+': date.getSeconds(),
|
|
21
|
+
'q+': Math.floor((date.getMonth() + 3) / 3),
|
|
22
|
+
S: date.getMilliseconds(),
|
|
23
|
+
};
|
|
24
|
+
if (/(y+)/.test(fmt)) {
|
|
25
|
+
// eslint-disable-next-line no-param-reassign
|
|
26
|
+
fmt = fmt.replace(RegExp.$1, `${date.getFullYear()}`.substr(4 - RegExp.$1.length));
|
|
37
27
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
28
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
29
|
+
for (const k in o) {
|
|
30
|
+
if (new RegExp(`(${k})`).test(fmt)) {
|
|
31
|
+
// eslint-disable-next-line no-param-reassign
|
|
32
|
+
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : `00${o[k]}`.substr(`${o[k]}`.length));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return fmt;
|
|
36
|
+
}
|
|
37
|
+
exports.formatDate = formatDate;
|
package/lib/getBlobByUrl.js
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getBlobByUrl = getBlobByUrl;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBlobByUrl = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* 根据在线 url 返回 blob
|
|
9
6
|
*/
|
|
10
7
|
function getBlobByUrl(url) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const xhr = new XMLHttpRequest();
|
|
10
|
+
xhr.open('GET', url, true);
|
|
11
|
+
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
|
|
12
|
+
xhr.responseType = 'blob';
|
|
13
|
+
xhr.onload = () => {
|
|
14
|
+
const { status, response, statusText } = xhr;
|
|
15
|
+
if (status >= 200 && status < 300) {
|
|
16
|
+
resolve(response);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
reject(new Error(`${statusText}[${status}]`));
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
xhr.send();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.getBlobByUrl = getBlobByUrl;
|
package/lib/getDayMillisecond.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getDayMillisecond = getDayMillisecond;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDayMillisecond = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* 获取多少天的毫秒数 默认获取1天的
|
|
9
6
|
*/
|
|
10
|
-
function getDayMillisecond() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
function getDayMillisecond(day = 1) {
|
|
8
|
+
return day * 24 * 60 * 60 * 1000;
|
|
9
|
+
}
|
|
10
|
+
exports.getDayMillisecond = getDayMillisecond;
|
package/lib/getImageInfo.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getImageInfo = getImageInfo;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getImageInfo = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* 获取图片信息
|
|
9
6
|
*/
|
|
10
7
|
function getImageInfo(src) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const image = new Image();
|
|
10
|
+
image.onload = () => {
|
|
11
|
+
resolve(image);
|
|
12
|
+
};
|
|
13
|
+
image.onerror = reject;
|
|
14
|
+
image.src = src;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
exports.getImageInfo = getImageInfo;
|
package/lib/getRandomColor.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getRandomColor = getRandomColor;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRandomColor = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* 随机颜色
|
|
9
6
|
*/
|
|
10
7
|
function getRandomColor() {
|
|
11
|
-
|
|
12
|
-
}
|
|
8
|
+
return `#${Math.floor(Math.random() * 0xffffff).toString(16)}`;
|
|
9
|
+
}
|
|
10
|
+
exports.getRandomColor = getRandomColor;
|
package/lib/getVideoInfo.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getVideoInfo = getVideoInfo;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVideoInfo = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* 获取 video 信息
|
|
9
6
|
*/
|
|
10
7
|
function getVideoInfo(src) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const video = document.createElement('video');
|
|
10
|
+
video.preload = 'metadata';
|
|
11
|
+
video.muted = true;
|
|
12
|
+
video.onerror = reject;
|
|
13
|
+
video.onloadedmetadata = () => {
|
|
14
|
+
resolve(video);
|
|
15
|
+
};
|
|
16
|
+
video.src = src;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
exports.getVideoInfo = getVideoInfo;
|
package/lib/inBrowser.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.inBrowser = inBrowser;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inBrowser = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* 判断是否是浏览器环境
|
|
9
6
|
*/
|
|
10
7
|
function inBrowser() {
|
|
11
|
-
|
|
12
|
-
}
|
|
8
|
+
return typeof window !== 'undefined';
|
|
9
|
+
}
|
|
10
|
+
exports.inBrowser = inBrowser;
|
package/lib/index.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ export * from './base64ToBlob';
|
|
|
2
2
|
export * from './blobToBase64';
|
|
3
3
|
export * from './canvasToBlob';
|
|
4
4
|
export * from './clone';
|
|
5
|
+
export * from './cloneSimple';
|
|
5
6
|
export * from './compareVersion';
|
|
6
7
|
export * from './compressImage';
|
|
7
8
|
export * from './createHexColorByHash';
|
|
9
|
+
export * from './debounce';
|
|
8
10
|
export * from './downloadFile';
|
|
9
11
|
export * from './each';
|
|
10
12
|
export * from './filterBankCardNo';
|
|
@@ -42,6 +44,7 @@ export * from './isPhone';
|
|
|
42
44
|
export * from './isPromise';
|
|
43
45
|
export * from './isRegExp';
|
|
44
46
|
export * from './isString';
|
|
47
|
+
export * from './isURL';
|
|
45
48
|
export * from './isUndefined';
|
|
46
49
|
export * from './isWeixin';
|
|
47
50
|
export * from './isWindow';
|
|
@@ -61,4 +64,5 @@ export * from './sleep';
|
|
|
61
64
|
export * from './storage';
|
|
62
65
|
export * from './stringTrim';
|
|
63
66
|
export * from './stringifyQuery';
|
|
67
|
+
export * from './throttle';
|
|
64
68
|
export * from './typeOf';
|