util-helpers 4.23.0 → 5.0.0

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 (72) hide show
  1. package/dist/util-helpers.js +159 -322
  2. package/dist/util-helpers.js.map +1 -1
  3. package/dist/util-helpers.min.js +1 -1
  4. package/dist/util-helpers.min.js.map +1 -1
  5. package/esm/VERSION.js +1 -1
  6. package/esm/compressImage.js +2 -2
  7. package/esm/formatBankCard.js +3 -5
  8. package/esm/formatMobile.js +4 -6
  9. package/esm/getImageInfo.js +14 -47
  10. package/esm/index.js +0 -8
  11. package/esm/isBusinessLicense.js +1 -2
  12. package/esm/isSocialCreditCode.js +1 -3
  13. package/esm/loadImage.js +17 -44
  14. package/esm/loadImageWithBlob.js +17 -45
  15. package/lib/VERSION.js +1 -1
  16. package/lib/compressImage.js +2 -2
  17. package/lib/formatBankCard.js +3 -5
  18. package/lib/formatMobile.js +4 -6
  19. package/lib/getImageInfo.js +14 -47
  20. package/lib/index.js +1 -9
  21. package/lib/isBusinessLicense.js +1 -2
  22. package/lib/isSocialCreditCode.js +1 -3
  23. package/lib/loadImage.js +16 -43
  24. package/lib/loadImageWithBlob.js +16 -44
  25. package/package.json +11 -11
  26. package/types/AsyncMemo.d.ts +2 -2
  27. package/types/ajax.d.ts +2 -2
  28. package/types/calculateCursorPosition.d.ts +2 -2
  29. package/types/compressImage.d.ts +3 -5
  30. package/types/dataURLToBlob.d.ts +1 -1
  31. package/types/download.d.ts +3 -3
  32. package/types/fileReader.d.ts +1 -1
  33. package/types/formatBankCard.d.ts +1 -3
  34. package/types/formatMobile.d.ts +0 -2
  35. package/types/gcd.d.ts +1 -1
  36. package/types/getImageInfo.d.ts +1 -2
  37. package/types/index.d.ts +2 -10
  38. package/types/isBankCard.d.ts +1 -1
  39. package/types/isBusinessLicense.d.ts +1 -3
  40. package/types/isChinese.d.ts +3 -3
  41. package/types/isHMCard.d.ts +1 -1
  42. package/types/isIdCard.d.ts +2 -2
  43. package/types/isPassport.d.ts +1 -1
  44. package/types/isPassword.d.ts +1 -1
  45. package/types/isSocialCreditCode.d.ts +1 -3
  46. package/types/isSwiftCode.d.ts +1 -1
  47. package/types/isTWCard.d.ts +1 -1
  48. package/types/isUrl.d.ts +1 -1
  49. package/types/isVehicle.d.ts +1 -1
  50. package/types/lcm.d.ts +1 -1
  51. package/types/loadImage.d.ts +1 -10
  52. package/types/loadImageWithBlob.d.ts +3 -5
  53. package/types/numberToChinese.d.ts +1 -1
  54. package/types/parseIdCard.d.ts +1 -1
  55. package/types/safeDate.d.ts +1 -1
  56. package/types/setDataURLPrefix.d.ts +2 -2
  57. package/types/validatePassword.d.ts +1 -1
  58. package/esm/blobToDataURL.js +0 -7
  59. package/esm/isPromiseLike.js +0 -7
  60. package/esm/normalizeString.js +0 -7
  61. package/esm/utils/Cache.js +0 -47
  62. package/esm/waitTime.js +0 -8
  63. package/lib/blobToDataURL.js +0 -9
  64. package/lib/isPromiseLike.js +0 -9
  65. package/lib/normalizeString.js +0 -9
  66. package/lib/utils/Cache.js +0 -49
  67. package/lib/waitTime.js +0 -10
  68. package/types/blobToDataURL.d.ts +0 -29
  69. package/types/isPromiseLike.d.ts +0 -19
  70. package/types/normalizeString.d.ts +0 -26
  71. package/types/utils/Cache.d.ts +0 -14
  72. package/types/waitTime.d.ts +0 -24
@@ -1,47 +0,0 @@
1
- import { __extends, __assign } from 'tslib';
2
- import Emitter from 'emitter-pro';
3
- import { forEach } from 'ut2';
4
-
5
- var Cache = (function (_super) {
6
- __extends(Cache, _super);
7
- function Cache(options) {
8
- var _this = _super.call(this) || this;
9
- _this.data = [];
10
- _this.options = __assign({ max: 10 }, options);
11
- return _this;
12
- }
13
- Cache.prototype.has = function (k) {
14
- return !!this.data.find(function (item) { return item.k === k; });
15
- };
16
- Cache.prototype.get = function (k) {
17
- var _a;
18
- return (_a = this.data.find(function (item) { return item.k === k; })) === null || _a === void 0 ? void 0 : _a.v;
19
- };
20
- Cache.prototype.checkLimit = function () {
21
- var _this = this;
22
- if (this.options.max !== 0) {
23
- var limit = this.data.length - this.options.max;
24
- if (limit >= 0) {
25
- var delArr = this.data.splice(0, limit + 1);
26
- forEach(delArr, function (item) {
27
- _this.emit('del', item.v, item.k);
28
- });
29
- }
30
- }
31
- };
32
- Cache.prototype.set = function (k, v) {
33
- var newData = { k: k, v: v };
34
- if (this.has(k)) {
35
- var index = this.data.findIndex(function (item) { return item.k === k; });
36
- this.data.splice(index, 1, newData);
37
- }
38
- else {
39
- this.checkLimit();
40
- this.data.push(newData);
41
- }
42
- };
43
- return Cache;
44
- }(Emitter));
45
- var Cache$1 = Cache;
46
-
47
- export { Cache$1 as default };
package/esm/waitTime.js DELETED
@@ -1,8 +0,0 @@
1
- import { sleep } from 'ut2';
2
-
3
- function waitTime(time) {
4
- if (time === void 0) { time = 1000; }
5
- return sleep(time);
6
- }
7
-
8
- export { waitTime as default };
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- var fileReader = require('./fileReader.js');
4
-
5
- function blobToDataURL(blob) {
6
- return fileReader(blob);
7
- }
8
-
9
- module.exports = blobToDataURL;
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- var ut2 = require('ut2');
4
-
5
- function isPromiseLike(obj) {
6
- return ut2.isPromiseLike(obj);
7
- }
8
-
9
- module.exports = isPromiseLike;
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- var ut2 = require('ut2');
4
-
5
- function normalizeString(value) {
6
- return ut2.toString(value);
7
- }
8
-
9
- module.exports = normalizeString;
@@ -1,49 +0,0 @@
1
- 'use strict';
2
-
3
- var tslib = require('tslib');
4
- var Emitter = require('emitter-pro');
5
- var ut2 = require('ut2');
6
-
7
- var Cache = (function (_super) {
8
- tslib.__extends(Cache, _super);
9
- function Cache(options) {
10
- var _this = _super.call(this) || this;
11
- _this.data = [];
12
- _this.options = tslib.__assign({ max: 10 }, options);
13
- return _this;
14
- }
15
- Cache.prototype.has = function (k) {
16
- return !!this.data.find(function (item) { return item.k === k; });
17
- };
18
- Cache.prototype.get = function (k) {
19
- var _a;
20
- return (_a = this.data.find(function (item) { return item.k === k; })) === null || _a === void 0 ? void 0 : _a.v;
21
- };
22
- Cache.prototype.checkLimit = function () {
23
- var _this = this;
24
- if (this.options.max !== 0) {
25
- var limit = this.data.length - this.options.max;
26
- if (limit >= 0) {
27
- var delArr = this.data.splice(0, limit + 1);
28
- ut2.forEach(delArr, function (item) {
29
- _this.emit('del', item.v, item.k);
30
- });
31
- }
32
- }
33
- };
34
- Cache.prototype.set = function (k, v) {
35
- var newData = { k: k, v: v };
36
- if (this.has(k)) {
37
- var index = this.data.findIndex(function (item) { return item.k === k; });
38
- this.data.splice(index, 1, newData);
39
- }
40
- else {
41
- this.checkLimit();
42
- this.data.push(newData);
43
- }
44
- };
45
- return Cache;
46
- }(Emitter));
47
- var Cache$1 = Cache;
48
-
49
- module.exports = Cache$1;
package/lib/waitTime.js DELETED
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- var ut2 = require('ut2');
4
-
5
- function waitTime(time) {
6
- if (time === void 0) { time = 1000; }
7
- return ut2.sleep(time);
8
- }
9
-
10
- module.exports = waitTime;
@@ -1,29 +0,0 @@
1
- /**
2
- * 将 Blob 或 File 对象转成 data:URL 格式的 Base64 字符串
3
- *
4
- * <em style="font-weight: bold;">注意:该方法仅适用于浏览器端。</em>
5
- *
6
- * @ignore
7
- * @static
8
- * @alias module:Processor.blobToDataURL
9
- * @since 4.1.0
10
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL | FileReader.readAsDataURL()}
11
- * @deprecated 请使用 `fileReader` 方法
12
- * @param {Blob} blob Blob 或 File 对象
13
- * @returns {Promise<string>} data:URL 格式的 Base64 字符串。
14
- * @example
15
- * const aFileParts = ['<a id="a"><b id="b">hey!</b></a>']; // 一个包含DOMString的数组
16
- * const htmlBlob = new Blob(aFileParts, { type: 'text/html' }); // 得到 blob
17
- *
18
- * blobToDataURL(htmlBlob).then(data=>{
19
- * console.log(data); // data:text/html;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
20
- * });
21
- *
22
- * const textBlob = new Blob(aFileParts, { type: 'text/plain' });
23
- *
24
- * blobToDataURL(textBlob).then(data=>{
25
- * console.log(data); // data:text/plain;base64,PGEgaWQ9ImEiPjxiIGlkPSJiIj5oZXkhPC9iPjwvYT4=
26
- * });
27
- */
28
- declare function blobToDataURL(blob: Blob): Promise<string>;
29
- export default blobToDataURL;
@@ -1,19 +0,0 @@
1
- /**
2
- * 检测值是否类似Promise对象
3
- *
4
- * @ignore
5
- * @static
6
- * @alias module:Validator.isPromiseLike
7
- * @since 3.8.0
8
- * @deprecated 即将废弃,请使用 `import { isPromiseLike } 'ut2'`
9
- * @param {*} obj 要检测的值
10
- * @returns {boolean} 是否类似Promise对象
11
- * @example
12
- *
13
- * isPromiseLike([]); // false
14
- * isPromiseLike({ then: () => { } }); // true
15
- * isPromiseLike(Promise.resolve()); // true
16
- *
17
- */
18
- declare function isPromiseLike(obj: any): boolean;
19
- export default isPromiseLike;
@@ -1,26 +0,0 @@
1
- /**
2
- * 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
3
- *
4
- * @ignore
5
- * @static
6
- * @alias module:Processor.normalizeString
7
- * @since 4.3.0
8
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances | String}
9
- * @deprecated 即将废弃,请使用 `import { toString } 'ut2'`
10
- * @param {*} value 待处理的值
11
- * @returns {string} 规整化的值
12
- * @example
13
- *
14
- * normalizeString(); // ''
15
- * normalizeString(undefined); // ''
16
- * normalizeString(void 0); // ''
17
- * normalizeString(null); // ''
18
- *
19
- * normalizeString(true); // 'true'
20
- * normalizeString(NaN); // 'NaN'
21
- * normalizeString(1); // '1'
22
- * normalizeString('a'); // 'a'
23
- *
24
- */
25
- declare function normalizeString(value: any): string;
26
- export default normalizeString;
@@ -1,14 +0,0 @@
1
- import Emitter from 'emitter-pro';
2
- type Options = {
3
- max: number;
4
- };
5
- declare class Cache<V = any, K = any> extends Emitter<(v: V, k: K) => void> {
6
- private data;
7
- private options;
8
- constructor(options?: Options);
9
- has(k: K): boolean;
10
- get(k: K): V | undefined;
11
- private checkLimit;
12
- set(k: K, v: V): void;
13
- }
14
- export default Cache;
@@ -1,24 +0,0 @@
1
- /**
2
- * 等待时间返回 Promise 。常用于异步方法中延时。
3
- *
4
- * @ignore
5
- * @static
6
- * @alias module:Other.waitTime
7
- * @since 4.2.0
8
- * @deprecated 即将废弃,请使用 `import { sleep } from 'ut2'`
9
- * @param {number} [time=1000] 延时时间,单位毫秒
10
- * @returns {Promise<void>}
11
- * @example
12
- *
13
- * const test = async ()=>{
14
- * await waitTime();
15
- * // do something
16
- * }
17
- *
18
- * waitTime(500).then(()=>{
19
- * // do something
20
- * });
21
- *
22
- */
23
- declare function waitTime(time?: number): Promise<void>;
24
- export default waitTime;