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
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "4.23.0";
1
+ var VERSION = "5.0.0";
2
2
  var VERSION$1 = VERSION;
3
3
 
4
4
  export { VERSION$1 as default };
@@ -12,8 +12,8 @@ function canvasToBlob(canvas, type, quality) {
12
12
  var compressImage = function (img, options) {
13
13
  if (options === void 0) { options = {}; }
14
14
  return new Promise(function (resolve, reject) {
15
- var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
16
- loadImageWithBlob(img, cacheImage, ajaxOptions)
15
+ var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.background, background = _b === void 0 ? '#fff' : _b, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _c = options.format, format = _c === void 0 ? 'blob' : _c, _d = options.type, type = _d === void 0 ? 'image/jpeg' : _d, _e = options.quality, quality = _e === void 0 ? 0.8 : _e, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
16
+ loadImageWithBlob(img, ajaxOptions)
17
17
  .then(function (_a) {
18
18
  var image = _a.image, blob = _a.blob;
19
19
  var numWidth = toNumber(width);
@@ -2,13 +2,11 @@ import { toString } from 'ut2';
2
2
 
3
3
  function formatBankCard(bankCardNo, options) {
4
4
  if (bankCardNo === void 0) { bankCardNo = ''; }
5
- if (options === void 0) { options = {}; }
6
- var _a = options.char, char = _a === void 0 ? ' ' : _a, _b = options.length, length = _b === void 0 ? 4 : _b;
7
- var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
5
+ var _a = options || {}, _b = _a.spaceMark, spaceMark = _b === void 0 ? ' ' : _b, _c = _a.length, length = _c === void 0 ? 4 : _c;
8
6
  var reg = new RegExp("(.{".concat(length, "})"), 'g');
9
- var regChar = new RegExp("".concat(realSpaceMark), 'g');
7
+ var regChar = new RegExp("".concat(spaceMark), 'g');
10
8
  var realValue = toString(bankCardNo).replace(regChar, '');
11
- var str = realValue.replace(reg, "$1".concat(realSpaceMark));
9
+ var str = realValue.replace(reg, "$1".concat(spaceMark));
12
10
  return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
13
11
  }
14
12
 
@@ -2,16 +2,14 @@ import { toString } from 'ut2';
2
2
 
3
3
  function formatMobile(mobileNo, options) {
4
4
  if (mobileNo === void 0) { mobileNo = ''; }
5
- if (options === void 0) { options = {}; }
6
- var _a = options.char, char = _a === void 0 ? ' ' : _a;
7
- var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
8
- var regChar = new RegExp(realSpaceMark, 'g');
5
+ var _a = (options || {}).spaceMark, spaceMark = _a === void 0 ? ' ' : _a;
6
+ var regChar = new RegExp(spaceMark, 'g');
9
7
  var realValue = toString(mobileNo).replace(regChar, '').substring(0, 11);
10
8
  if (realValue.length > 7) {
11
- return realValue.replace(/^(...)(....)/g, "$1".concat(realSpaceMark, "$2").concat(realSpaceMark));
9
+ return realValue.replace(/^(...)(....)/g, "$1".concat(spaceMark, "$2").concat(spaceMark));
12
10
  }
13
11
  if (realValue.length > 3) {
14
- return realValue.replace(/^(...)/g, "$1".concat(realSpaceMark));
12
+ return realValue.replace(/^(...)/g, "$1".concat(spaceMark));
15
13
  }
16
14
  return realValue;
17
15
  }
@@ -3,58 +3,25 @@ import divide from './divide.js';
3
3
  import gcd from './gcd.js';
4
4
  import loadImageWithBlob from './loadImageWithBlob.js';
5
5
  import bytesToSize from './bytesToSize.js';
6
- import Cache from './utils/Cache.js';
7
- import { revokeObjectURL } from './utils/native.js';
8
6
 
9
- var cache = new Cache({ max: 1 });
10
- cache.on('del', function (v) {
11
- if (v.r) {
12
- try {
13
- revokeObjectURL(v.data.image.src);
14
- }
15
- catch (_a) {
16
- }
17
- }
18
- });
19
7
  function calcContrast(w, h) {
20
8
  var n = gcd(w, h);
21
9
  return "".concat(divide(round(w), n), ":").concat(divide(round(h), n));
22
10
  }
23
- function getImageInfo(img, cacheOptions, ajaxOptions) {
24
- if (cacheOptions === void 0) { cacheOptions = true; }
25
- var _cacheOptions = {
26
- useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
27
- autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
28
- };
29
- return new Promise(function (resolve, reject) {
30
- if (_cacheOptions.useCache && cache.has(img)) {
31
- resolve(cache.get(img).data);
32
- }
33
- else {
34
- loadImageWithBlob(img, false, ajaxOptions)
35
- .then(function (_a) {
36
- var image = _a.image, blob = _a.blob;
37
- var width = image.width, height = image.height;
38
- var result = {
39
- width: width,
40
- height: height,
41
- contrast: calcContrast(width, height),
42
- measure: "".concat(width, " \u00D7 ").concat(height, " px"),
43
- size: bytesToSize(blob.size),
44
- bytes: blob.size,
45
- image: image,
46
- blob: blob
47
- };
48
- if (_cacheOptions.useCache) {
49
- cache.set(img, {
50
- data: result,
51
- r: _cacheOptions.autoRevokeOnDel
52
- });
53
- }
54
- resolve(result);
55
- })
56
- .catch(reject);
57
- }
11
+ function getImageInfo(img, ajaxOptions) {
12
+ return loadImageWithBlob(img, ajaxOptions).then(function (_a) {
13
+ var image = _a.image, blob = _a.blob;
14
+ var width = image.width, height = image.height;
15
+ return {
16
+ width: width,
17
+ height: height,
18
+ contrast: calcContrast(width, height),
19
+ measure: "".concat(width, " \u00D7 ").concat(height, " px"),
20
+ size: bytesToSize(blob.size),
21
+ bytes: blob.size,
22
+ image: image,
23
+ blob: blob
24
+ };
58
25
  });
59
26
  }
60
27
 
package/esm/index.js CHANGED
@@ -16,7 +16,6 @@ export { default as isIPv6 } from './isIPv6.js';
16
16
  export { default as isUrl } from './isUrl.js';
17
17
  export { default as isBusinessLicense } from './isBusinessLicense.js';
18
18
  export { default as validatePassword } from './validatePassword.js';
19
- export { default as isPromiseLike } from './isPromiseLike.js';
20
19
  export { default as isHMCard } from './isHMCard.js';
21
20
  export { default as isTWCard } from './isTWCard.js';
22
21
  export { default as isSwiftCode } from './isSwiftCode.js';
@@ -27,11 +26,9 @@ export { default as replaceChar } from './replaceChar.js';
27
26
  export { default as numberToChinese } from './numberToChinese.js';
28
27
  export { default as bytesToSize } from './bytesToSize.js';
29
28
  export { default as parseIdCard } from './parseIdCard.js';
30
- export { default as blobToDataURL } from './blobToDataURL.js';
31
29
  export { default as fileReader } from './fileReader.js';
32
30
  export { default as dataURLToBlob } from './dataURLToBlob.js';
33
31
  export { default as setDataURLPrefix } from './setDataURLPrefix.js';
34
- export { default as normalizeString } from './normalizeString.js';
35
32
  export { default as safeDate } from './safeDate.js';
36
33
  export { default as formatMobile } from './formatMobile.js';
37
34
  export { default as padZero } from './padZero.js';
@@ -54,7 +51,6 @@ export { default as loadImageWithBlob } from './loadImageWithBlob.js';
54
51
  export { default as loadScript } from './loadScript.js';
55
52
  export { default as randomString } from './randomString.js';
56
53
  export { default as strlen } from './strlen.js';
57
- export { default as waitTime } from './waitTime.js';
58
54
  export { default as transformFieldNames } from './transformFieldNames.js';
59
55
  export { default as listToTree } from './listToTree.js';
60
56
  export { default as treeToList } from './treeToList.js';
@@ -65,7 +61,3 @@ export { default as findTreeSelect } from './findTreeSelect.js';
65
61
  export { setDisableWarning } from './utils/config.js';
66
62
  export { default as VERSION } from './VERSION.js';
67
63
  export { default as AsyncMemo } from './AsyncMemo.js';
68
-
69
- var version = "4.23.0";
70
-
71
- export { version };
@@ -22,8 +22,7 @@ function sumCheckCode(preCode) {
22
22
  function isBusinessLicense(value, options) {
23
23
  if (options === void 0) { options = {}; }
24
24
  var valueStr = toString(value);
25
- var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
26
- var needCheckCode = !loose && cc;
25
+ var _a = options.checkCode, needCheckCode = _a === void 0 ? true : _a;
27
26
  var passBaseRule = baseReg.test(valueStr);
28
27
  if (!needCheckCode || !passBaseRule) {
29
28
  return passBaseRule;
@@ -17,10 +17,8 @@ function sumCheckCode(preCode) {
17
17
  return baseCodeArr[checkCodeIndex];
18
18
  }
19
19
  function isSocialCreditCode(value, options) {
20
- if (options === void 0) { options = {}; }
21
20
  var valueStr = toString(value);
22
- var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
23
- var needCheckCode = !loose && cc;
21
+ var _a = (options || {}).checkCode, needCheckCode = _a === void 0 ? true : _a;
24
22
  var passBaseRule = baseReg.test(valueStr);
25
23
  if (!needCheckCode || !passBaseRule) {
26
24
  return passBaseRule;
package/esm/loadImage.js CHANGED
@@ -1,52 +1,25 @@
1
1
  import { isBlob } from 'ut2';
2
- import { revokeObjectURL, createObjectURL } from './utils/native.js';
3
- import Cache from './utils/Cache.js';
2
+ import { createObjectURL, revokeObjectURL } from './utils/native.js';
4
3
 
5
- var cache = new Cache({ max: 1 });
6
- cache.on('del', function (v) {
7
- if (v.r) {
8
- try {
9
- revokeObjectURL(v.data.src);
10
- }
11
- catch (_a) {
12
- }
13
- }
14
- });
15
- function loadImage(img, cacheOptions) {
16
- if (cacheOptions === void 0) { cacheOptions = true; }
17
- var _cacheOptions = {
18
- useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
19
- autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
20
- };
4
+ function loadImage(img) {
21
5
  return new Promise(function (resolve, reject) {
22
- if (_cacheOptions.useCache && cache.has(img)) {
23
- resolve(cache.get(img).data);
6
+ var imgIsBlob = isBlob(img);
7
+ var url = imgIsBlob ? createObjectURL(img) : img;
8
+ var image = new Image();
9
+ if (!imgIsBlob) {
10
+ image.crossOrigin = 'anonymous';
24
11
  }
25
- else {
26
- var imgIsBlob_1 = isBlob(img);
27
- var url_1 = imgIsBlob_1 ? createObjectURL(img) : img;
28
- var image_1 = new Image();
29
- if (!imgIsBlob_1) {
30
- image_1.crossOrigin = 'anonymous';
12
+ image.onload = function () {
13
+ resolve(image);
14
+ };
15
+ image.onerror = function (err) {
16
+ if (imgIsBlob) {
17
+ revokeObjectURL(url);
31
18
  }
32
- image_1.onload = function () {
33
- if (_cacheOptions.useCache) {
34
- cache.set(img, {
35
- data: image_1,
36
- r: _cacheOptions.autoRevokeOnDel
37
- });
38
- }
39
- resolve(image_1);
40
- };
41
- image_1.onerror = function (err) {
42
- if (imgIsBlob_1) {
43
- revokeObjectURL(url_1);
44
- }
45
- console.error("[loadImage] The image load failed, '".concat(img, "'."));
46
- reject(err);
47
- };
48
- image_1.src = url_1;
49
- }
19
+ console.error("[loadImage] The image load failed, '".concat(img, "'."));
20
+ reject(err);
21
+ };
22
+ image.src = url;
50
23
  });
51
24
  }
52
25
 
@@ -1,51 +1,23 @@
1
- import { revokeObjectURL, createObjectURL } from './utils/native.js';
1
+ import { createObjectURL, revokeObjectURL } from './utils/native.js';
2
2
  import getFileBlob from './getFileBlob.js';
3
- import Cache from './utils/Cache.js';
4
3
 
5
- var cache = new Cache({ max: 1 });
6
- cache.on('del', function (v) {
7
- if (v.r) {
8
- try {
9
- revokeObjectURL(v.data.image.src);
10
- }
11
- catch (_a) {
12
- }
13
- }
14
- });
15
- function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
16
- if (cacheOptions === void 0) { cacheOptions = true; }
17
- var _cacheOptions = {
18
- useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
19
- autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
20
- };
4
+ function loadImageWithBlob(img, ajaxOptions) {
21
5
  return new Promise(function (resolve, reject) {
22
- if (_cacheOptions.useCache && cache.has(img)) {
23
- resolve(cache.get(img).data);
24
- }
25
- else {
26
- getFileBlob(img, ajaxOptions)
27
- .then(function (blob) {
28
- var url = createObjectURL(blob);
29
- var image = new Image();
30
- image.onload = function () {
31
- var result = { blob: blob, image: image };
32
- if (_cacheOptions.useCache) {
33
- cache.set(img, {
34
- data: result,
35
- r: _cacheOptions.autoRevokeOnDel
36
- });
37
- }
38
- resolve(result);
39
- };
40
- image.onerror = function (err) {
41
- revokeObjectURL(url);
42
- console.error("[loadImageWithBlob] The image load failed, '".concat(img, "'."));
43
- reject(err);
44
- };
45
- image.src = url;
46
- })
47
- .catch(reject);
48
- }
6
+ getFileBlob(img, ajaxOptions)
7
+ .then(function (blob) {
8
+ var url = createObjectURL(blob);
9
+ var image = new Image();
10
+ image.onload = function () {
11
+ resolve({ blob: blob, image: image });
12
+ };
13
+ image.onerror = function (err) {
14
+ revokeObjectURL(url);
15
+ console.error("[loadImageWithBlob] The image load failed, '".concat(img, "'."));
16
+ reject(err);
17
+ };
18
+ image.src = url;
19
+ })
20
+ .catch(reject);
49
21
  });
50
22
  }
51
23
 
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "4.23.0";
3
+ var VERSION = "5.0.0";
4
4
  var VERSION$1 = VERSION;
5
5
 
6
6
  module.exports = VERSION$1;
@@ -14,8 +14,8 @@ function canvasToBlob(canvas, type, quality) {
14
14
  var compressImage = function (img, options) {
15
15
  if (options === void 0) { options = {}; }
16
16
  return new Promise(function (resolve, reject) {
17
- var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.cacheImage, cacheImage = _b === void 0 ? true : _b, _c = options.background, background = _c === void 0 ? '#fff' : _c, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _d = options.format, format = _d === void 0 ? 'blob' : _d, _e = options.type, type = _e === void 0 ? 'image/jpeg' : _e, _f = options.quality, quality = _f === void 0 ? 0.8 : _f, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
18
- loadImageWithBlob(img, cacheImage, ajaxOptions)
17
+ var width = options.width, height = options.height, rotate = options.rotate, _a = options.offset, offset = _a === void 0 ? [0, 0] : _a, _b = options.background, background = _b === void 0 ? '#fff' : _b, canvasWidth = options.canvasWidth, canvasHeight = options.canvasHeight, _c = options.format, format = _c === void 0 ? 'blob' : _c, _d = options.type, type = _d === void 0 ? 'image/jpeg' : _d, _e = options.quality, quality = _e === void 0 ? 0.8 : _e, beforeCompress = options.beforeCompress, beforeDraw = options.beforeDraw, afterDraw = options.afterDraw, ajaxOptions = options.ajaxOptions;
18
+ loadImageWithBlob(img, ajaxOptions)
19
19
  .then(function (_a) {
20
20
  var image = _a.image, blob = _a.blob;
21
21
  var numWidth = ut2.toNumber(width);
@@ -4,13 +4,11 @@ var ut2 = require('ut2');
4
4
 
5
5
  function formatBankCard(bankCardNo, options) {
6
6
  if (bankCardNo === void 0) { bankCardNo = ''; }
7
- if (options === void 0) { options = {}; }
8
- var _a = options.char, char = _a === void 0 ? ' ' : _a, _b = options.length, length = _b === void 0 ? 4 : _b;
9
- var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
7
+ var _a = options || {}, _b = _a.spaceMark, spaceMark = _b === void 0 ? ' ' : _b, _c = _a.length, length = _c === void 0 ? 4 : _c;
10
8
  var reg = new RegExp("(.{".concat(length, "})"), 'g');
11
- var regChar = new RegExp("".concat(realSpaceMark), 'g');
9
+ var regChar = new RegExp("".concat(spaceMark), 'g');
12
10
  var realValue = ut2.toString(bankCardNo).replace(regChar, '');
13
- var str = realValue.replace(reg, "$1".concat(realSpaceMark));
11
+ var str = realValue.replace(reg, "$1".concat(spaceMark));
14
12
  return realValue.length % length === 0 ? str.substring(0, str.length - 1) : str;
15
13
  }
16
14
 
@@ -4,16 +4,14 @@ var ut2 = require('ut2');
4
4
 
5
5
  function formatMobile(mobileNo, options) {
6
6
  if (mobileNo === void 0) { mobileNo = ''; }
7
- if (options === void 0) { options = {}; }
8
- var _a = options.char, char = _a === void 0 ? ' ' : _a;
9
- var realSpaceMark = 'spaceMark' in options ? options.spaceMark : char;
10
- var regChar = new RegExp(realSpaceMark, 'g');
7
+ var _a = (options || {}).spaceMark, spaceMark = _a === void 0 ? ' ' : _a;
8
+ var regChar = new RegExp(spaceMark, 'g');
11
9
  var realValue = ut2.toString(mobileNo).replace(regChar, '').substring(0, 11);
12
10
  if (realValue.length > 7) {
13
- return realValue.replace(/^(...)(....)/g, "$1".concat(realSpaceMark, "$2").concat(realSpaceMark));
11
+ return realValue.replace(/^(...)(....)/g, "$1".concat(spaceMark, "$2").concat(spaceMark));
14
12
  }
15
13
  if (realValue.length > 3) {
16
- return realValue.replace(/^(...)/g, "$1".concat(realSpaceMark));
14
+ return realValue.replace(/^(...)/g, "$1".concat(spaceMark));
17
15
  }
18
16
  return realValue;
19
17
  }
@@ -5,58 +5,25 @@ var divide = require('./divide.js');
5
5
  var gcd = require('./gcd.js');
6
6
  var loadImageWithBlob = require('./loadImageWithBlob.js');
7
7
  var bytesToSize = require('./bytesToSize.js');
8
- var Cache = require('./utils/Cache.js');
9
- var native = require('./utils/native.js');
10
8
 
11
- var cache = new Cache({ max: 1 });
12
- cache.on('del', function (v) {
13
- if (v.r) {
14
- try {
15
- native.revokeObjectURL(v.data.image.src);
16
- }
17
- catch (_a) {
18
- }
19
- }
20
- });
21
9
  function calcContrast(w, h) {
22
10
  var n = gcd(w, h);
23
11
  return "".concat(divide(ut2.round(w), n), ":").concat(divide(ut2.round(h), n));
24
12
  }
25
- function getImageInfo(img, cacheOptions, ajaxOptions) {
26
- if (cacheOptions === void 0) { cacheOptions = true; }
27
- var _cacheOptions = {
28
- useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
29
- autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
30
- };
31
- return new Promise(function (resolve, reject) {
32
- if (_cacheOptions.useCache && cache.has(img)) {
33
- resolve(cache.get(img).data);
34
- }
35
- else {
36
- loadImageWithBlob(img, false, ajaxOptions)
37
- .then(function (_a) {
38
- var image = _a.image, blob = _a.blob;
39
- var width = image.width, height = image.height;
40
- var result = {
41
- width: width,
42
- height: height,
43
- contrast: calcContrast(width, height),
44
- measure: "".concat(width, " \u00D7 ").concat(height, " px"),
45
- size: bytesToSize(blob.size),
46
- bytes: blob.size,
47
- image: image,
48
- blob: blob
49
- };
50
- if (_cacheOptions.useCache) {
51
- cache.set(img, {
52
- data: result,
53
- r: _cacheOptions.autoRevokeOnDel
54
- });
55
- }
56
- resolve(result);
57
- })
58
- .catch(reject);
59
- }
13
+ function getImageInfo(img, ajaxOptions) {
14
+ return loadImageWithBlob(img, ajaxOptions).then(function (_a) {
15
+ var image = _a.image, blob = _a.blob;
16
+ var width = image.width, height = image.height;
17
+ return {
18
+ width: width,
19
+ height: height,
20
+ contrast: calcContrast(width, height),
21
+ measure: "".concat(width, " \u00D7 ").concat(height, " px"),
22
+ size: bytesToSize(blob.size),
23
+ bytes: blob.size,
24
+ image: image,
25
+ blob: blob
26
+ };
60
27
  });
61
28
  }
62
29
 
package/lib/index.js CHANGED
@@ -18,7 +18,6 @@ var isIPv6 = require('./isIPv6.js');
18
18
  var isUrl = require('./isUrl.js');
19
19
  var isBusinessLicense = require('./isBusinessLicense.js');
20
20
  var validatePassword = require('./validatePassword.js');
21
- var isPromiseLike = require('./isPromiseLike.js');
22
21
  var isHMCard = require('./isHMCard.js');
23
22
  var isTWCard = require('./isTWCard.js');
24
23
  var isSwiftCode = require('./isSwiftCode.js');
@@ -29,11 +28,9 @@ var replaceChar = require('./replaceChar.js');
29
28
  var numberToChinese = require('./numberToChinese.js');
30
29
  var bytesToSize = require('./bytesToSize.js');
31
30
  var parseIdCard = require('./parseIdCard.js');
32
- var blobToDataURL = require('./blobToDataURL.js');
33
31
  var fileReader = require('./fileReader.js');
34
32
  var dataURLToBlob = require('./dataURLToBlob.js');
35
33
  var setDataURLPrefix = require('./setDataURLPrefix.js');
36
- var normalizeString = require('./normalizeString.js');
37
34
  var safeDate = require('./safeDate.js');
38
35
  var formatMobile = require('./formatMobile.js');
39
36
  var padZero = require('./padZero.js');
@@ -56,7 +53,6 @@ var loadImageWithBlob = require('./loadImageWithBlob.js');
56
53
  var loadScript = require('./loadScript.js');
57
54
  var randomString = require('./randomString.js');
58
55
  var strlen = require('./strlen.js');
59
- var waitTime = require('./waitTime.js');
60
56
  var transformFieldNames = require('./transformFieldNames.js');
61
57
  var listToTree = require('./listToTree.js');
62
58
  var treeToList = require('./treeToList.js');
@@ -68,7 +64,7 @@ var config = require('./utils/config.js');
68
64
  var VERSION = require('./VERSION.js');
69
65
  var AsyncMemo = require('./AsyncMemo.js');
70
66
 
71
- exports.version = "4.23.0";
67
+
72
68
 
73
69
  exports.isMobile = isMobile;
74
70
  exports.isTelephone = isTelephone;
@@ -88,7 +84,6 @@ exports.isIPv6 = isIPv6;
88
84
  exports.isUrl = isUrl;
89
85
  exports.isBusinessLicense = isBusinessLicense;
90
86
  exports.validatePassword = validatePassword;
91
- exports.isPromiseLike = isPromiseLike;
92
87
  exports.isHMCard = isHMCard;
93
88
  exports.isTWCard = isTWCard;
94
89
  exports.isSwiftCode = isSwiftCode;
@@ -99,11 +94,9 @@ exports.replaceChar = replaceChar;
99
94
  exports.numberToChinese = numberToChinese;
100
95
  exports.bytesToSize = bytesToSize;
101
96
  exports.parseIdCard = parseIdCard;
102
- exports.blobToDataURL = blobToDataURL;
103
97
  exports.fileReader = fileReader;
104
98
  exports.dataURLToBlob = dataURLToBlob;
105
99
  exports.setDataURLPrefix = setDataURLPrefix;
106
- exports.normalizeString = normalizeString;
107
100
  exports.safeDate = safeDate;
108
101
  exports.formatMobile = formatMobile;
109
102
  exports.padZero = padZero;
@@ -126,7 +119,6 @@ exports.loadImageWithBlob = loadImageWithBlob;
126
119
  exports.loadScript = loadScript;
127
120
  exports.randomString = randomString;
128
121
  exports.strlen = strlen;
129
- exports.waitTime = waitTime;
130
122
  exports.transformFieldNames = transformFieldNames;
131
123
  exports.listToTree = listToTree;
132
124
  exports.treeToList = treeToList;
@@ -24,8 +24,7 @@ function sumCheckCode(preCode) {
24
24
  function isBusinessLicense(value, options) {
25
25
  if (options === void 0) { options = {}; }
26
26
  var valueStr = ut2.toString(value);
27
- var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
28
- var needCheckCode = !loose && cc;
27
+ var _a = options.checkCode, needCheckCode = _a === void 0 ? true : _a;
29
28
  var passBaseRule = baseReg.test(valueStr);
30
29
  if (!needCheckCode || !passBaseRule) {
31
30
  return passBaseRule;
@@ -19,10 +19,8 @@ function sumCheckCode(preCode) {
19
19
  return baseCodeArr[checkCodeIndex];
20
20
  }
21
21
  function isSocialCreditCode(value, options) {
22
- if (options === void 0) { options = {}; }
23
22
  var valueStr = ut2.toString(value);
24
- var _a = options.loose, loose = _a === void 0 ? false : _a, _b = options.checkCode, cc = _b === void 0 ? true : _b;
25
- var needCheckCode = !loose && cc;
23
+ var _a = (options || {}).checkCode, needCheckCode = _a === void 0 ? true : _a;
26
24
  var passBaseRule = baseReg.test(valueStr);
27
25
  if (!needCheckCode || !passBaseRule) {
28
26
  return passBaseRule;
package/lib/loadImage.js CHANGED
@@ -2,53 +2,26 @@
2
2
 
3
3
  var ut2 = require('ut2');
4
4
  var native = require('./utils/native.js');
5
- var Cache = require('./utils/Cache.js');
6
5
 
7
- var cache = new Cache({ max: 1 });
8
- cache.on('del', function (v) {
9
- if (v.r) {
10
- try {
11
- native.revokeObjectURL(v.data.src);
12
- }
13
- catch (_a) {
14
- }
15
- }
16
- });
17
- function loadImage(img, cacheOptions) {
18
- if (cacheOptions === void 0) { cacheOptions = true; }
19
- var _cacheOptions = {
20
- useCache: typeof cacheOptions === 'object' ? cacheOptions.useCache !== false : cacheOptions !== false,
21
- autoRevokeOnDel: typeof cacheOptions === 'object' ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions
22
- };
6
+ function loadImage(img) {
23
7
  return new Promise(function (resolve, reject) {
24
- if (_cacheOptions.useCache && cache.has(img)) {
25
- resolve(cache.get(img).data);
8
+ var imgIsBlob = ut2.isBlob(img);
9
+ var url = imgIsBlob ? native.createObjectURL(img) : img;
10
+ var image = new Image();
11
+ if (!imgIsBlob) {
12
+ image.crossOrigin = 'anonymous';
26
13
  }
27
- else {
28
- var imgIsBlob_1 = ut2.isBlob(img);
29
- var url_1 = imgIsBlob_1 ? native.createObjectURL(img) : img;
30
- var image_1 = new Image();
31
- if (!imgIsBlob_1) {
32
- image_1.crossOrigin = 'anonymous';
14
+ image.onload = function () {
15
+ resolve(image);
16
+ };
17
+ image.onerror = function (err) {
18
+ if (imgIsBlob) {
19
+ native.revokeObjectURL(url);
33
20
  }
34
- image_1.onload = function () {
35
- if (_cacheOptions.useCache) {
36
- cache.set(img, {
37
- data: image_1,
38
- r: _cacheOptions.autoRevokeOnDel
39
- });
40
- }
41
- resolve(image_1);
42
- };
43
- image_1.onerror = function (err) {
44
- if (imgIsBlob_1) {
45
- native.revokeObjectURL(url_1);
46
- }
47
- console.error("[loadImage] The image load failed, '".concat(img, "'."));
48
- reject(err);
49
- };
50
- image_1.src = url_1;
51
- }
21
+ console.error("[loadImage] The image load failed, '".concat(img, "'."));
22
+ reject(err);
23
+ };
24
+ image.src = url;
52
25
  });
53
26
  }
54
27