@daysnap/utils 0.0.41 → 0.0.42
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 +21 -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 +15 -17
package/es/base64ToBlob.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
/**
|
|
3
2
|
* base64 转 blob
|
|
4
3
|
* @param base64 base64字符串
|
|
5
4
|
* @param contentType 文件类型
|
|
6
5
|
*/
|
|
7
6
|
export function base64ToBlob(base64, contentType) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
return new Blob([u8arr], {
|
|
21
|
-
type: type
|
|
22
|
-
});
|
|
23
|
-
}
|
|
7
|
+
var _a;
|
|
8
|
+
const [prefix, rest] = base64.split(',');
|
|
9
|
+
const type = contentType !== null && contentType !== void 0 ? contentType : (_a = prefix.match(/:(.*?);/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
10
|
+
const data = window.atob(rest);
|
|
11
|
+
let len = data.length;
|
|
12
|
+
const u8arr = new Uint8Array(len);
|
|
13
|
+
while (len--) {
|
|
14
|
+
u8arr[len] = data.charCodeAt(len);
|
|
15
|
+
}
|
|
16
|
+
return new Blob([u8arr], { type });
|
|
17
|
+
}
|
package/es/blobToBase64.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
* blob 转 base64
|
|
3
3
|
*/
|
|
4
4
|
export function blobToBase64(blob) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
const fileReader = new FileReader();
|
|
7
|
+
fileReader.onload = (res) => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
resolve((_b = (_a = res.target) === null || _a === void 0 ? void 0 : _a.result) !== null && _b !== void 0 ? _b : '');
|
|
10
|
+
};
|
|
11
|
+
fileReader.onerror = reject;
|
|
12
|
+
fileReader.readAsDataURL(blob);
|
|
13
|
+
});
|
|
14
|
+
}
|
package/es/canvasToBlob.js
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
* canvas 转 blob 文件
|
|
3
3
|
*/
|
|
4
4
|
export function canvasToBlob(canvas, type, quality) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
}
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
canvas.toBlob((data) => data ? resolve(data) : reject(new Error('canvas toBlob is null')), type, quality);
|
|
7
|
+
});
|
|
8
|
+
}
|
package/es/clone.d.ts
CHANGED
package/es/clone.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
import { isArray } from './isArray';
|
|
2
|
+
import { isObject } from './isObject';
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param
|
|
4
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
4
|
+
* 深拷贝
|
|
5
|
+
* @param source 需要转换的值
|
|
6
|
+
* */
|
|
7
|
+
export function clone(source) {
|
|
8
|
+
if (!isArray(source) && !isObject(source)) {
|
|
9
|
+
return source;
|
|
10
|
+
}
|
|
11
|
+
const target = (isArray(source) ? [] : {});
|
|
12
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
13
|
+
for (const key in source) {
|
|
14
|
+
if (source.hasOwnProperty(key)) {
|
|
15
|
+
target[key] = clone(source[key]);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
}
|
package/es/compareVersion.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
1
|
/**
|
|
3
2
|
* 比对版本
|
|
4
3
|
* -1 => nv < v
|
|
@@ -8,45 +7,33 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
8
7
|
* @param v 版本
|
|
9
8
|
*/
|
|
10
9
|
export function compareVersion(nv, v) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
_nv$split$map2$ = _nv$split$map2[0],
|
|
16
|
-
H = _nv$split$map2$ === void 0 ? 0 : _nv$split$map2$,
|
|
17
|
-
_nv$split$map2$2 = _nv$split$map2[1],
|
|
18
|
-
T = _nv$split$map2$2 === void 0 ? 0 : _nv$split$map2$2,
|
|
19
|
-
_nv$split$map2$3 = _nv$split$map2[2],
|
|
20
|
-
S = _nv$split$map2$3 === void 0 ? 0 : _nv$split$map2$3; // 新
|
|
21
|
-
var _v$split$map = v.split('.').map(function (i) {
|
|
22
|
-
return +i;
|
|
23
|
-
}),
|
|
24
|
-
_v$split$map2 = _slicedToArray(_v$split$map, 3),
|
|
25
|
-
_v$split$map2$ = _v$split$map2[0],
|
|
26
|
-
h = _v$split$map2$ === void 0 ? 0 : _v$split$map2$,
|
|
27
|
-
_v$split$map2$2 = _v$split$map2[1],
|
|
28
|
-
t = _v$split$map2$2 === void 0 ? 0 : _v$split$map2$2,
|
|
29
|
-
_v$split$map2$3 = _v$split$map2[2],
|
|
30
|
-
s = _v$split$map2$3 === void 0 ? 0 : _v$split$map2$3; // 本
|
|
31
|
-
var result = 0;
|
|
32
|
-
if (H > h) {
|
|
33
|
-
result = 1;
|
|
34
|
-
} else if (H === h) {
|
|
35
|
-
if (T > t) {
|
|
36
|
-
result = 1;
|
|
37
|
-
} else if (T === t) {
|
|
38
|
-
if (S > s) {
|
|
10
|
+
const [H = 0, T = 0, S = 0] = nv.split('.').map((i) => +i); // 新
|
|
11
|
+
const [h = 0, t = 0, s = 0] = v.split('.').map((i) => +i); // 本
|
|
12
|
+
let result = 0;
|
|
13
|
+
if (H > h) {
|
|
39
14
|
result = 1;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
15
|
+
}
|
|
16
|
+
else if (H === h) {
|
|
17
|
+
if (T > t) {
|
|
18
|
+
result = 1;
|
|
19
|
+
}
|
|
20
|
+
else if (T === t) {
|
|
21
|
+
if (S > s) {
|
|
22
|
+
result = 1;
|
|
23
|
+
}
|
|
24
|
+
else if (S === s) {
|
|
25
|
+
result = 0;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
result = -1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
result = -1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
43
36
|
result = -1;
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
result = -1;
|
|
47
37
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
package/es/compressImage.js
CHANGED
|
@@ -3,16 +3,14 @@ import { pick } from './pick';
|
|
|
3
3
|
* 压缩图片
|
|
4
4
|
*/
|
|
5
5
|
export function compressImage(image) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return canvas;
|
|
18
|
-
}
|
|
6
|
+
const { width, height } = pick(image, ['width', 'height']);
|
|
7
|
+
const canvas = document.createElement('canvas');
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
9
|
+
const ctx = canvas.getContext('2d');
|
|
10
|
+
canvas.width = width;
|
|
11
|
+
canvas.height = height;
|
|
12
|
+
ctx.fillStyle = '#fff';
|
|
13
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
14
|
+
ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
|
|
15
|
+
return canvas;
|
|
16
|
+
}
|
|
@@ -1,60 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 根据字符串hash值生成颜色值
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
export const colorGenByHash = (str) => {
|
|
5
|
+
const lsL = [0.35, 0.5, 0.65];
|
|
6
|
+
const lsS = [0.35, 0.5, 0.65];
|
|
7
|
+
const seed = 131;
|
|
8
|
+
const seed2 = 137;
|
|
9
|
+
let hash = 0;
|
|
10
|
+
// eslint-disable-next-line no-param-reassign
|
|
11
|
+
str += 'x';
|
|
12
|
+
const MAX_SAFE_INTEGER = parseInt((9007199254740991 / seed2).toString(), 10);
|
|
13
|
+
for (let i = 0; i < str.length; i++) {
|
|
14
|
+
if (hash > MAX_SAFE_INTEGER) {
|
|
15
|
+
hash = parseInt((hash / seed2).toString(), 10);
|
|
16
|
+
}
|
|
17
|
+
hash = hash * seed + str.charCodeAt(i);
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
19
|
+
let H;
|
|
20
|
+
H = hash % 359;
|
|
21
|
+
hash = parseInt((hash / 360).toString(), 10);
|
|
22
|
+
const S = lsS[hash % lsS.length];
|
|
23
|
+
hash = parseInt((hash / lsS.length).toString(), 10);
|
|
24
|
+
const L = lsL[hash % lsL.length];
|
|
25
|
+
H /= 360;
|
|
26
|
+
const q = L < 0.5 ? L * (1 + S) : L + S - L * S;
|
|
27
|
+
const p = 2 * L - q;
|
|
28
|
+
const RGBArray = [H + 1 / 3, H, H - 1 / 3].map((color) => {
|
|
29
|
+
if (color < 0) {
|
|
30
|
+
// eslint-disable-next-line no-param-reassign
|
|
31
|
+
color++;
|
|
32
|
+
}
|
|
33
|
+
if (color > 1) {
|
|
34
|
+
// eslint-disable-next-line no-param-reassign
|
|
35
|
+
color--;
|
|
36
|
+
}
|
|
37
|
+
if (color < 1 / 6) {
|
|
38
|
+
// eslint-disable-next-line no-param-reassign
|
|
39
|
+
color = p + (q - p) * 6 * color;
|
|
40
|
+
}
|
|
41
|
+
else if (color < 0.5) {
|
|
42
|
+
// eslint-disable-next-line no-param-reassign
|
|
43
|
+
color = q;
|
|
44
|
+
}
|
|
45
|
+
else if (color < 2 / 3) {
|
|
46
|
+
// eslint-disable-next-line no-param-reassign
|
|
47
|
+
color = p + (q - p) * 6 * (2 / 3 - color);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// eslint-disable-next-line no-param-reassign
|
|
51
|
+
color = p;
|
|
52
|
+
}
|
|
53
|
+
return Math.round(color * 255);
|
|
54
|
+
});
|
|
55
|
+
let hex = '#';
|
|
56
|
+
RGBArray.forEach((value) => {
|
|
57
|
+
if (value < 16) {
|
|
58
|
+
hex += 0;
|
|
59
|
+
}
|
|
60
|
+
hex += value.toString(16);
|
|
61
|
+
});
|
|
62
|
+
return hex;
|
|
63
|
+
};
|
package/es/debounce.d.ts
ADDED
package/es/debounce.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 防抖函数
|
|
3
|
+
* 事件频繁触发,只会执行最后一次
|
|
4
|
+
*/
|
|
5
|
+
export function debounce(fn, ms) {
|
|
6
|
+
let timer = null;
|
|
7
|
+
// eslint-disable-next-line func-names
|
|
8
|
+
return function (...args) {
|
|
9
|
+
clearTimeout(timer);
|
|
10
|
+
timer = setTimeout(() => {
|
|
11
|
+
fn.apply(this, args);
|
|
12
|
+
}, ms);
|
|
13
|
+
};
|
|
14
|
+
}
|
package/es/downloadFile.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* 通过 a 标签下载文件
|
|
3
3
|
*/
|
|
4
4
|
export function downloadFile(data, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
5
|
+
const a = document.createElement('a');
|
|
6
|
+
a.href = typeof data === 'string' ? data : URL.createObjectURL(data);
|
|
7
|
+
if (options === null || options === void 0 ? void 0 : options.fileName) {
|
|
8
|
+
a.download = options.fileName;
|
|
9
|
+
}
|
|
10
|
+
a.click();
|
|
11
|
+
}
|
package/es/each.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export function each(data, callback) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
if (Array.isArray(data)) {
|
|
3
|
+
// eslint-disable-next-line no-plusplus
|
|
4
|
+
for (let index = 0, { length } = data; index < length; index++) {
|
|
5
|
+
callback.call(data[index], data[index], index);
|
|
6
|
+
}
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
8
|
+
else {
|
|
9
|
+
Object.keys(data).forEach((key) => {
|
|
10
|
+
callback.call(data[key], data[key], key);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
package/es/filterBankCardNo.js
CHANGED
|
@@ -2,5 +2,7 @@
|
|
|
2
2
|
* 过滤银行卡号
|
|
3
3
|
*/
|
|
4
4
|
export function filterBankCardNo(val) {
|
|
5
|
-
|
|
6
|
-
}
|
|
5
|
+
return val
|
|
6
|
+
? `${new Array(val.length - 3).join('*')}${val.substring(val.length - 4)}`.replace(/(.{4})/g, '$1 ')
|
|
7
|
+
: '';
|
|
8
|
+
}
|
package/es/filterCRLF.js
CHANGED
package/es/filterEmoji.js
CHANGED
|
@@ -2,9 +2,16 @@
|
|
|
2
2
|
* 过滤emoji
|
|
3
3
|
*/
|
|
4
4
|
export function filterEmoji(val) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
if (!val) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
const ranges = [
|
|
9
|
+
'\uD83C[\uDF00-\uDFFF]',
|
|
10
|
+
'\uD83D[\uDC00-\uDE4F]',
|
|
11
|
+
'\ud83d[\ude80-\udeff]',
|
|
12
|
+
'[\uD800-\uDBFF]',
|
|
13
|
+
'[\uDC00-\uDFFF]',
|
|
14
|
+
'[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]',
|
|
15
|
+
];
|
|
16
|
+
return val.replace(new RegExp(ranges.join('|'), 'g'), '');
|
|
17
|
+
}
|
package/es/filterIdCard.js
CHANGED
package/es/filterName.js
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
* 过滤姓名
|
|
3
3
|
*/
|
|
4
4
|
export function filterName(val) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
5
|
+
if (!val) {
|
|
6
|
+
return '';
|
|
7
|
+
}
|
|
8
|
+
const len = val.length;
|
|
9
|
+
if (len === 1) {
|
|
10
|
+
return val;
|
|
11
|
+
}
|
|
12
|
+
if (len === 2) {
|
|
13
|
+
return `${val.substring(0, 1)}*`;
|
|
14
|
+
}
|
|
15
|
+
return `${val.substring(0, 1)}${new Array(len - 1).join('*')}${val.substr(-1)}`;
|
|
16
|
+
}
|
package/es/filterPhone.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* filterPhone('13177778888') => 131****8888
|
|
4
4
|
* filterPhone('13177778888', ' ') => 131 **** 8888
|
|
5
5
|
*/
|
|
6
|
-
export function filterPhone(val) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
6
|
+
export function filterPhone(val, sep = '') {
|
|
7
|
+
return val ? `${val.substring(0, 3)}${sep}****${sep}${val.substring(7)}` : '';
|
|
8
|
+
}
|
package/es/formatAmount.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 格式化金额,默认元
|
|
3
3
|
*/
|
|
4
|
-
export function formatAmount(s) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return '
|
|
21
|
-
|
|
22
|
-
return '---';
|
|
23
|
-
}
|
|
4
|
+
export function formatAmount(s, radix = 1) {
|
|
5
|
+
const money = parseFloat(s === null || s === void 0 ? void 0 : s.toString());
|
|
6
|
+
if (money) {
|
|
7
|
+
// eslint-disable-next-line no-param-reassign
|
|
8
|
+
s = `${(money / radix).toFixed(2)}`;
|
|
9
|
+
const l = s.split('.')[0].split('').reverse();
|
|
10
|
+
const r = s.split('.')[1];
|
|
11
|
+
let t = '';
|
|
12
|
+
l.forEach((_, key) => {
|
|
13
|
+
t += l[key] + ((key + 1) % 3 === 0 && key + 1 !== l.length ? ',' : '');
|
|
14
|
+
});
|
|
15
|
+
return `${t.split('').reverse().join('')}.${r}`;
|
|
16
|
+
}
|
|
17
|
+
if (+s === 0) {
|
|
18
|
+
return '0.00';
|
|
19
|
+
}
|
|
20
|
+
return '---';
|
|
21
|
+
}
|
package/es/formatDate.js
CHANGED
|
@@ -2,33 +2,32 @@ import { isString } from './isString';
|
|
|
2
2
|
/**
|
|
3
3
|
* 格式化日期
|
|
4
4
|
*/
|
|
5
|
-
export function formatDate(val) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
v = v.replace(/-/g, '/');
|
|
11
|
-
}
|
|
12
|
-
var date = new Date(v);
|
|
13
|
-
var o = {
|
|
14
|
-
'M+': date.getMonth() + 1,
|
|
15
|
-
'd+': date.getDate(),
|
|
16
|
-
'h+': date.getHours(),
|
|
17
|
-
'm+': date.getMinutes(),
|
|
18
|
-
's+': date.getSeconds(),
|
|
19
|
-
'q+': Math.floor((date.getMonth() + 3) / 3),
|
|
20
|
-
S: date.getMilliseconds()
|
|
21
|
-
};
|
|
22
|
-
if (/(y+)/.test(fmt)) {
|
|
23
|
-
// eslint-disable-next-line no-param-reassign
|
|
24
|
-
fmt = fmt.replace(RegExp.$1, "".concat(date.getFullYear()).substr(4 - RegExp.$1.length));
|
|
25
|
-
}
|
|
26
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
27
|
-
for (var k in o) {
|
|
28
|
-
if (new RegExp("(".concat(k, ")")).test(fmt)) {
|
|
29
|
-
// eslint-disable-next-line no-param-reassign
|
|
30
|
-
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : "00".concat(o[k]).substr("".concat(o[k]).length));
|
|
5
|
+
export function formatDate(val, fmt = 'yyyy-MM-dd hh:mm:ss') {
|
|
6
|
+
let v = val;
|
|
7
|
+
if (isString(v)) {
|
|
8
|
+
// fix iOS new Date() 不支持 2020-01-01 格式,需转换为 2020/01/01
|
|
9
|
+
v = v.replace(/-/g, '/');
|
|
31
10
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
const date = new Date(v);
|
|
12
|
+
const o = {
|
|
13
|
+
'M+': date.getMonth() + 1,
|
|
14
|
+
'd+': date.getDate(),
|
|
15
|
+
'h+': date.getHours(),
|
|
16
|
+
'm+': date.getMinutes(),
|
|
17
|
+
's+': date.getSeconds(),
|
|
18
|
+
'q+': Math.floor((date.getMonth() + 3) / 3),
|
|
19
|
+
S: date.getMilliseconds(),
|
|
20
|
+
};
|
|
21
|
+
if (/(y+)/.test(fmt)) {
|
|
22
|
+
// eslint-disable-next-line no-param-reassign
|
|
23
|
+
fmt = fmt.replace(RegExp.$1, `${date.getFullYear()}`.substr(4 - RegExp.$1.length));
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
26
|
+
for (const k in o) {
|
|
27
|
+
if (new RegExp(`(${k})`).test(fmt)) {
|
|
28
|
+
// eslint-disable-next-line no-param-reassign
|
|
29
|
+
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : `00${o[k]}`.substr(`${o[k]}`.length));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return fmt;
|
|
33
|
+
}
|