@daysnap/utils 0.0.1

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 (199) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/dist/base64ToBlob.d.ts +4 -0
  4. package/dist/blobToBase64.d.ts +4 -0
  5. package/dist/compareVersion.d.ts +7 -0
  6. package/dist/compressImage.d.ts +4 -0
  7. package/dist/createHexColorByHash.d.ts +4 -0
  8. package/dist/downloadFile.d.ts +6 -0
  9. package/dist/filterBankCardNo.d.ts +4 -0
  10. package/dist/filterEmoji.d.ts +4 -0
  11. package/dist/filterIdCard.d.ts +4 -0
  12. package/dist/filterName.d.ts +4 -0
  13. package/dist/filterPhone.d.ts +6 -0
  14. package/dist/formatAmount.d.ts +4 -0
  15. package/dist/formatDate.d.ts +4 -0
  16. package/dist/getBlobByUrl.d.ts +4 -0
  17. package/dist/getImageInfo.d.ts +4 -0
  18. package/dist/getVideoInfo.d.ts +4 -0
  19. package/dist/index.d.ts +38 -0
  20. package/dist/index.js +604 -0
  21. package/dist/isAndroid.d.ts +4 -0
  22. package/dist/isEmail.d.ts +4 -0
  23. package/dist/isEmpty.d.ts +4 -0
  24. package/dist/isFunction.d.ts +4 -0
  25. package/dist/isIOS.d.ts +4 -0
  26. package/dist/isIdCard.d.ts +4 -0
  27. package/dist/isMobile.d.ts +4 -0
  28. package/dist/isNull.d.ts +4 -0
  29. package/dist/isObject.d.ts +4 -0
  30. package/dist/isPhone.d.ts +4 -0
  31. package/dist/isPromise.d.ts +4 -0
  32. package/dist/isRegExp.d.ts +4 -0
  33. package/dist/isString.d.ts +4 -0
  34. package/dist/isUndefined.d.ts +4 -0
  35. package/dist/omit.d.ts +4 -0
  36. package/dist/parseError.d.ts +4 -0
  37. package/dist/parsePath.d.ts +4 -0
  38. package/dist/pick.d.ts +4 -0
  39. package/dist/replaceCrlf.d.ts +4 -0
  40. package/dist/reserve.d.ts +7 -0
  41. package/dist/storage/factory.d.ts +13 -0
  42. package/dist/storage/index.d.ts +26 -0
  43. package/es/base64ToBlob.d.ts +4 -0
  44. package/es/base64ToBlob.js +55 -0
  45. package/es/blobToBase64.d.ts +4 -0
  46. package/es/blobToBase64.js +20 -0
  47. package/es/compareVersion.d.ts +7 -0
  48. package/es/compareVersion.js +58 -0
  49. package/es/compressImage.d.ts +4 -0
  50. package/es/compressImage.js +20 -0
  51. package/es/createHexColorByHash.d.ts +4 -0
  52. package/es/createHexColorByHash.js +72 -0
  53. package/es/downloadFile.d.ts +6 -0
  54. package/es/downloadFile.js +20 -0
  55. package/es/filterBankCardNo.d.ts +4 -0
  56. package/es/filterBankCardNo.js +11 -0
  57. package/es/filterEmoji.d.ts +4 -0
  58. package/es/filterEmoji.js +17 -0
  59. package/es/filterIdCard.d.ts +4 -0
  60. package/es/filterIdCard.js +8 -0
  61. package/es/filterName.d.ts +4 -0
  62. package/es/filterName.js +23 -0
  63. package/es/filterPhone.d.ts +6 -0
  64. package/es/filterPhone.js +11 -0
  65. package/es/formatAmount.d.ts +4 -0
  66. package/es/formatAmount.js +31 -0
  67. package/es/formatDate.d.ts +4 -0
  68. package/es/formatDate.js +44 -0
  69. package/es/getBlobByUrl.d.ts +4 -0
  70. package/es/getBlobByUrl.js +27 -0
  71. package/es/getImageInfo.d.ts +4 -0
  72. package/es/getImageInfo.js +18 -0
  73. package/es/getVideoInfo.d.ts +4 -0
  74. package/es/getVideoInfo.js +20 -0
  75. package/es/index.d.ts +38 -0
  76. package/es/index.js +39 -0
  77. package/es/isAndroid.d.ts +4 -0
  78. package/es/isAndroid.js +8 -0
  79. package/es/isEmail.d.ts +4 -0
  80. package/es/isEmail.js +8 -0
  81. package/es/isEmpty.d.ts +4 -0
  82. package/es/isEmpty.js +9 -0
  83. package/es/isFunction.d.ts +4 -0
  84. package/es/isFunction.js +6 -0
  85. package/es/isIOS.d.ts +4 -0
  86. package/es/isIOS.js +8 -0
  87. package/es/isIdCard.d.ts +4 -0
  88. package/es/isIdCard.js +8 -0
  89. package/es/isMobile.d.ts +4 -0
  90. package/es/isMobile.js +13 -0
  91. package/es/isNull.d.ts +4 -0
  92. package/es/isNull.js +6 -0
  93. package/es/isObject.d.ts +4 -0
  94. package/es/isObject.js +8 -0
  95. package/es/isPhone.d.ts +4 -0
  96. package/es/isPhone.js +8 -0
  97. package/es/isPromise.d.ts +4 -0
  98. package/es/isPromise.js +9 -0
  99. package/es/isRegExp.d.ts +4 -0
  100. package/es/isRegExp.js +10 -0
  101. package/es/isString.d.ts +4 -0
  102. package/es/isString.js +6 -0
  103. package/es/isUndefined.d.ts +4 -0
  104. package/es/isUndefined.js +6 -0
  105. package/es/omit.d.ts +4 -0
  106. package/es/omit.js +17 -0
  107. package/es/parseError.d.ts +4 -0
  108. package/es/parseError.js +28 -0
  109. package/es/parsePath.d.ts +4 -0
  110. package/es/parsePath.js +15 -0
  111. package/es/pick.d.ts +4 -0
  112. package/es/pick.js +14 -0
  113. package/es/replaceCrlf.d.ts +4 -0
  114. package/es/replaceCrlf.js +9 -0
  115. package/es/reserve.d.ts +7 -0
  116. package/es/reserve.js +11 -0
  117. package/es/storage/factory.d.ts +13 -0
  118. package/es/storage/factory.js +65 -0
  119. package/es/storage/index.d.ts +26 -0
  120. package/es/storage/index.js +3 -0
  121. package/lib/base64ToBlob.d.ts +4 -0
  122. package/lib/base64ToBlob.js +93 -0
  123. package/lib/blobToBase64.d.ts +4 -0
  124. package/lib/blobToBase64.js +28 -0
  125. package/lib/compareVersion.d.ts +7 -0
  126. package/lib/compareVersion.js +68 -0
  127. package/lib/compressImage.d.ts +4 -0
  128. package/lib/compressImage.js +27 -0
  129. package/lib/createHexColorByHash.d.ts +4 -0
  130. package/lib/createHexColorByHash.js +84 -0
  131. package/lib/downloadFile.d.ts +6 -0
  132. package/lib/downloadFile.js +32 -0
  133. package/lib/filterBankCardNo.d.ts +4 -0
  134. package/lib/filterBankCardNo.js +21 -0
  135. package/lib/filterEmoji.d.ts +4 -0
  136. package/lib/filterEmoji.js +28 -0
  137. package/lib/filterIdCard.d.ts +4 -0
  138. package/lib/filterIdCard.js +15 -0
  139. package/lib/filterName.d.ts +4 -0
  140. package/lib/filterName.js +31 -0
  141. package/lib/filterPhone.d.ts +6 -0
  142. package/lib/filterPhone.js +18 -0
  143. package/lib/formatAmount.d.ts +4 -0
  144. package/lib/formatAmount.js +42 -0
  145. package/lib/formatDate.d.ts +4 -0
  146. package/lib/formatDate.js +55 -0
  147. package/lib/getBlobByUrl.d.ts +4 -0
  148. package/lib/getBlobByUrl.js +36 -0
  149. package/lib/getImageInfo.d.ts +4 -0
  150. package/lib/getImageInfo.js +26 -0
  151. package/lib/getVideoInfo.d.ts +4 -0
  152. package/lib/getVideoInfo.js +28 -0
  153. package/lib/index.d.ts +38 -0
  154. package/lib/index.js +537 -0
  155. package/lib/isAndroid.d.ts +4 -0
  156. package/lib/isAndroid.js +15 -0
  157. package/lib/isEmail.d.ts +4 -0
  158. package/lib/isEmail.js +15 -0
  159. package/lib/isEmpty.d.ts +4 -0
  160. package/lib/isEmpty.js +17 -0
  161. package/lib/isFunction.d.ts +4 -0
  162. package/lib/isFunction.js +13 -0
  163. package/lib/isIOS.d.ts +4 -0
  164. package/lib/isIOS.js +15 -0
  165. package/lib/isIdCard.d.ts +4 -0
  166. package/lib/isIdCard.js +15 -0
  167. package/lib/isMobile.d.ts +4 -0
  168. package/lib/isMobile.js +20 -0
  169. package/lib/isNull.d.ts +4 -0
  170. package/lib/isNull.js +13 -0
  171. package/lib/isObject.d.ts +4 -0
  172. package/lib/isObject.js +15 -0
  173. package/lib/isPhone.d.ts +4 -0
  174. package/lib/isPhone.js +15 -0
  175. package/lib/isPromise.d.ts +4 -0
  176. package/lib/isPromise.js +17 -0
  177. package/lib/isRegExp.d.ts +4 -0
  178. package/lib/isRegExp.js +19 -0
  179. package/lib/isString.d.ts +4 -0
  180. package/lib/isString.js +13 -0
  181. package/lib/isUndefined.d.ts +4 -0
  182. package/lib/isUndefined.js +13 -0
  183. package/lib/omit.d.ts +4 -0
  184. package/lib/omit.js +26 -0
  185. package/lib/parseError.d.ts +4 -0
  186. package/lib/parseError.js +37 -0
  187. package/lib/parsePath.d.ts +4 -0
  188. package/lib/parsePath.js +23 -0
  189. package/lib/pick.d.ts +4 -0
  190. package/lib/pick.js +22 -0
  191. package/lib/replaceCrlf.d.ts +4 -0
  192. package/lib/replaceCrlf.js +17 -0
  193. package/lib/reserve.d.ts +7 -0
  194. package/lib/reserve.js +18 -0
  195. package/lib/storage/factory.d.ts +13 -0
  196. package/lib/storage/factory.js +75 -0
  197. package/lib/storage/index.d.ts +26 -0
  198. package/lib/storage/index.js +13 -0
  199. package/package.json +94 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 根据路径解析值
3
+ */
4
+ export declare function parsePath(obj: Record<string, any>, path: string): Record<string, any>;
package/dist/pick.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 挑选对象里的某些属性,新对象返回
3
+ */
4
+ export declare function pick<T extends object, K extends keyof T>(obj: T, fields?: K[]): Pick<T, K>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 替换字符串里面的回车换行
3
+ */
4
+ export declare function replaceCrlf(val: string, replaceVal: string): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 值为 ''、undefined、null 则取默认值
3
+ * 解决:
4
+ * 0 || '--' => '--'
5
+ * reserve(0, '--') => 0
6
+ */
7
+ export declare function reserve(val: any, defaultVal?: any): any;
@@ -0,0 +1,13 @@
1
+ export declare function factory(type: 'sessionStorage' | 'localStorage'): {
2
+ setItem: <T>(key: string, val: T) => T;
3
+ getItem: <T_1>(key: string, defaultVal?: Partial<T_1>) => any;
4
+ removeItem: (key: string) => void;
5
+ updateItem: <T_2>(key: string, val: Partial<T_2>) => T_2;
6
+ clear: () => void;
7
+ generate: <T_3>(key: string) => {
8
+ setItem: (val: T_3) => T_3;
9
+ getItem: (defaultVal?: Partial<T_3>) => any;
10
+ removeItem: () => void;
11
+ updateItem: (val: Partial<T_3>) => T_3;
12
+ };
13
+ };
@@ -0,0 +1,26 @@
1
+ export declare const cache: {
2
+ setItem: <T>(key: string, val: T) => T;
3
+ getItem: <T_1>(key: string, defaultVal?: Partial<T_1>) => any;
4
+ removeItem: (key: string) => void;
5
+ updateItem: <T_2>(key: string, val: Partial<T_2>) => T_2;
6
+ clear: () => void;
7
+ generate: <T_3>(key: string) => {
8
+ setItem: (val: T_3) => T_3;
9
+ getItem: (defaultVal?: Partial<T_3>) => any;
10
+ removeItem: () => void;
11
+ updateItem: (val: Partial<T_3>) => T_3;
12
+ };
13
+ };
14
+ export declare const local: {
15
+ setItem: <T>(key: string, val: T) => T;
16
+ getItem: <T_1>(key: string, defaultVal?: Partial<T_1>) => any;
17
+ removeItem: (key: string) => void;
18
+ updateItem: <T_2>(key: string, val: Partial<T_2>) => T_2;
19
+ clear: () => void;
20
+ generate: <T_3>(key: string) => {
21
+ setItem: (val: T_3) => T_3;
22
+ getItem: (defaultVal?: Partial<T_3>) => any;
23
+ removeItem: () => void;
24
+ updateItem: (val: Partial<T_3>) => T_3;
25
+ };
26
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * base64 转 blob
3
+ */
4
+ export declare function base64ToBlob(base64: string, contentType?: string): Blob;
@@ -0,0 +1,55 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import "core-js/modules/es.regexp.exec.js";
3
+ import "core-js/modules/es.string.match.js";
4
+ import "core-js/modules/es.array.iterator.js";
5
+ import "core-js/modules/es.array-buffer.slice.js";
6
+ import "core-js/modules/es.object.to-string.js";
7
+ import "core-js/modules/es.typed-array.uint8-array.js";
8
+ import "core-js/modules/es.typed-array.copy-within.js";
9
+ import "core-js/modules/es.typed-array.every.js";
10
+ import "core-js/modules/es.typed-array.fill.js";
11
+ import "core-js/modules/es.typed-array.filter.js";
12
+ import "core-js/modules/es.typed-array.find.js";
13
+ import "core-js/modules/es.typed-array.find-index.js";
14
+ import "core-js/modules/es.typed-array.for-each.js";
15
+ import "core-js/modules/es.typed-array.includes.js";
16
+ import "core-js/modules/es.typed-array.index-of.js";
17
+ import "core-js/modules/es.typed-array.iterator.js";
18
+ import "core-js/modules/es.typed-array.join.js";
19
+ import "core-js/modules/es.typed-array.last-index-of.js";
20
+ import "core-js/modules/es.typed-array.map.js";
21
+ import "core-js/modules/es.typed-array.reduce.js";
22
+ import "core-js/modules/es.typed-array.reduce-right.js";
23
+ import "core-js/modules/es.typed-array.reverse.js";
24
+ import "core-js/modules/es.typed-array.set.js";
25
+ import "core-js/modules/es.typed-array.slice.js";
26
+ import "core-js/modules/es.typed-array.some.js";
27
+ import "core-js/modules/es.typed-array.sort.js";
28
+ import "core-js/modules/es.typed-array.subarray.js";
29
+ import "core-js/modules/es.typed-array.to-locale-string.js";
30
+ import "core-js/modules/es.typed-array.to-string.js";
31
+
32
+ /**
33
+ * base64 转 blob
34
+ */
35
+ export function base64ToBlob(base64, contentType) {
36
+ var _prefix$match;
37
+
38
+ var _base64$split = base64.split(','),
39
+ _base64$split2 = _slicedToArray(_base64$split, 2),
40
+ prefix = _base64$split2[0],
41
+ rest = _base64$split2[1];
42
+
43
+ var type = contentType !== null && contentType !== void 0 ? contentType : (_prefix$match = prefix.match(/:(.*?);/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[1];
44
+ var data = window.atob(rest);
45
+ var len = data.length;
46
+ var u8arr = new Uint8Array(len);
47
+
48
+ while (len--) {
49
+ u8arr[len] = data.charCodeAt(len);
50
+ }
51
+
52
+ return new Blob([u8arr], {
53
+ type: type
54
+ });
55
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * blob 转 base64
3
+ */
4
+ export declare function blobToBase64(blob: Blob): Promise<string | ArrayBuffer>;
@@ -0,0 +1,20 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.promise.js";
3
+
4
+ /**
5
+ * blob 转 base64
6
+ */
7
+ export function blobToBase64(blob) {
8
+ return new Promise(function (resolve, reject) {
9
+ var fileReader = new FileReader();
10
+
11
+ fileReader.onload = function (res) {
12
+ var _res$target$result, _res$target;
13
+
14
+ 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 : '');
15
+ };
16
+
17
+ fileReader.onerror = reject;
18
+ fileReader.readAsDataURL(blob);
19
+ });
20
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 比对版本
3
+ * -1 => V < v
4
+ * 0 => V === v
5
+ * 1 => V > v
6
+ */
7
+ export declare function compareVersion(V: string, v: string): number;
@@ -0,0 +1,58 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import "core-js/modules/es.array.map.js";
3
+
4
+ /**
5
+ * 比对版本
6
+ * -1 => V < v
7
+ * 0 => V === v
8
+ * 1 => V > v
9
+ */
10
+ export function compareVersion(V, v) {
11
+ var _V$split$map = V.split('.').map(function (i) {
12
+ return +i;
13
+ }),
14
+ _V$split$map2 = _slicedToArray(_V$split$map, 3),
15
+ _V$split$map2$ = _V$split$map2[0],
16
+ H = _V$split$map2$ === void 0 ? 0 : _V$split$map2$,
17
+ _V$split$map2$2 = _V$split$map2[1],
18
+ T = _V$split$map2$2 === void 0 ? 0 : _V$split$map2$2,
19
+ _V$split$map2$3 = _V$split$map2[2],
20
+ S = _V$split$map2$3 === void 0 ? 0 : _V$split$map2$3; // 新
21
+
22
+
23
+ var _v$split$map = v.split('.').map(function (i) {
24
+ return +i;
25
+ }),
26
+ _v$split$map2 = _slicedToArray(_v$split$map, 3),
27
+ _v$split$map2$ = _v$split$map2[0],
28
+ h = _v$split$map2$ === void 0 ? 0 : _v$split$map2$,
29
+ _v$split$map2$2 = _v$split$map2[1],
30
+ t = _v$split$map2$2 === void 0 ? 0 : _v$split$map2$2,
31
+ _v$split$map2$3 = _v$split$map2[2],
32
+ s = _v$split$map2$3 === void 0 ? 0 : _v$split$map2$3; // 本
33
+
34
+
35
+ var result = 0;
36
+
37
+ if (H > h) {
38
+ result = 1;
39
+ } else if (H === h) {
40
+ if (T > t) {
41
+ result = 1;
42
+ } else if (T === t) {
43
+ if (S > s) {
44
+ result = 1;
45
+ } else if (S === s) {
46
+ result = 0;
47
+ } else {
48
+ result = -1;
49
+ }
50
+ } else {
51
+ result = -1;
52
+ }
53
+ } else {
54
+ result = -1;
55
+ }
56
+
57
+ return result;
58
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 压缩图片
3
+ */
4
+ export declare function compressImage(image: CanvasImageSource): HTMLCanvasElement;
@@ -0,0 +1,20 @@
1
+ import { pick } from './pick';
2
+ /**
3
+ * 压缩图片
4
+ */
5
+
6
+ export function compressImage(image) {
7
+ var _pick = pick(image, ['width', 'height']),
8
+ width = _pick.width,
9
+ height = _pick.height;
10
+
11
+ var canvas = document.createElement('canvas'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
12
+
13
+ var ctx = canvas.getContext('2d');
14
+ canvas.width = width;
15
+ canvas.height = height;
16
+ ctx.fillStyle = '#fff';
17
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
18
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
19
+ return canvas;
20
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 根据字符串hash值生成颜色值
3
+ */
4
+ export declare const colorGenByHash: (str: string) => string;
@@ -0,0 +1,72 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.regexp.to-string.js";
3
+ import "core-js/modules/es.array.map.js";
4
+ import "core-js/modules/web.dom-collections.for-each.js";
5
+
6
+ /**
7
+ * 根据字符串hash值生成颜色值
8
+ */
9
+ export var colorGenByHash = function colorGenByHash(str) {
10
+ var lsL = [0.35, 0.5, 0.65];
11
+ var lsS = [0.35, 0.5, 0.65];
12
+ var seed = 131;
13
+ var seed2 = 137;
14
+ var hash = 0; // eslint-disable-next-line no-param-reassign
15
+
16
+ str += 'x';
17
+ var MAX_SAFE_INTEGER = parseInt((9007199254740991 / seed2).toString(), 10);
18
+
19
+ for (var i = 0; i < str.length; i++) {
20
+ if (hash > MAX_SAFE_INTEGER) {
21
+ hash = parseInt((hash / seed2).toString(), 10);
22
+ }
23
+
24
+ hash = hash * seed + str.charCodeAt(i);
25
+ }
26
+
27
+ var H;
28
+ H = hash % 359;
29
+ hash = parseInt((hash / 360).toString(), 10);
30
+ var S = lsS[hash % lsS.length];
31
+ hash = parseInt((hash / lsS.length).toString(), 10);
32
+ var L = lsL[hash % lsL.length];
33
+ H /= 360;
34
+ var q = L < 0.5 ? L * (1 + S) : L + S - L * S;
35
+ var p = 2 * L - q;
36
+ var RGBArray = [H + 1 / 3, H, H - 1 / 3].map(function (color) {
37
+ if (color < 0) {
38
+ // eslint-disable-next-line no-param-reassign
39
+ color++;
40
+ }
41
+
42
+ if (color > 1) {
43
+ // eslint-disable-next-line no-param-reassign
44
+ color--;
45
+ }
46
+
47
+ if (color < 1 / 6) {
48
+ // eslint-disable-next-line no-param-reassign
49
+ color = p + (q - p) * 6 * color;
50
+ } else if (color < 0.5) {
51
+ // eslint-disable-next-line no-param-reassign
52
+ color = q;
53
+ } else if (color < 2 / 3) {
54
+ // eslint-disable-next-line no-param-reassign
55
+ color = p + (q - p) * 6 * (2 / 3 - color);
56
+ } else {
57
+ // eslint-disable-next-line no-param-reassign
58
+ color = p;
59
+ }
60
+
61
+ return Math.round(color * 255);
62
+ });
63
+ var hex = '#';
64
+ RGBArray.forEach(function (value) {
65
+ if (value < 16) {
66
+ hex += 0;
67
+ }
68
+
69
+ hex += value.toString(16);
70
+ });
71
+ return hex;
72
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 通过 a 标签下载文件
3
+ */
4
+ export declare function downloadFile(data: string | Blob | MediaSource, options?: {
5
+ fileName?: string;
6
+ }): void;
@@ -0,0 +1,20 @@
1
+ import "core-js/modules/es.array.iterator.js";
2
+ import "core-js/modules/es.object.to-string.js";
3
+ import "core-js/modules/es.string.iterator.js";
4
+ import "core-js/modules/web.dom-collections.iterator.js";
5
+ import "core-js/modules/web.url.js";
6
+ import "core-js/modules/web.url-search-params.js";
7
+
8
+ /**
9
+ * 通过 a 标签下载文件
10
+ */
11
+ export function downloadFile(data, options) {
12
+ var a = document.createElement('a');
13
+ a.href = typeof data === 'string' ? data : URL.createObjectURL(data);
14
+
15
+ if (options !== null && options !== void 0 && options.fileName) {
16
+ a.download = options.fileName;
17
+ }
18
+
19
+ a.click();
20
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 过滤银行卡号
3
+ */
4
+ export declare function filterBankCardNo(val: string): string;
@@ -0,0 +1,11 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.string.replace.js";
3
+ import "core-js/modules/es.array.concat.js";
4
+ import "core-js/modules/es.array.join.js";
5
+
6
+ /**
7
+ * 过滤银行卡号
8
+ */
9
+ export function filterBankCardNo(val) {
10
+ return val ? "".concat(new Array(val.length - 3).join('*')).concat(val.substring(val.length - 4)).replace(/(.{4})/g, '$1 ') : '';
11
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 过滤emoji
3
+ */
4
+ export declare function filterEmoji(val: string): string;
@@ -0,0 +1,17 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.string.replace.js";
3
+ import "core-js/modules/es.regexp.constructor.js";
4
+ import "core-js/modules/es.regexp.to-string.js";
5
+ import "core-js/modules/es.array.join.js";
6
+
7
+ /**
8
+ * 过滤emoji
9
+ */
10
+ export function filterEmoji(val) {
11
+ if (!val) {
12
+ return '';
13
+ }
14
+
15
+ 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]"];
16
+ return val.replace(new RegExp(ranges.join('|'), 'g'), '');
17
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 身份证号码加 *
3
+ */
4
+ export declare function filterIdCard(val: string): string;
@@ -0,0 +1,8 @@
1
+ import "core-js/modules/es.array.concat.js";
2
+
3
+ /**
4
+ * 身份证号码加 *
5
+ */
6
+ export function filterIdCard(val) {
7
+ return val ? "".concat(val.substring(0, 6), "********").concat(val.substring(14)) : '';
8
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 过滤姓名
3
+ */
4
+ export declare function filterName(val: string): string;
@@ -0,0 +1,23 @@
1
+ import "core-js/modules/es.array.concat.js";
2
+ import "core-js/modules/es.array.join.js";
3
+
4
+ /**
5
+ * 过滤姓名
6
+ */
7
+ export function filterName(val) {
8
+ if (!val) {
9
+ return '';
10
+ }
11
+
12
+ var len = val.length;
13
+
14
+ if (len === 1) {
15
+ return val;
16
+ }
17
+
18
+ if (len === 2) {
19
+ return "".concat(val.substring(0, 1), "*");
20
+ }
21
+
22
+ return "".concat(val.substring(0, 1)).concat(new Array(len - 1).join('*')).concat(val.substr(-1));
23
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 手机号加 *
3
+ * filterPhone('13177778888') => 131****8888
4
+ * filterPhone('13177778888', ' ') => 131 **** 8888
5
+ */
6
+ export declare function filterPhone(val: string, sep?: string): string;
@@ -0,0 +1,11 @@
1
+ import "core-js/modules/es.array.concat.js";
2
+
3
+ /**
4
+ * 手机号加 *
5
+ * filterPhone('13177778888') => 131****8888
6
+ * filterPhone('13177778888', ' ') => 131 **** 8888
7
+ */
8
+ export function filterPhone(val) {
9
+ var sep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
10
+ return val ? "".concat(val.substring(0, 3)).concat(sep, "****").concat(sep).concat(val.substring(7)) : '';
11
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 格式化金额,默认元
3
+ */
4
+ export declare function formatAmount(s: string, radix?: number): string;
@@ -0,0 +1,31 @@
1
+ import "core-js/modules/es.number.to-fixed.js";
2
+ import "core-js/modules/es.object.to-string.js";
3
+ import "core-js/modules/web.dom-collections.for-each.js";
4
+ import "core-js/modules/es.array.concat.js";
5
+ import "core-js/modules/es.array.join.js";
6
+
7
+ /**
8
+ * 格式化金额,默认元
9
+ */
10
+ export function formatAmount(s) {
11
+ var radix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
12
+ var money = parseFloat(s);
13
+
14
+ if (money) {
15
+ // eslint-disable-next-line no-param-reassign
16
+ s = "".concat((money / radix).toFixed(2));
17
+ var l = s.split('.')[0].split('').reverse();
18
+ var r = s.split('.')[1];
19
+ var t = '';
20
+ l.forEach(function (_, key) {
21
+ t += l[key] + ((key + 1) % 3 === 0 && key + 1 !== l.length ? ',' : '');
22
+ });
23
+ return "".concat(t.split('').reverse().join(''), ".").concat(r);
24
+ }
25
+
26
+ if (+s === 0) {
27
+ return '0.00';
28
+ }
29
+
30
+ return '---';
31
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 格式化日期
3
+ */
4
+ export declare function formatDate(val: string | Date | number, fmt?: string): string;
@@ -0,0 +1,44 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.string.replace.js";
3
+ import "core-js/modules/es.regexp.constructor.js";
4
+ import "core-js/modules/es.regexp.to-string.js";
5
+ import { isString } from './isString';
6
+ /**
7
+ * 格式化日期
8
+ */
9
+
10
+ export function formatDate(val) {
11
+ var fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd hh:mm:ss';
12
+ var v = val;
13
+
14
+ if (isString(v)) {
15
+ // fix iOS new Date() 不支持 2020-01-01 格式,需转换为 2020/01/01
16
+ v = v.replace(/-/g, '/');
17
+ }
18
+
19
+ var date = new Date(v);
20
+ var o = {
21
+ 'M+': date.getMonth() + 1,
22
+ 'd+': date.getDate(),
23
+ 'h+': date.getHours(),
24
+ 'm+': date.getMinutes(),
25
+ 's+': date.getSeconds(),
26
+ 'q+': Math.floor((date.getMonth() + 3) / 3),
27
+ S: date.getMilliseconds()
28
+ };
29
+
30
+ if (/(y+)/.test(fmt)) {
31
+ // eslint-disable-next-line no-param-reassign
32
+ fmt = fmt.replace(RegExp.$1, "".concat(date.getFullYear()).substr(4 - RegExp.$1.length));
33
+ } // eslint-disable-next-line no-restricted-syntax
34
+
35
+
36
+ for (var k in o) {
37
+ if (new RegExp("(".concat(k, ")")).test(fmt)) {
38
+ // eslint-disable-next-line no-param-reassign
39
+ fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : "00".concat(o[k]).substr("".concat(o[k]).length));
40
+ }
41
+ }
42
+
43
+ return fmt;
44
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 根据在线 url 返回 blob
3
+ */
4
+ export declare function getBlobByUrl(url: string): Promise<Blob>;
@@ -0,0 +1,27 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.promise.js";
3
+ import "core-js/modules/es.array.concat.js";
4
+
5
+ /**
6
+ * 根据在线 url 返回 blob
7
+ */
8
+ export function getBlobByUrl(url) {
9
+ return new Promise(function (resolve, reject) {
10
+ var xhr = new XMLHttpRequest();
11
+ xhr.open('GET', url, true);
12
+ xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
13
+ xhr.responseType = 'blob';
14
+
15
+ xhr.onload = function () {
16
+ var status = xhr.status,
17
+ response = xhr.response,
18
+ statusText = xhr.statusText;
19
+
20
+ if (status >= 200 && status < 300) {
21
+ resolve(response);
22
+ } else {
23
+ reject(new Error("".concat(statusText, "[").concat(status, "]")));
24
+ }
25
+ };
26
+ });
27
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 获取图片信息
3
+ */
4
+ export declare function getImageInfo(src: string): Promise<HTMLImageElement>;
@@ -0,0 +1,18 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.promise.js";
3
+
4
+ /**
5
+ * 获取图片信息
6
+ */
7
+ export function getImageInfo(src) {
8
+ return new Promise(function (resolve, reject) {
9
+ var image = new Image();
10
+
11
+ image.onload = function () {
12
+ resolve(image);
13
+ };
14
+
15
+ image.onerror = reject;
16
+ image.src = src;
17
+ });
18
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 获取 video 信息
3
+ */
4
+ export declare function getVideoInfo(src: string): Promise<HTMLVideoElement>;
@@ -0,0 +1,20 @@
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.promise.js";
3
+
4
+ /**
5
+ * 获取 video 信息
6
+ */
7
+ export function getVideoInfo(src) {
8
+ return new Promise(function (resolve, reject) {
9
+ var video = document.createElement('video');
10
+ video.preload = 'metadata';
11
+ video.muted = true;
12
+ video.onerror = reject;
13
+
14
+ video.onloadedmetadata = function () {
15
+ resolve(video);
16
+ };
17
+
18
+ video.src = src;
19
+ });
20
+ }