@daysnap/utils 0.0.6 → 0.0.8

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 (99) hide show
  1. package/es/base64ToBlob.js +0 -29
  2. package/es/blobToBase64.js +0 -3
  3. package/es/compareVersion.js +0 -1
  4. package/es/createHexColorByHash.js +0 -5
  5. package/es/downloadFile.js +0 -7
  6. package/es/filterBankCardNo.js +0 -5
  7. package/es/filterEmoji.js +0 -6
  8. package/es/filterIdCard.js +0 -2
  9. package/es/filterName.js +0 -3
  10. package/es/filterPhone.js +0 -2
  11. package/es/formatAmount.js +0 -6
  12. package/es/formatDate.js +0 -4
  13. package/es/getBlobByUrl.js +0 -4
  14. package/es/getImageInfo.js +0 -3
  15. package/es/getVideoInfo.js +0 -3
  16. package/es/isAndroid.js +0 -2
  17. package/es/isEmail.js +0 -2
  18. package/es/isIOS.js +0 -2
  19. package/es/isIdCard.js +0 -2
  20. package/es/isMobile.js +0 -2
  21. package/es/isObject.js +0 -2
  22. package/es/isPhone.js +0 -2
  23. package/es/isPromise.js +1 -4
  24. package/es/isRegExp.js +0 -4
  25. package/es/omit.js +0 -2
  26. package/es/parsePath.js +0 -3
  27. package/es/pick.js +0 -3
  28. package/es/replaceCrlf.js +0 -3
  29. package/lib/base64ToBlob.js +2 -60
  30. package/lib/blobToBase64.js +0 -4
  31. package/lib/compareVersion.js +3 -5
  32. package/lib/createHexColorByHash.js +0 -8
  33. package/lib/downloadFile.js +0 -12
  34. package/lib/filterBankCardNo.js +0 -8
  35. package/lib/filterEmoji.js +0 -10
  36. package/lib/filterIdCard.js +0 -2
  37. package/lib/filterName.js +0 -4
  38. package/lib/filterPhone.js +0 -2
  39. package/lib/formatAmount.js +0 -10
  40. package/lib/formatDate.js +0 -8
  41. package/lib/getBlobByUrl.js +0 -6
  42. package/lib/getImageInfo.js +0 -4
  43. package/lib/getVideoInfo.js +0 -4
  44. package/lib/index.js +0 -6
  45. package/lib/isAndroid.js +0 -2
  46. package/lib/isEmail.js +0 -2
  47. package/lib/isIOS.js +0 -2
  48. package/lib/isIdCard.js +0 -2
  49. package/lib/isMobile.js +0 -2
  50. package/lib/isObject.js +0 -2
  51. package/lib/isPhone.js +0 -2
  52. package/lib/isPromise.js +1 -5
  53. package/lib/isRegExp.js +0 -6
  54. package/lib/omit.js +2 -6
  55. package/lib/parsePath.js +0 -4
  56. package/lib/pick.js +0 -4
  57. package/lib/replaceCrlf.js +0 -4
  58. package/lib/storage/factory.js +2 -2
  59. package/package.json +13 -24
  60. package/dist/base64ToBlob.d.ts +0 -4
  61. package/dist/blobToBase64.d.ts +0 -4
  62. package/dist/compareVersion.d.ts +0 -7
  63. package/dist/compressImage.d.ts +0 -4
  64. package/dist/createHexColorByHash.d.ts +0 -4
  65. package/dist/downloadFile.d.ts +0 -6
  66. package/dist/filterBankCardNo.d.ts +0 -4
  67. package/dist/filterEmoji.d.ts +0 -4
  68. package/dist/filterIdCard.d.ts +0 -4
  69. package/dist/filterName.d.ts +0 -4
  70. package/dist/filterPhone.d.ts +0 -6
  71. package/dist/formatAmount.d.ts +0 -4
  72. package/dist/formatDate.d.ts +0 -4
  73. package/dist/getBlobByUrl.d.ts +0 -4
  74. package/dist/getImageInfo.d.ts +0 -4
  75. package/dist/getVideoInfo.d.ts +0 -4
  76. package/dist/index.d.ts +0 -38
  77. package/dist/index.js +0 -604
  78. package/dist/isAndroid.d.ts +0 -4
  79. package/dist/isEmail.d.ts +0 -4
  80. package/dist/isEmpty.d.ts +0 -4
  81. package/dist/isFunction.d.ts +0 -4
  82. package/dist/isIOS.d.ts +0 -4
  83. package/dist/isIdCard.d.ts +0 -4
  84. package/dist/isMobile.d.ts +0 -4
  85. package/dist/isNull.d.ts +0 -4
  86. package/dist/isObject.d.ts +0 -4
  87. package/dist/isPhone.d.ts +0 -4
  88. package/dist/isPromise.d.ts +0 -4
  89. package/dist/isRegExp.d.ts +0 -4
  90. package/dist/isString.d.ts +0 -4
  91. package/dist/isUndefined.d.ts +0 -4
  92. package/dist/omit.d.ts +0 -4
  93. package/dist/parseError.d.ts +0 -4
  94. package/dist/parsePath.d.ts +0 -4
  95. package/dist/pick.d.ts +0 -4
  96. package/dist/replaceCrlf.d.ts +0 -4
  97. package/dist/reserve.d.ts +0 -7
  98. package/dist/storage/factory.d.ts +0 -13
  99. package/dist/storage/index.d.ts +0 -26
package/dist/index.js DELETED
@@ -1,604 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.dsu = {}));
5
- })(this, (function (exports) { 'use strict';
6
-
7
- /**
8
- * base64 转 blob
9
- */
10
- function base64ToBlob(base64, contentType) {
11
- var _prefix$match;
12
- const [prefix, rest] = base64.split(',');
13
- const type = contentType ?? ((_prefix$match = prefix.match(/:(.*?);/)) === null || _prefix$match === void 0 ? void 0 : _prefix$match[1]);
14
- const data = window.atob(rest);
15
- let len = data.length;
16
- const u8arr = new Uint8Array(len);
17
- while (len--) {
18
- u8arr[len] = data.charCodeAt(len);
19
- }
20
- return new Blob([u8arr], {
21
- type
22
- });
23
- }
24
-
25
- /**
26
- * blob 转 base64
27
- */
28
- function blobToBase64(blob) {
29
- return new Promise((resolve, reject) => {
30
- const fileReader = new FileReader();
31
- fileReader.onload = res => {
32
- var _res$target;
33
- resolve(((_res$target = res.target) === null || _res$target === void 0 ? void 0 : _res$target.result) ?? '');
34
- };
35
- fileReader.onerror = reject;
36
- fileReader.readAsDataURL(blob);
37
- });
38
- }
39
-
40
- /**
41
- * 比对版本
42
- * -1 => V < v
43
- * 0 => V === v
44
- * 1 => V > v
45
- */
46
- function compareVersion(V, v) {
47
- const [H = 0, T = 0, S = 0] = V.split('.').map(i => +i); // 新
48
- const [h = 0, t = 0, s = 0] = v.split('.').map(i => +i); // 本
49
- let result = 0;
50
- if (H > h) {
51
- result = 1;
52
- } else if (H === h) {
53
- if (T > t) {
54
- result = 1;
55
- } else if (T === t) {
56
- if (S > s) {
57
- result = 1;
58
- } else if (S === s) {
59
- result = 0;
60
- } else {
61
- result = -1;
62
- }
63
- } else {
64
- result = -1;
65
- }
66
- } else {
67
- result = -1;
68
- }
69
- return result;
70
- }
71
-
72
- /**
73
- * 挑选对象里的某些属性,新对象返回
74
- */
75
- function pick(obj) {
76
- let fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
77
- const clone = {};
78
- fields.forEach(key => {
79
- clone[key] = obj[key];
80
- });
81
- return clone;
82
- }
83
-
84
- /**
85
- * 压缩图片
86
- */
87
- function compressImage(image) {
88
- const {
89
- width,
90
- height
91
- } = pick(image, ['width', 'height']);
92
- const canvas = document.createElement('canvas');
93
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
94
- const ctx = canvas.getContext('2d');
95
- canvas.width = width;
96
- canvas.height = height;
97
- ctx.fillStyle = '#fff';
98
- ctx.fillRect(0, 0, canvas.width, canvas.height);
99
- ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
100
- return canvas;
101
- }
102
-
103
- /**
104
- * 根据字符串hash值生成颜色值
105
- */
106
- const colorGenByHash = str => {
107
- const lsL = [0.35, 0.5, 0.65];
108
- const lsS = [0.35, 0.5, 0.65];
109
- const seed = 131;
110
- const seed2 = 137;
111
- let hash = 0;
112
- // eslint-disable-next-line no-param-reassign
113
- str += 'x';
114
- const MAX_SAFE_INTEGER = parseInt((9007199254740991 / seed2).toString(), 10);
115
- for (let i = 0; i < str.length; i++) {
116
- if (hash > MAX_SAFE_INTEGER) {
117
- hash = parseInt((hash / seed2).toString(), 10);
118
- }
119
- hash = hash * seed + str.charCodeAt(i);
120
- }
121
- let H;
122
- H = hash % 359;
123
- hash = parseInt((hash / 360).toString(), 10);
124
- const S = lsS[hash % lsS.length];
125
- hash = parseInt((hash / lsS.length).toString(), 10);
126
- const L = lsL[hash % lsL.length];
127
- H /= 360;
128
- const q = L < 0.5 ? L * (1 + S) : L + S - L * S;
129
- const p = 2 * L - q;
130
- const RGBArray = [H + 1 / 3, H, H - 1 / 3].map(color => {
131
- if (color < 0) {
132
- // eslint-disable-next-line no-param-reassign
133
- color++;
134
- }
135
- if (color > 1) {
136
- // eslint-disable-next-line no-param-reassign
137
- color--;
138
- }
139
- if (color < 1 / 6) {
140
- // eslint-disable-next-line no-param-reassign
141
- color = p + (q - p) * 6 * color;
142
- } else if (color < 0.5) {
143
- // eslint-disable-next-line no-param-reassign
144
- color = q;
145
- } else if (color < 2 / 3) {
146
- // eslint-disable-next-line no-param-reassign
147
- color = p + (q - p) * 6 * (2 / 3 - color);
148
- } else {
149
- // eslint-disable-next-line no-param-reassign
150
- color = p;
151
- }
152
- return Math.round(color * 255);
153
- });
154
- let hex = '#';
155
- RGBArray.forEach(value => {
156
- if (value < 16) {
157
- hex += 0;
158
- }
159
- hex += value.toString(16);
160
- });
161
- return hex;
162
- };
163
-
164
- /**
165
- * 通过 a 标签下载文件
166
- */
167
- function downloadFile(data, options) {
168
- const a = document.createElement('a');
169
- a.href = typeof data === 'string' ? data : URL.createObjectURL(data);
170
- if (options !== null && options !== void 0 && options.fileName) {
171
- a.download = options.fileName;
172
- }
173
- a.click();
174
- }
175
-
176
- /**
177
- * 过滤银行卡号
178
- */
179
- function filterBankCardNo(val) {
180
- return val ? `${new Array(val.length - 3).join('*')}${val.substring(val.length - 4)}`.replace(/(.{4})/g, '$1 ') : '';
181
- }
182
-
183
- /**
184
- * 过滤emoji
185
- */
186
- function filterEmoji(val) {
187
- if (!val) {
188
- return '';
189
- }
190
- const ranges = ['\uD83C[\uDF00-\uDFFF]', '\uD83D[\uDC00-\uDE4F]', '\ud83d[\ude80-\udeff]', '[\uD800-\uDBFF]', '[\uDC00-\uDFFF]', '[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]'];
191
- return val.replace(new RegExp(ranges.join('|'), 'g'), '');
192
- }
193
-
194
- /**
195
- * 身份证号码加 *
196
- */
197
- function filterIdCard(val) {
198
- return val ? `${val.substring(0, 6)}********${val.substring(14)}` : '';
199
- }
200
-
201
- /**
202
- * 过滤姓名
203
- */
204
- function filterName(val) {
205
- if (!val) {
206
- return '';
207
- }
208
- const len = val.length;
209
- if (len === 1) {
210
- return val;
211
- }
212
- if (len === 2) {
213
- return `${val.substring(0, 1)}*`;
214
- }
215
- return `${val.substring(0, 1)}${new Array(len - 1).join('*')}${val.substr(-1)}`;
216
- }
217
-
218
- /**
219
- * 手机号加 *
220
- * filterPhone('13177778888') => 131****8888
221
- * filterPhone('13177778888', ' ') => 131 **** 8888
222
- */
223
- function filterPhone(val) {
224
- let sep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
225
- return val ? `${val.substring(0, 3)}${sep}****${sep}${val.substring(7)}` : '';
226
- }
227
-
228
- /**
229
- * 格式化金额,默认元
230
- */
231
- function formatAmount(s) {
232
- let radix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
233
- const money = parseFloat(s);
234
- if (money) {
235
- // eslint-disable-next-line no-param-reassign
236
- s = `${(money / radix).toFixed(2)}`;
237
- const l = s.split('.')[0].split('').reverse();
238
- const r = s.split('.')[1];
239
- let t = '';
240
- l.forEach((_, key) => {
241
- t += l[key] + ((key + 1) % 3 === 0 && key + 1 !== l.length ? ',' : '');
242
- });
243
- return `${t.split('').reverse().join('')}.${r}`;
244
- }
245
- if (+s === 0) {
246
- return '0.00';
247
- }
248
- return '---';
249
- }
250
-
251
- /**
252
- * 校验是否是字符串
253
- */
254
- function isString(val) {
255
- return typeof val === 'string';
256
- }
257
-
258
- /**
259
- * 格式化日期
260
- */
261
- function formatDate(val) {
262
- let fmt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd hh:mm:ss';
263
- let v = val;
264
- if (isString(v)) {
265
- // fix iOS new Date() 不支持 2020-01-01 格式,需转换为 2020/01/01
266
- v = v.replace(/-/g, '/');
267
- }
268
- const date = new Date(v);
269
- const o = {
270
- 'M+': date.getMonth() + 1,
271
- 'd+': date.getDate(),
272
- 'h+': date.getHours(),
273
- 'm+': date.getMinutes(),
274
- 's+': date.getSeconds(),
275
- 'q+': Math.floor((date.getMonth() + 3) / 3),
276
- S: date.getMilliseconds()
277
- };
278
- if (/(y+)/.test(fmt)) {
279
- // eslint-disable-next-line no-param-reassign
280
- fmt = fmt.replace(RegExp.$1, `${date.getFullYear()}`.substr(4 - RegExp.$1.length));
281
- }
282
- // eslint-disable-next-line no-restricted-syntax
283
- for (const k in o) {
284
- if (new RegExp(`(${k})`).test(fmt)) {
285
- // eslint-disable-next-line no-param-reassign
286
- fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : `00${o[k]}`.substr(`${o[k]}`.length));
287
- }
288
- }
289
- return fmt;
290
- }
291
-
292
- /**
293
- * 根据在线 url 返回 blob
294
- */
295
- function getBlobByUrl(url) {
296
- return new Promise((resolve, reject) => {
297
- const xhr = new XMLHttpRequest();
298
- xhr.open('GET', url, true);
299
- xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
300
- xhr.responseType = 'blob';
301
- xhr.onload = () => {
302
- const {
303
- status,
304
- response,
305
- statusText
306
- } = xhr;
307
- if (status >= 200 && status < 300) {
308
- resolve(response);
309
- } else {
310
- reject(new Error(`${statusText}[${status}]`));
311
- }
312
- };
313
- });
314
- }
315
-
316
- /**
317
- * 获取图片信息
318
- */
319
- function getImageInfo(src) {
320
- return new Promise((resolve, reject) => {
321
- const image = new Image();
322
- image.onload = () => {
323
- resolve(image);
324
- };
325
- image.onerror = reject;
326
- image.src = src;
327
- });
328
- }
329
-
330
- /**
331
- * 获取 video 信息
332
- */
333
- function getVideoInfo(src) {
334
- return new Promise((resolve, reject) => {
335
- const video = document.createElement('video');
336
- video.preload = 'metadata';
337
- video.muted = true;
338
- video.onerror = reject;
339
- video.onloadedmetadata = () => {
340
- resolve(video);
341
- };
342
- video.src = src;
343
- });
344
- }
345
-
346
- /**
347
- * 校验是否是安卓
348
- */
349
- function isAndroid() {
350
- return /android/.test(navigator.userAgent.toLowerCase());
351
- }
352
-
353
- /**
354
- * 校验是否是邮箱
355
- */
356
- function isEmail(val) {
357
- return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(val);
358
- }
359
-
360
- /**
361
- * 校验是否是 null
362
- */
363
- function isNull(val) {
364
- return val === null;
365
- }
366
-
367
- /**
368
- * 校验是否是 undefined
369
- */
370
- function isUndefined(val) {
371
- return typeof val === 'undefined';
372
- }
373
-
374
- /**
375
- * 校验是否为空 ''、undefined、null
376
- */
377
- function isEmpty(val) {
378
- return val === '' || isNull(val) || isUndefined(val);
379
- }
380
-
381
- /**
382
- * 校验是否是函数
383
- */
384
- function isFunction(val) {
385
- return typeof val === 'function';
386
- }
387
-
388
- /**
389
- * 校验是否是ios
390
- */
391
- function isIOS() {
392
- return /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
393
- }
394
-
395
- /**
396
- * 校验是否是身份证
397
- */
398
- function isIdCard(val) {
399
- return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(val);
400
- }
401
-
402
- /**
403
- * 校验设备是否是手机
404
- */
405
- function isMobile() {
406
- if (typeof navigator === 'undefined' || typeof window === 'undefined') {
407
- return false;
408
- }
409
- const agent = navigator.userAgent || navigator.vendor || window.opera;
410
- return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substr(0, 4));
411
- }
412
-
413
- /**
414
- * 校验是否是对象
415
- */
416
- function isObject(val) {
417
- return Object.prototype.toString.call(val) === '[object Object]';
418
- }
419
-
420
- /**
421
- * 校验是否是手机号码
422
- */
423
- function isPhone(val) {
424
- return /^1\d{10}$/.test(val);
425
- }
426
-
427
- /**
428
- * 校验是否是 promise
429
- */
430
- function isPromise(val) {
431
- return val instanceof Promise || !!val.then || !!val.catch;
432
- }
433
-
434
- /**
435
- * 校验是否是正则表达式
436
- */
437
- function isRegExp(val) {
438
- return val instanceof RegExp;
439
- }
440
-
441
- /**
442
- * 排除对象里的某些属性,返回剩下的对象,浅拷贝
443
- */
444
- function omit(obj) {
445
- let fields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
446
- const clone = {
447
- ...obj
448
- };
449
- fields.forEach(key => {
450
- delete clone[key];
451
- });
452
- return clone;
453
- }
454
-
455
- /**
456
- * 解析格式化 error 获取对应的 message
457
- */
458
- function parseError(val) {
459
- let keys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['message', 'msg', 'errorMsg'];
460
- if (isEmpty(val)) {
461
- // null or '' or undefined
462
- return '';
463
- }
464
- if (isObject(val)) {
465
- for (let i = 0, len = keys.length; i < len; i++) {
466
- const key = keys[i];
467
- const v = val[key];
468
- if (!isUndefined(v)) {
469
- return v;
470
- }
471
- }
472
- }
473
- return JSON.stringify(val);
474
- }
475
-
476
- /**
477
- * 根据路径解析值
478
- */
479
- function parsePath(obj, path) {
480
- path.split('.').forEach(key => {
481
- // eslint-disable-next-line no-param-reassign
482
- obj = obj[key] ?? '';
483
- });
484
- return obj;
485
- }
486
-
487
- /**
488
- * 替换字符串里面的回车换行
489
- */
490
- function replaceCrlf(val, replaceVal) {
491
- return val ? val.replace(/\\r|\\n/gi, replaceVal) : '';
492
- }
493
-
494
- /**
495
- * 值为 ''、undefined、null 则取默认值
496
- * 解决:
497
- * 0 || '--' => '--'
498
- * reserve(0, '--') => 0
499
- */
500
- function reserve(val, defaultVal) {
501
- return isEmpty(val) ? defaultVal : val;
502
- }
503
-
504
- function factory(type) {
505
- const fn = window[type];
506
- // 设置
507
- const setItem = (key, val) => {
508
- fn.setItem(key, JSON.stringify(val));
509
- return val;
510
- };
511
- // 获取
512
- const getItem = function (key) {
513
- let defaultVal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
514
- const val = fn.getItem(key);
515
- // 如果为 null 取默认值
516
- if (val === null) {
517
- return defaultVal;
518
- }
519
- return JSON.parse(val);
520
- };
521
- // 删除
522
- const removeItem = key => {
523
- fn.removeItem(key);
524
- };
525
- // 更新
526
- const updateItem = (key, val) => {
527
- const prev = getItem(key);
528
- return setItem(key, {
529
- ...prev,
530
- ...val
531
- });
532
- };
533
- // 清除
534
- const clear = () => {
535
- fn.clear();
536
- };
537
- // 生成
538
- const generate = key => {
539
- return {
540
- setItem: val => setItem(key, val),
541
- getItem: defaultVal => getItem(key, defaultVal),
542
- removeItem: () => removeItem(key),
543
- updateItem: val => updateItem(key, val)
544
- };
545
- };
546
- return {
547
- setItem,
548
- getItem,
549
- removeItem,
550
- updateItem,
551
- clear,
552
- generate
553
- };
554
- }
555
-
556
- const cache = factory('sessionStorage');
557
- const local = factory('localStorage');
558
-
559
- /* 本文件自动生成 './scripts/entry.js' */
560
- const version = '0.0.3';
561
-
562
- exports.base64ToBlob = base64ToBlob;
563
- exports.blobToBase64 = blobToBase64;
564
- exports.cache = cache;
565
- exports.colorGenByHash = colorGenByHash;
566
- exports.compareVersion = compareVersion;
567
- exports.compressImage = compressImage;
568
- exports.downloadFile = downloadFile;
569
- exports.filterBankCardNo = filterBankCardNo;
570
- exports.filterEmoji = filterEmoji;
571
- exports.filterIdCard = filterIdCard;
572
- exports.filterName = filterName;
573
- exports.filterPhone = filterPhone;
574
- exports.formatAmount = formatAmount;
575
- exports.formatDate = formatDate;
576
- exports.getBlobByUrl = getBlobByUrl;
577
- exports.getImageInfo = getImageInfo;
578
- exports.getVideoInfo = getVideoInfo;
579
- exports.isAndroid = isAndroid;
580
- exports.isEmail = isEmail;
581
- exports.isEmpty = isEmpty;
582
- exports.isFunction = isFunction;
583
- exports.isIOS = isIOS;
584
- exports.isIdCard = isIdCard;
585
- exports.isMobile = isMobile;
586
- exports.isNull = isNull;
587
- exports.isObject = isObject;
588
- exports.isPhone = isPhone;
589
- exports.isPromise = isPromise;
590
- exports.isRegExp = isRegExp;
591
- exports.isString = isString;
592
- exports.isUndefined = isUndefined;
593
- exports.local = local;
594
- exports.omit = omit;
595
- exports.parseError = parseError;
596
- exports.parsePath = parsePath;
597
- exports.pick = pick;
598
- exports.replaceCrlf = replaceCrlf;
599
- exports.reserve = reserve;
600
- exports.version = version;
601
-
602
- Object.defineProperty(exports, '__esModule', { value: true });
603
-
604
- }));
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是安卓
3
- */
4
- export declare function isAndroid(): boolean;
package/dist/isEmail.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是邮箱
3
- */
4
- export declare function isEmail(val: string): boolean;
package/dist/isEmpty.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否为空 ''、undefined、null
3
- */
4
- export declare function isEmpty(val: unknown): boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是函数
3
- */
4
- export declare function isFunction(val: unknown): val is (...args: any[]) => any;
package/dist/isIOS.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是ios
3
- */
4
- export declare function isIOS(): boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是身份证
3
- */
4
- export declare function isIdCard(val: string): boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验设备是否是手机
3
- */
4
- export declare function isMobile(): boolean;
package/dist/isNull.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是 null
3
- */
4
- export declare function isNull(val: unknown): val is null;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是对象
3
- */
4
- export declare function isObject(val: unknown): val is Record<string, any>;
package/dist/isPhone.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是手机号码
3
- */
4
- export declare function isPhone(val: string): boolean;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是 promise
3
- */
4
- export declare function isPromise<T = any>(val: unknown): val is Promise<T>;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是正则表达式
3
- */
4
- export declare function isRegExp(val: unknown): val is RegExp;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是字符串
3
- */
4
- export declare function isString(val: unknown): val is string;
@@ -1,4 +0,0 @@
1
- /**
2
- * 校验是否是 undefined
3
- */
4
- export declare function isUndefined(val: unknown): val is undefined;
package/dist/omit.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 排除对象里的某些属性,返回剩下的对象,浅拷贝
3
- */
4
- export declare function omit<T extends object, K extends keyof T>(obj: T, fields?: K[]): Omit<T, K>;
@@ -1,4 +0,0 @@
1
- /**
2
- * 解析格式化 error 获取对应的 message
3
- */
4
- export declare function parseError(val: any, keys?: string[]): string;