@daysnap/utils 0.0.40 → 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.
Files changed (174) hide show
  1. package/README.md +21 -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 -19
  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 -24
  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 +15 -17
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.canvasToBlob = canvasToBlob;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.canvasToBlob = void 0;
7
4
  /**
8
5
  * canvas 转 blob 文件
9
6
  */
10
7
  function canvasToBlob(canvas, type, quality) {
11
- return new Promise(function (resolve, reject) {
12
- canvas.toBlob(function (data) {
13
- return data ? resolve(data) : reject(new Error('canvas toBlob is null'));
14
- }, type, quality);
15
- });
16
- }
8
+ return new Promise((resolve, reject) => {
9
+ canvas.toBlob((data) => data ? resolve(data) : reject(new Error('canvas toBlob is null')), type, quality);
10
+ });
11
+ }
12
+ exports.canvasToBlob = canvasToBlob;
package/lib/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/lib/clone.js CHANGED
@@ -1,15 +1,23 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.clone = clone;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clone = void 0;
4
+ const isArray_1 = require("./isArray");
5
+ const isObject_1 = require("./isObject");
7
6
  /**
8
- * 拷贝对象
9
- * @param target 需要转换的值
10
- *
11
- * 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略
12
- */
13
- function clone(target) {
14
- return JSON.parse(JSON.stringify(target));
15
- }
7
+ * 深拷贝
8
+ * @param source 需要转换的值
9
+ * */
10
+ function clone(source) {
11
+ if (!(0, isArray_1.isArray)(source) && !(0, isObject_1.isObject)(source)) {
12
+ return source;
13
+ }
14
+ const target = ((0, isArray_1.isArray)(source) ? [] : {});
15
+ // eslint-disable-next-line no-restricted-syntax
16
+ for (const key in source) {
17
+ if (source.hasOwnProperty(key)) {
18
+ target[key] = clone(source[key]);
19
+ }
20
+ }
21
+ return target;
22
+ }
23
+ exports.clone = clone;
@@ -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,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cloneSimple = void 0;
4
+ /**
5
+ * 拷贝对象
6
+ * @param source 需要转换的值
7
+ *
8
+ * 需要注意 当值为 undefined、function、symbol 会在转换过程中被忽略
9
+ */
10
+ function cloneSimple(source) {
11
+ return JSON.parse(JSON.stringify(source));
12
+ }
13
+ exports.cloneSimple = cloneSimple;
@@ -1,11 +1,6 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.compareVersion = compareVersion;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compareVersion = void 0;
9
4
  /**
10
5
  * 比对版本
11
6
  * -1 => nv < v
@@ -15,45 +10,34 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
15
10
  * @param v 版本
16
11
  */
17
12
  function compareVersion(nv, v) {
18
- var _nv$split$map = nv.split('.').map(function (i) {
19
- return +i;
20
- }),
21
- _nv$split$map2 = (0, _slicedToArray2["default"])(_nv$split$map, 3),
22
- _nv$split$map2$ = _nv$split$map2[0],
23
- H = _nv$split$map2$ === void 0 ? 0 : _nv$split$map2$,
24
- _nv$split$map2$2 = _nv$split$map2[1],
25
- T = _nv$split$map2$2 === void 0 ? 0 : _nv$split$map2$2,
26
- _nv$split$map2$3 = _nv$split$map2[2],
27
- S = _nv$split$map2$3 === void 0 ? 0 : _nv$split$map2$3; // 新
28
- var _v$split$map = v.split('.').map(function (i) {
29
- return +i;
30
- }),
31
- _v$split$map2 = (0, _slicedToArray2["default"])(_v$split$map, 3),
32
- _v$split$map2$ = _v$split$map2[0],
33
- h = _v$split$map2$ === void 0 ? 0 : _v$split$map2$,
34
- _v$split$map2$2 = _v$split$map2[1],
35
- t = _v$split$map2$2 === void 0 ? 0 : _v$split$map2$2,
36
- _v$split$map2$3 = _v$split$map2[2],
37
- s = _v$split$map2$3 === void 0 ? 0 : _v$split$map2$3; // 本
38
- var result = 0;
39
- if (H > h) {
40
- result = 1;
41
- } else if (H === h) {
42
- if (T > t) {
43
- result = 1;
44
- } else if (T === t) {
45
- if (S > s) {
13
+ const [H = 0, T = 0, S = 0] = nv.split('.').map((i) => +i); // 新
14
+ const [h = 0, t = 0, s = 0] = v.split('.').map((i) => +i); // 本
15
+ let result = 0;
16
+ if (H > h) {
46
17
  result = 1;
47
- } else if (S === s) {
48
- result = 0;
49
- } else {
18
+ }
19
+ else if (H === h) {
20
+ if (T > t) {
21
+ result = 1;
22
+ }
23
+ else if (T === t) {
24
+ if (S > s) {
25
+ result = 1;
26
+ }
27
+ else if (S === s) {
28
+ result = 0;
29
+ }
30
+ else {
31
+ result = -1;
32
+ }
33
+ }
34
+ else {
35
+ result = -1;
36
+ }
37
+ }
38
+ else {
50
39
  result = -1;
51
- }
52
- } else {
53
- result = -1;
54
40
  }
55
- } else {
56
- result = -1;
57
- }
58
- return result;
59
- }
41
+ return result;
42
+ }
43
+ exports.compareVersion = compareVersion;
@@ -1,24 +1,20 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.compressImage = compressImage;
7
- var _pick2 = require("./pick");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compressImage = void 0;
4
+ const pick_1 = require("./pick");
8
5
  /**
9
6
  * 压缩图片
10
7
  */
11
8
  function compressImage(image) {
12
- var _pick = (0, _pick2.pick)(image, ['width', 'height']),
13
- width = _pick.width,
14
- height = _pick.height;
15
- var canvas = document.createElement('canvas');
16
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17
- var ctx = canvas.getContext('2d');
18
- canvas.width = width;
19
- canvas.height = height;
20
- ctx.fillStyle = '#fff';
21
- ctx.fillRect(0, 0, canvas.width, canvas.height);
22
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
23
- return canvas;
24
- }
9
+ const { width, height } = (0, pick_1.pick)(image, ['width', 'height']);
10
+ const canvas = document.createElement('canvas');
11
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12
+ const ctx = canvas.getContext('2d');
13
+ canvas.width = width;
14
+ canvas.height = height;
15
+ ctx.fillStyle = '#fff';
16
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
17
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
18
+ return canvas;
19
+ }
20
+ exports.compressImage = compressImage;
@@ -1,67 +1,67 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.colorGenByHash = void 0;
7
4
  /**
8
5
  * 根据字符串hash值生成颜色值
9
6
  */
10
- var colorGenByHash = function colorGenByHash(str) {
11
- var lsL = [0.35, 0.5, 0.65];
12
- var lsS = [0.35, 0.5, 0.65];
13
- var seed = 131;
14
- var seed2 = 137;
15
- var hash = 0;
16
- // eslint-disable-next-line no-param-reassign
17
- str += 'x';
18
- var MAX_SAFE_INTEGER = parseInt((9007199254740991 / seed2).toString(), 10);
19
- for (var i = 0; i < str.length; i++) {
20
- if (hash > MAX_SAFE_INTEGER) {
21
- hash = parseInt((hash / seed2).toString(), 10);
7
+ const colorGenByHash = (str) => {
8
+ const lsL = [0.35, 0.5, 0.65];
9
+ const lsS = [0.35, 0.5, 0.65];
10
+ const seed = 131;
11
+ const seed2 = 137;
12
+ let hash = 0;
13
+ // eslint-disable-next-line no-param-reassign
14
+ str += 'x';
15
+ const MAX_SAFE_INTEGER = parseInt((9007199254740991 / seed2).toString(), 10);
16
+ for (let i = 0; i < str.length; i++) {
17
+ if (hash > MAX_SAFE_INTEGER) {
18
+ hash = parseInt((hash / seed2).toString(), 10);
19
+ }
20
+ hash = hash * seed + str.charCodeAt(i);
22
21
  }
23
- hash = hash * seed + str.charCodeAt(i);
24
- }
25
- var H;
26
- H = hash % 359;
27
- hash = parseInt((hash / 360).toString(), 10);
28
- var S = lsS[hash % lsS.length];
29
- hash = parseInt((hash / lsS.length).toString(), 10);
30
- var L = lsL[hash % lsL.length];
31
- H /= 360;
32
- var q = L < 0.5 ? L * (1 + S) : L + S - L * S;
33
- var p = 2 * L - q;
34
- var RGBArray = [H + 1 / 3, H, H - 1 / 3].map(function (color) {
35
- if (color < 0) {
36
- // eslint-disable-next-line no-param-reassign
37
- color++;
38
- }
39
- if (color > 1) {
40
- // eslint-disable-next-line no-param-reassign
41
- color--;
42
- }
43
- if (color < 1 / 6) {
44
- // eslint-disable-next-line no-param-reassign
45
- color = p + (q - p) * 6 * color;
46
- } else if (color < 0.5) {
47
- // eslint-disable-next-line no-param-reassign
48
- color = q;
49
- } else if (color < 2 / 3) {
50
- // eslint-disable-next-line no-param-reassign
51
- color = p + (q - p) * 6 * (2 / 3 - color);
52
- } else {
53
- // eslint-disable-next-line no-param-reassign
54
- color = p;
55
- }
56
- return Math.round(color * 255);
57
- });
58
- var hex = '#';
59
- RGBArray.forEach(function (value) {
60
- if (value < 16) {
61
- hex += 0;
62
- }
63
- hex += value.toString(16);
64
- });
65
- return hex;
22
+ let H;
23
+ H = hash % 359;
24
+ hash = parseInt((hash / 360).toString(), 10);
25
+ const S = lsS[hash % lsS.length];
26
+ hash = parseInt((hash / lsS.length).toString(), 10);
27
+ const L = lsL[hash % lsL.length];
28
+ H /= 360;
29
+ const q = L < 0.5 ? L * (1 + S) : L + S - L * S;
30
+ const p = 2 * L - q;
31
+ const RGBArray = [H + 1 / 3, H, H - 1 / 3].map((color) => {
32
+ if (color < 0) {
33
+ // eslint-disable-next-line no-param-reassign
34
+ color++;
35
+ }
36
+ if (color > 1) {
37
+ // eslint-disable-next-line no-param-reassign
38
+ color--;
39
+ }
40
+ if (color < 1 / 6) {
41
+ // eslint-disable-next-line no-param-reassign
42
+ color = p + (q - p) * 6 * color;
43
+ }
44
+ else if (color < 0.5) {
45
+ // eslint-disable-next-line no-param-reassign
46
+ color = q;
47
+ }
48
+ else if (color < 2 / 3) {
49
+ // eslint-disable-next-line no-param-reassign
50
+ color = p + (q - p) * 6 * (2 / 3 - color);
51
+ }
52
+ else {
53
+ // eslint-disable-next-line no-param-reassign
54
+ color = p;
55
+ }
56
+ return Math.round(color * 255);
57
+ });
58
+ let hex = '#';
59
+ RGBArray.forEach((value) => {
60
+ if (value < 16) {
61
+ hex += 0;
62
+ }
63
+ hex += value.toString(16);
64
+ });
65
+ return hex;
66
66
  };
67
- exports.colorGenByHash = colorGenByHash;
67
+ exports.colorGenByHash = colorGenByHash;
@@ -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;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.debounce = void 0;
4
+ /**
5
+ * 防抖函数
6
+ * 事件频繁触发,只会执行最后一次
7
+ */
8
+ function debounce(fn, ms) {
9
+ let timer = null;
10
+ // eslint-disable-next-line func-names
11
+ return function (...args) {
12
+ clearTimeout(timer);
13
+ timer = setTimeout(() => {
14
+ fn.apply(this, args);
15
+ }, ms);
16
+ };
17
+ }
18
+ exports.debounce = debounce;
@@ -1,17 +1,15 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.downloadFile = downloadFile;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadFile = void 0;
7
4
  /**
8
5
  * 通过 a 标签下载文件
9
6
  */
10
7
  function downloadFile(data, options) {
11
- var a = document.createElement('a');
12
- a.href = typeof data === 'string' ? data : URL.createObjectURL(data);
13
- if (options !== null && options !== void 0 && options.fileName) {
14
- a.download = options.fileName;
15
- }
16
- a.click();
17
- }
8
+ const a = document.createElement('a');
9
+ a.href = typeof data === 'string' ? data : URL.createObjectURL(data);
10
+ if (options === null || options === void 0 ? void 0 : options.fileName) {
11
+ a.download = options.fileName;
12
+ }
13
+ a.click();
14
+ }
15
+ exports.downloadFile = downloadFile;
package/lib/each.js CHANGED
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.each = each;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.each = void 0;
7
4
  function each(data, callback) {
8
- if (Array.isArray(data)) {
9
- // eslint-disable-next-line no-plusplus
10
- for (var index = 0, length = data.length; index < length; index++) {
11
- callback.call(data[index], data[index], index);
5
+ if (Array.isArray(data)) {
6
+ // eslint-disable-next-line no-plusplus
7
+ for (let index = 0, { length } = data; index < length; index++) {
8
+ callback.call(data[index], data[index], index);
9
+ }
10
+ }
11
+ else {
12
+ Object.keys(data).forEach((key) => {
13
+ callback.call(data[key], data[key], key);
14
+ });
12
15
  }
13
- } else {
14
- Object.keys(data).forEach(function (key) {
15
- callback.call(data[key], data[key], key);
16
- });
17
- }
18
- }
16
+ }
17
+ exports.each = each;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.filterBankCardNo = filterBankCardNo;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterBankCardNo = void 0;
7
4
  /**
8
5
  * 过滤银行卡号
9
6
  */
10
7
  function filterBankCardNo(val) {
11
- return val ? "".concat(new Array(val.length - 3).join('*')).concat(val.substring(val.length - 4)).replace(/(.{4})/g, '$1 ') : '';
12
- }
8
+ return val
9
+ ? `${new Array(val.length - 3).join('*')}${val.substring(val.length - 4)}`.replace(/(.{4})/g, '$1 ')
10
+ : '';
11
+ }
12
+ exports.filterBankCardNo = filterBankCardNo;
package/lib/filterCRLF.js CHANGED
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.filterCRLF = filterCRLF;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterCRLF = void 0;
7
4
  /**
8
5
  * 替换字符串里面的回车换行符
9
6
  */
10
7
  function filterCRLF(v) {
11
- return v.replace(/\r|\n/gi, '<br/>');
12
- }
8
+ return v.replace(/\r|\n/gi, '<br/>');
9
+ }
10
+ exports.filterCRLF = filterCRLF;
@@ -1,16 +1,21 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.filterEmoji = filterEmoji;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterEmoji = void 0;
7
4
  /**
8
5
  * 过滤emoji
9
6
  */
10
7
  function filterEmoji(val) {
11
- if (!val) {
12
- return '';
13
- }
14
- 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]"];
15
- return val.replace(new RegExp(ranges.join('|'), 'g'), '');
16
- }
8
+ if (!val) {
9
+ return '';
10
+ }
11
+ const ranges = [
12
+ '\uD83C[\uDF00-\uDFFF]',
13
+ '\uD83D[\uDC00-\uDE4F]',
14
+ '\ud83d[\ude80-\udeff]',
15
+ '[\uD800-\uDBFF]',
16
+ '[\uDC00-\uDFFF]',
17
+ '[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]',
18
+ ];
19
+ return val.replace(new RegExp(ranges.join('|'), 'g'), '');
20
+ }
21
+ exports.filterEmoji = filterEmoji;
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.filterIdCard = filterIdCard;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterIdCard = void 0;
7
4
  /**
8
5
  * 身份证号码加 *
9
6
  */
10
7
  function filterIdCard(val) {
11
- return val ? "".concat(val.substring(0, 6), "********").concat(val.substring(14)) : '';
12
- }
8
+ return val ? `${val.substring(0, 6)}********${val.substring(14)}` : '';
9
+ }
10
+ exports.filterIdCard = filterIdCard;
package/lib/filterName.js CHANGED
@@ -1,22 +1,20 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.filterName = filterName;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterName = void 0;
7
4
  /**
8
5
  * 过滤姓名
9
6
  */
10
7
  function filterName(val) {
11
- if (!val) {
12
- return '';
13
- }
14
- var len = val.length;
15
- if (len === 1) {
16
- return val;
17
- }
18
- if (len === 2) {
19
- return "".concat(val.substring(0, 1), "*");
20
- }
21
- return "".concat(val.substring(0, 1)).concat(new Array(len - 1).join('*')).concat(val.substr(-1));
22
- }
8
+ if (!val) {
9
+ return '';
10
+ }
11
+ const len = val.length;
12
+ if (len === 1) {
13
+ return val;
14
+ }
15
+ if (len === 2) {
16
+ return `${val.substring(0, 1)}*`;
17
+ }
18
+ return `${val.substring(0, 1)}${new Array(len - 1).join('*')}${val.substr(-1)}`;
19
+ }
20
+ exports.filterName = filterName;
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.filterPhone = filterPhone;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.filterPhone = void 0;
7
4
  /**
8
5
  * 手机号加 *
9
6
  * filterPhone('13177778888') => 131****8888
10
7
  * filterPhone('13177778888', ' ') => 131 **** 8888
11
8
  */
12
- function filterPhone(val) {
13
- var sep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
14
- return val ? "".concat(val.substring(0, 3)).concat(sep, "****").concat(sep).concat(val.substring(7)) : '';
15
- }
9
+ function filterPhone(val, sep = '') {
10
+ return val ? `${val.substring(0, 3)}${sep}****${sep}${val.substring(7)}` : '';
11
+ }
12
+ exports.filterPhone = filterPhone;
@@ -1,28 +1,25 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.formatAmount = formatAmount;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatAmount = void 0;
7
4
  /**
8
5
  * 格式化金额,默认元
9
6
  */
10
- function formatAmount(s) {
11
- var radix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
12
- var money = parseFloat(s.toString());
13
- if (money) {
14
- // eslint-disable-next-line no-param-reassign
15
- s = "".concat((money / radix).toFixed(2));
16
- var l = s.split('.')[0].split('').reverse();
17
- var r = s.split('.')[1];
18
- var t = '';
19
- l.forEach(function (_, key) {
20
- t += l[key] + ((key + 1) % 3 === 0 && key + 1 !== l.length ? ',' : '');
21
- });
22
- return "".concat(t.split('').reverse().join(''), ".").concat(r);
23
- }
24
- if (+s === 0) {
25
- return '0.00';
26
- }
27
- return '---';
28
- }
7
+ function formatAmount(s, radix = 1) {
8
+ const money = parseFloat(s === null || s === void 0 ? void 0 : s.toString());
9
+ if (money) {
10
+ // eslint-disable-next-line no-param-reassign
11
+ s = `${(money / radix).toFixed(2)}`;
12
+ const l = s.split('.')[0].split('').reverse();
13
+ const r = s.split('.')[1];
14
+ let t = '';
15
+ l.forEach((_, key) => {
16
+ t += l[key] + ((key + 1) % 3 === 0 && key + 1 !== l.length ? ',' : '');
17
+ });
18
+ return `${t.split('').reverse().join('')}.${r}`;
19
+ }
20
+ if (+s === 0) {
21
+ return '0.00';
22
+ }
23
+ return '---';
24
+ }
25
+ exports.formatAmount = formatAmount;