@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.
Files changed (174) hide show
  1. package/README.md +24 -4
  2. package/docs/README.md +20 -4
  3. package/docs/modules.md +228 -93
  4. package/es/base64ToBlob.js +11 -17
  5. package/es/blobToBase64.js +10 -10
  6. package/es/canvasToBlob.js +4 -6
  7. package/es/clone.d.ts +4 -6
  8. package/es/clone.js +18 -8
  9. package/es/cloneSimple.d.ts +7 -0
  10. package/es/cloneSimple.js +9 -0
  11. package/es/compareVersion.js +27 -40
  12. package/es/compressImage.js +11 -13
  13. package/es/createHexColorByHash.js +59 -56
  14. package/es/debounce.d.ts +5 -0
  15. package/es/debounce.js +14 -0
  16. package/es/downloadFile.js +7 -7
  17. package/es/each.js +11 -10
  18. package/es/filterBankCardNo.js +4 -2
  19. package/es/filterCRLF.js +2 -2
  20. package/es/filterEmoji.js +13 -6
  21. package/es/filterIdCard.js +2 -2
  22. package/es/filterName.js +12 -12
  23. package/es/filterPhone.js +3 -4
  24. package/es/formatAmount.js +18 -20
  25. package/es/formatDate.js +28 -29
  26. package/es/getBlobByUrl.js +17 -18
  27. package/es/getDayMillisecond.js +3 -4
  28. package/es/getImageInfo.js +9 -9
  29. package/es/getRandomColor.js +2 -2
  30. package/es/getVideoInfo.js +11 -11
  31. package/es/inBrowser.js +2 -2
  32. package/es/index.d.ts +4 -0
  33. package/es/index.js +5 -1
  34. package/es/isAndroid.js +2 -2
  35. package/es/isArray.js +2 -2
  36. package/es/isBoolean.js +2 -2
  37. package/es/isEmail.js +2 -2
  38. package/es/isEmpty.js +2 -2
  39. package/es/isEmptyObject.js +2 -2
  40. package/es/isError.js +2 -2
  41. package/es/isFunction.js +2 -2
  42. package/es/isIOS.js +2 -2
  43. package/es/isIdCard.js +2 -2
  44. package/es/isJSONString.js +8 -7
  45. package/es/isLan.js +29 -28
  46. package/es/isLicenseCode.js +2 -2
  47. package/es/isMobile.js +7 -6
  48. package/es/isNull.js +2 -2
  49. package/es/isNumber.js +2 -2
  50. package/es/isObject.js +2 -2
  51. package/es/isPhone.js +2 -2
  52. package/es/isPromise.js +2 -2
  53. package/es/isRegExp.js +2 -2
  54. package/es/isString.js +2 -2
  55. package/es/isURL.d.ts +4 -0
  56. package/es/isURL.js +6 -0
  57. package/es/isUndefined.js +2 -2
  58. package/es/isWeixin.js +2 -2
  59. package/es/isWindow.js +2 -2
  60. package/es/loadResource.d.ts +1 -1
  61. package/es/loadResource.js +27 -23
  62. package/es/omit.js +7 -9
  63. package/es/padding.js +5 -5
  64. package/es/parseDate.js +7 -7
  65. package/es/parseError.js +15 -16
  66. package/es/parseObject.d.ts +2 -1
  67. package/es/parseObject.js +9 -8
  68. package/es/parsePath.js +7 -7
  69. package/es/parseQuery.d.ts +1 -1
  70. package/es/parseQuery.js +13 -24
  71. package/es/pick.js +7 -8
  72. package/es/replaceCrlf.js +2 -2
  73. package/es/reserve.js +2 -2
  74. package/es/round.js +38 -39
  75. package/es/sleep.d.ts +4 -2
  76. package/es/sleep.js +8 -7
  77. package/es/storage/factory.d.ts +2 -2
  78. package/es/storage/factory.js +44 -54
  79. package/es/storage/index.d.ts +4 -4
  80. package/es/storage/index.js +10 -10
  81. package/es/stringTrim.d.ts +3 -1
  82. package/es/stringTrim.js +17 -19
  83. package/es/stringifyQuery.d.ts +1 -1
  84. package/es/stringifyQuery.js +11 -8
  85. package/es/throttle.d.ts +5 -0
  86. package/es/throttle.js +17 -0
  87. package/es/typeOf.d.ts +1 -1
  88. package/es/typeOf.js +2 -2
  89. package/lib/base64ToBlob.js +14 -23
  90. package/lib/blobToBase64.js +13 -15
  91. package/lib/canvasToBlob.js +7 -11
  92. package/lib/clone.d.ts +4 -6
  93. package/lib/clone.js +21 -13
  94. package/lib/cloneSimple.d.ts +7 -0
  95. package/lib/cloneSimple.js +13 -0
  96. package/lib/compareVersion.js +30 -46
  97. package/lib/compressImage.js +15 -19
  98. package/lib/createHexColorByHash.js +60 -60
  99. package/lib/debounce.d.ts +5 -0
  100. package/lib/debounce.js +18 -0
  101. package/lib/downloadFile.js +10 -12
  102. package/lib/each.js +14 -15
  103. package/lib/filterBankCardNo.js +7 -7
  104. package/lib/filterCRLF.js +5 -7
  105. package/lib/filterEmoji.js +16 -11
  106. package/lib/filterIdCard.js +5 -7
  107. package/lib/filterName.js +15 -17
  108. package/lib/filterPhone.js +6 -9
  109. package/lib/formatAmount.js +21 -25
  110. package/lib/formatDate.js +32 -35
  111. package/lib/getBlobByUrl.js +20 -23
  112. package/lib/getDayMillisecond.js +6 -9
  113. package/lib/getImageInfo.js +12 -14
  114. package/lib/getRandomColor.js +5 -7
  115. package/lib/getVideoInfo.js +14 -16
  116. package/lib/inBrowser.js +5 -7
  117. package/lib/index.d.ts +4 -0
  118. package/lib/index.js +84 -708
  119. package/lib/isAndroid.js +5 -7
  120. package/lib/isArray.js +5 -7
  121. package/lib/isBoolean.js +5 -7
  122. package/lib/isEmail.js +5 -7
  123. package/lib/isEmpty.js +7 -9
  124. package/lib/isEmptyObject.js +5 -7
  125. package/lib/isError.js +5 -7
  126. package/lib/isFunction.js +5 -7
  127. package/lib/isIOS.js +5 -7
  128. package/lib/isIdCard.js +5 -7
  129. package/lib/isJSONString.js +12 -13
  130. package/lib/isLan.js +32 -33
  131. package/lib/isLicenseCode.js +5 -7
  132. package/lib/isMobile.js +10 -11
  133. package/lib/isNull.js +5 -7
  134. package/lib/isNumber.js +5 -7
  135. package/lib/isObject.js +5 -7
  136. package/lib/isPhone.js +5 -7
  137. package/lib/isPromise.js +5 -7
  138. package/lib/isRegExp.js +5 -7
  139. package/lib/isString.js +5 -7
  140. package/lib/isURL.d.ts +4 -0
  141. package/lib/isURL.js +10 -0
  142. package/lib/isUndefined.js +5 -7
  143. package/lib/isWeixin.js +5 -7
  144. package/lib/isWindow.js +5 -7
  145. package/lib/loadResource.d.ts +1 -1
  146. package/lib/loadResource.js +31 -29
  147. package/lib/omit.js +10 -15
  148. package/lib/padding.js +8 -10
  149. package/lib/parseDate.js +10 -12
  150. package/lib/parseError.js +21 -24
  151. package/lib/parseObject.d.ts +2 -1
  152. package/lib/parseObject.js +12 -13
  153. package/lib/parsePath.js +10 -12
  154. package/lib/parseQuery.d.ts +1 -1
  155. package/lib/parseQuery.js +17 -31
  156. package/lib/pick.js +10 -13
  157. package/lib/replaceCrlf.js +5 -7
  158. package/lib/reserve.js +6 -8
  159. package/lib/round.js +41 -44
  160. package/lib/sleep.d.ts +4 -2
  161. package/lib/sleep.js +11 -12
  162. package/lib/storage/factory.d.ts +2 -2
  163. package/lib/storage/factory.js +47 -60
  164. package/lib/storage/index.d.ts +4 -4
  165. package/lib/storage/index.js +12 -17
  166. package/lib/stringTrim.d.ts +3 -1
  167. package/lib/stringTrim.js +20 -24
  168. package/lib/stringifyQuery.d.ts +1 -1
  169. package/lib/stringifyQuery.js +15 -14
  170. package/lib/throttle.d.ts +5 -0
  171. package/lib/throttle.js +21 -0
  172. package/lib/typeOf.d.ts +1 -1
  173. package/lib/typeOf.js +5 -7
  174. package/package.json +23 -18
@@ -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
- var _prefix$match;
9
- var _base64$split = base64.split(','),
10
- _base64$split2 = _slicedToArray(_base64$split, 2),
11
- prefix = _base64$split2[0],
12
- rest = _base64$split2[1];
13
- var type = contentType !== null && contentType !== void 0 ? contentType : (_prefix$match = prefix.match(/:(.*?);/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[1];
14
- var data = window.atob(rest);
15
- var len = data.length;
16
- var u8arr = new Uint8Array(len);
17
- while (len--) {
18
- u8arr[len] = data.charCodeAt(len);
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
+ }
@@ -2,13 +2,13 @@
2
2
  * blob 转 base64
3
3
  */
4
4
  export function blobToBase64(blob) {
5
- return new Promise(function (resolve, reject) {
6
- var fileReader = new FileReader();
7
- fileReader.onload = function (res) {
8
- var _res$target$result, _res$target;
9
- resolve((_res$target$result = (_res$target = res.target) === null || _res$target === void 0 ? void 0 : _res$target.result) !== null && _res$target$result !== void 0 ? _res$target$result : '');
10
- };
11
- fileReader.onerror = reject;
12
- fileReader.readAsDataURL(blob);
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
+ }
@@ -2,9 +2,7 @@
2
2
  * canvas 转 blob 文件
3
3
  */
4
4
  export function canvasToBlob(canvas, type, quality) {
5
- return new Promise(function (resolve, reject) {
6
- canvas.toBlob(function (data) {
7
- return data ? resolve(data) : reject(new Error('canvas toBlob is null'));
8
- }, type, quality);
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
@@ -1,7 +1,5 @@
1
1
  /**
2
- * 拷贝对象
3
- * @param target 需要转换的值
4
- *
5
- * 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略
6
- */
7
- export declare function clone<T>(target: T): T;
2
+ * 深拷贝
3
+ * @param source 需要转换的值
4
+ * */
5
+ export declare function clone<T>(source: T): T;
package/es/clone.js CHANGED
@@ -1,9 +1,19 @@
1
+ import { isArray } from './isArray';
2
+ import { isObject } from './isObject';
1
3
  /**
2
- * 拷贝对象
3
- * @param target 需要转换的值
4
- *
5
- * 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略
6
- */
7
- export function clone(target) {
8
- return JSON.parse(JSON.stringify(target));
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
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 拷贝对象
3
+ * @param source 需要转换的值
4
+ *
5
+ * 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略
6
+ */
7
+ export declare function cloneSimple<T>(source: T): T;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 拷贝对象
3
+ * @param source 需要转换的值
4
+ *
5
+ * 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略
6
+ */
7
+ export function cloneSimple(source) {
8
+ return JSON.parse(JSON.stringify(source));
9
+ }
@@ -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
- var _nv$split$map = nv.split('.').map(function (i) {
12
- return +i;
13
- }),
14
- _nv$split$map2 = _slicedToArray(_nv$split$map, 3),
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
- } else if (S === s) {
41
- result = 0;
42
- } else {
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
- } else {
49
- result = -1;
50
- }
51
- return result;
52
- }
38
+ return result;
39
+ }
@@ -3,16 +3,14 @@ import { pick } from './pick';
3
3
  * 压缩图片
4
4
  */
5
5
  export function compressImage(image) {
6
- var _pick = pick(image, ['width', 'height']),
7
- width = _pick.width,
8
- height = _pick.height;
9
- var canvas = document.createElement('canvas');
10
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
11
- var ctx = canvas.getContext('2d');
12
- canvas.width = width;
13
- canvas.height = height;
14
- ctx.fillStyle = '#fff';
15
- ctx.fillRect(0, 0, canvas.width, canvas.height);
16
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
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 var colorGenByHash = function colorGenByHash(str) {
5
- var lsL = [0.35, 0.5, 0.65];
6
- var lsS = [0.35, 0.5, 0.65];
7
- var seed = 131;
8
- var seed2 = 137;
9
- var hash = 0;
10
- // eslint-disable-next-line no-param-reassign
11
- str += 'x';
12
- var MAX_SAFE_INTEGER = parseInt((9007199254740991 / seed2).toString(), 10);
13
- for (var i = 0; i < str.length; i++) {
14
- if (hash > MAX_SAFE_INTEGER) {
15
- hash = parseInt((hash / seed2).toString(), 10);
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
- hash = hash * seed + str.charCodeAt(i);
18
- }
19
- var H;
20
- H = hash % 359;
21
- hash = parseInt((hash / 360).toString(), 10);
22
- var S = lsS[hash % lsS.length];
23
- hash = parseInt((hash / lsS.length).toString(), 10);
24
- var L = lsL[hash % lsL.length];
25
- H /= 360;
26
- var q = L < 0.5 ? L * (1 + S) : L + S - L * S;
27
- var p = 2 * L - q;
28
- var RGBArray = [H + 1 / 3, H, H - 1 / 3].map(function (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
- } else if (color < 0.5) {
41
- // eslint-disable-next-line no-param-reassign
42
- color = q;
43
- } else if (color < 2 / 3) {
44
- // eslint-disable-next-line no-param-reassign
45
- color = p + (q - p) * 6 * (2 / 3 - color);
46
- } else {
47
- // eslint-disable-next-line no-param-reassign
48
- color = p;
49
- }
50
- return Math.round(color * 255);
51
- });
52
- var hex = '#';
53
- RGBArray.forEach(function (value) {
54
- if (value < 16) {
55
- hex += 0;
56
- }
57
- hex += value.toString(16);
58
- });
59
- return hex;
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
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 防抖函数
3
+ * 事件频繁触发,只会执行最后一次
4
+ */
5
+ export declare function debounce<T extends (...args: any[]) => any>(fn: T, ms: number): (this: unknown, ...args: Parameters<T>) => void;
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
+ }
@@ -2,10 +2,10 @@
2
2
  * 通过 a 标签下载文件
3
3
  */
4
4
  export function downloadFile(data, options) {
5
- var a = document.createElement('a');
6
- a.href = typeof data === 'string' ? data : URL.createObjectURL(data);
7
- if (options !== null && options !== void 0 && options.fileName) {
8
- a.download = options.fileName;
9
- }
10
- a.click();
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
- if (Array.isArray(data)) {
3
- // eslint-disable-next-line no-plusplus
4
- for (var index = 0, length = data.length; index < length; index++) {
5
- callback.call(data[index], data[index], index);
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
- } else {
8
- Object.keys(data).forEach(function (key) {
9
- callback.call(data[key], data[key], key);
10
- });
11
- }
12
- }
8
+ else {
9
+ Object.keys(data).forEach((key) => {
10
+ callback.call(data[key], data[key], key);
11
+ });
12
+ }
13
+ }
@@ -2,5 +2,7 @@
2
2
  * 过滤银行卡号
3
3
  */
4
4
  export function filterBankCardNo(val) {
5
- return val ? "".concat(new Array(val.length - 3).join('*')).concat(val.substring(val.length - 4)).replace(/(.{4})/g, '$1 ') : '';
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
@@ -2,5 +2,5 @@
2
2
  * 替换字符串里面的回车换行符
3
3
  */
4
4
  export function filterCRLF(v) {
5
- return v.replace(/\r|\n/gi, '<br/>');
6
- }
5
+ return v.replace(/\r|\n/gi, '<br/>');
6
+ }
package/es/filterEmoji.js CHANGED
@@ -2,9 +2,16 @@
2
2
  * 过滤emoji
3
3
  */
4
4
  export function filterEmoji(val) {
5
- if (!val) {
6
- return '';
7
- }
8
- var ranges = ["\uD83C[\uDF00-\uDFFF]", "\uD83D[\uDC00-\uDE4F]", "\uD83D[\uDE80-\uDEFF]", "[\uD800-\uDBFF]", "[\uDC00-\uDFFF]", "[^ -~\xA0-\xBE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\x80-\x9F\u2000-\u201F\u2026\u2022\u20AC\r\n]"];
9
- return val.replace(new RegExp(ranges.join('|'), 'g'), '');
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
+ }
@@ -2,5 +2,5 @@
2
2
  * 身份证号码加 *
3
3
  */
4
4
  export function filterIdCard(val) {
5
- return val ? "".concat(val.substring(0, 6), "********").concat(val.substring(14)) : '';
6
- }
5
+ return val ? `${val.substring(0, 6)}********${val.substring(14)}` : '';
6
+ }
package/es/filterName.js CHANGED
@@ -2,15 +2,15 @@
2
2
  * 过滤姓名
3
3
  */
4
4
  export function filterName(val) {
5
- if (!val) {
6
- return '';
7
- }
8
- var len = val.length;
9
- if (len === 1) {
10
- return val;
11
- }
12
- if (len === 2) {
13
- return "".concat(val.substring(0, 1), "*");
14
- }
15
- return "".concat(val.substring(0, 1)).concat(new Array(len - 1).join('*')).concat(val.substr(-1));
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
- var sep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
8
- return val ? "".concat(val.substring(0, 3)).concat(sep, "****").concat(sep).concat(val.substring(7)) : '';
9
- }
6
+ export function filterPhone(val, sep = '') {
7
+ return val ? `${val.substring(0, 3)}${sep}****${sep}${val.substring(7)}` : '';
8
+ }
@@ -1,23 +1,21 @@
1
1
  /**
2
2
  * 格式化金额,默认元
3
3
  */
4
- export function formatAmount(s) {
5
- var _s;
6
- var radix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7
- var money = parseFloat((_s = s) === null || _s === void 0 ? void 0 : _s.toString());
8
- if (money) {
9
- // eslint-disable-next-line no-param-reassign
10
- s = "".concat((money / radix).toFixed(2));
11
- var l = s.split('.')[0].split('').reverse();
12
- var r = s.split('.')[1];
13
- var t = '';
14
- l.forEach(function (_, key) {
15
- t += l[key] + ((key + 1) % 3 === 0 && key + 1 !== l.length ? ',' : '');
16
- });
17
- return "".concat(t.split('').reverse().join(''), ".").concat(r);
18
- }
19
- if (+s === 0) {
20
- return '0.00';
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
- var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd hh:mm:ss';
7
- var v = val;
8
- if (isString(v)) {
9
- // fix iOS new Date() 不支持 2020-01-01 格式,需转换为 2020/01/01
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
- return fmt;
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
+ }