util-helpers 4.23.1 → 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 (47) hide show
  1. package/dist/util-helpers.js +844 -961
  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 +16 -43
  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 +20 -45
  14. package/esm/loadImageWithBlob.js +19 -46
  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 +15 -42
  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 +18 -43
  24. package/lib/loadImageWithBlob.js +18 -45
  25. package/package.json +1 -1
  26. package/types/compressImage.d.ts +2 -4
  27. package/types/formatBankCard.d.ts +1 -3
  28. package/types/formatMobile.d.ts +0 -2
  29. package/types/getImageInfo.d.ts +10 -12
  30. package/types/index.d.ts +0 -8
  31. package/types/isBusinessLicense.d.ts +0 -2
  32. package/types/isSocialCreditCode.d.ts +0 -2
  33. package/types/loadImage.d.ts +1 -12
  34. package/types/loadImageWithBlob.d.ts +6 -10
  35. package/esm/blobToDataURL.js +0 -7
  36. package/esm/isPromiseLike.js +0 -7
  37. package/esm/normalizeString.js +0 -7
  38. package/esm/waitTime.js +0 -8
  39. package/lib/blobToDataURL.js +0 -9
  40. package/lib/isPromiseLike.js +0 -9
  41. package/lib/normalizeString.js +0 -9
  42. package/lib/waitTime.js +0 -10
  43. package/types/blobToDataURL.d.ts +0 -29
  44. package/types/isPromiseLike.d.ts +0 -19
  45. package/types/normalizeString.d.ts +0 -26
  46. package/types/utils/Cache.d.ts +0 -14
  47. package/types/waitTime.d.ts +0 -24
package/esm/VERSION.js CHANGED
@@ -1,4 +1,4 @@
1
- var VERSION = "4.23.1";
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
  }
@@ -1,55 +1,28 @@
1
- import { defaultTo, round } from 'ut2';
1
+ import { round } from 'ut2';
2
2
  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 { revokeObjectURL } from './utils/native.js';
7
- import AsyncMemo from './AsyncMemo.js';
8
6
 
9
- var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
10
- asyncMemo.cache.on('del', function (k, v) {
11
- try {
12
- if (v.r) {
13
- revokeObjectURL(v.data.image.src);
14
- }
15
- }
16
- catch (_a) {
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 cacheOptionsIsObject = typeof cacheOptions === 'object';
26
- var _cacheOptions = {
27
- useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
28
- autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
29
- cacheKey: defaultTo(cacheOptionsIsObject ? cacheOptions.cacheKey : undefined, typeof img === 'string' ? img : undefined)
30
- };
31
- return asyncMemo
32
- .run(function () {
33
- return loadImageWithBlob(img, false, ajaxOptions).then(function (_a) {
34
- var image = _a.image, blob = _a.blob;
35
- var width = image.width, height = image.height;
36
- var data = {
37
- width: width,
38
- height: height,
39
- contrast: calcContrast(width, height),
40
- measure: "".concat(width, " \u00D7 ").concat(height, " px"),
41
- size: bytesToSize(blob.size),
42
- bytes: blob.size,
43
- image: image,
44
- blob: blob
45
- };
46
- return {
47
- data: data,
48
- r: _cacheOptions.autoRevokeOnDel
49
- };
50
- });
51
- }, _cacheOptions.useCache && _cacheOptions.cacheKey ? _cacheOptions.cacheKey : undefined)
52
- .then(function (res) { return res.data; });
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
+ };
25
+ });
53
26
  }
54
27
 
55
28
  export { getImageInfo as default };
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.1";
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,51 +1,26 @@
1
- import { defaultTo, isBlob } from 'ut2';
2
- import { revokeObjectURL, createObjectURL } from './utils/native.js';
3
- import AsyncMemo from './AsyncMemo.js';
1
+ import { isBlob } from 'ut2';
2
+ import { createObjectURL, revokeObjectURL } from './utils/native.js';
4
3
 
5
- var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
6
- asyncMemo.cache.on('del', function (k, v) {
7
- try {
8
- if (v.r) {
9
- revokeObjectURL(v.data.src);
4
+ function loadImage(img) {
5
+ return new Promise(function (resolve, reject) {
6
+ var imgIsBlob = isBlob(img);
7
+ var url = imgIsBlob ? createObjectURL(img) : img;
8
+ var image = new Image();
9
+ if (!imgIsBlob) {
10
+ image.crossOrigin = 'anonymous';
10
11
  }
11
- }
12
- catch (_a) {
13
- }
14
- });
15
- function loadImage(img, cacheOptions) {
16
- if (cacheOptions === void 0) { cacheOptions = true; }
17
- var cacheOptionsIsObject = typeof cacheOptions === 'object';
18
- var _cacheOptions = {
19
- useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
20
- autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
21
- cacheKey: defaultTo(cacheOptionsIsObject ? cacheOptions.cacheKey : undefined, typeof img === 'string' ? img : undefined)
22
- };
23
- return asyncMemo
24
- .run(function () {
25
- return new Promise(function (resolve, reject) {
26
- var imgIsBlob = isBlob(img);
27
- var url = imgIsBlob ? createObjectURL(img) : img;
28
- var image = new Image();
29
- if (!imgIsBlob) {
30
- image.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.onload = function () {
33
- resolve({
34
- data: image,
35
- r: _cacheOptions.autoRevokeOnDel
36
- });
37
- };
38
- image.onerror = function (err) {
39
- if (imgIsBlob) {
40
- revokeObjectURL(url);
41
- }
42
- console.error("[loadImage] The image load failed, '".concat(img, "'."));
43
- reject(err);
44
- };
45
- image.src = url;
46
- });
47
- }, _cacheOptions.useCache && _cacheOptions.cacheKey ? _cacheOptions.cacheKey : undefined)
48
- .then(function (res) { return res.data; });
19
+ console.error("[loadImage] The image load failed, '".concat(img, "'."));
20
+ reject(err);
21
+ };
22
+ image.src = url;
23
+ });
49
24
  }
50
25
 
51
26
  export { loadImage as default };
@@ -1,51 +1,24 @@
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 AsyncMemo from './AsyncMemo.js';
4
- import { defaultTo } from 'ut2';
5
3
 
6
- var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
7
- asyncMemo.cache.on('del', function (k, v) {
8
- try {
9
- if (v.r) {
10
- revokeObjectURL(v.data.image.src);
11
- }
12
- }
13
- catch (_a) {
14
- }
15
- });
16
- function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
17
- if (cacheOptions === void 0) { cacheOptions = true; }
18
- var cacheOptionsIsObject = typeof cacheOptions === 'object';
19
- var _cacheOptions = {
20
- useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
21
- autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
22
- cacheKey: defaultTo(cacheOptionsIsObject ? cacheOptions.cacheKey : undefined, typeof img === 'string' ? img : undefined)
23
- };
24
- return asyncMemo
25
- .run(function () {
26
- return new Promise(function (resolve, reject) {
27
- getFileBlob(img, ajaxOptions)
28
- .then(function (blob) {
29
- var url = createObjectURL(blob);
30
- var image = new Image();
31
- image.onload = function () {
32
- var data = { blob: blob, image: image };
33
- resolve({
34
- data: data,
35
- r: _cacheOptions.autoRevokeOnDel
36
- });
37
- };
38
- image.onerror = function (err) {
39
- revokeObjectURL(url);
40
- console.error("[loadImageWithBlob] The image load failed, '".concat(img, "'."));
41
- reject(err);
42
- };
43
- image.src = url;
44
- })
45
- .catch(reject);
46
- });
47
- }, _cacheOptions.useCache && _cacheOptions.cacheKey ? _cacheOptions.cacheKey : undefined)
48
- .then(function (res) { return res.data; });
4
+ function loadImageWithBlob(img, ajaxOptions) {
5
+ return new Promise(function (resolve, reject) {
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);
21
+ });
49
22
  }
50
23
 
51
24
  export { loadImageWithBlob as default };
package/lib/VERSION.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var VERSION = "4.23.1";
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,53 +5,26 @@ 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 native = require('./utils/native.js');
9
- var AsyncMemo = require('./AsyncMemo.js');
10
8
 
11
- var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
12
- asyncMemo.cache.on('del', function (k, v) {
13
- try {
14
- if (v.r) {
15
- native.revokeObjectURL(v.data.image.src);
16
- }
17
- }
18
- catch (_a) {
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 cacheOptionsIsObject = typeof cacheOptions === 'object';
28
- var _cacheOptions = {
29
- useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
30
- autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
31
- cacheKey: ut2.defaultTo(cacheOptionsIsObject ? cacheOptions.cacheKey : undefined, typeof img === 'string' ? img : undefined)
32
- };
33
- return asyncMemo
34
- .run(function () {
35
- return loadImageWithBlob(img, false, ajaxOptions).then(function (_a) {
36
- var image = _a.image, blob = _a.blob;
37
- var width = image.width, height = image.height;
38
- var data = {
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
- return {
49
- data: data,
50
- r: _cacheOptions.autoRevokeOnDel
51
- };
52
- });
53
- }, _cacheOptions.useCache && _cacheOptions.cacheKey ? _cacheOptions.cacheKey : undefined)
54
- .then(function (res) { return res.data; });
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
+ };
27
+ });
55
28
  }
56
29
 
57
30
  module.exports = getImageInfo;
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.1";
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,52 +2,27 @@
2
2
 
3
3
  var ut2 = require('ut2');
4
4
  var native = require('./utils/native.js');
5
- var AsyncMemo = require('./AsyncMemo.js');
6
5
 
7
- var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
8
- asyncMemo.cache.on('del', function (k, v) {
9
- try {
10
- if (v.r) {
11
- native.revokeObjectURL(v.data.src);
6
+ function loadImage(img) {
7
+ return new Promise(function (resolve, reject) {
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';
12
13
  }
13
- }
14
- catch (_a) {
15
- }
16
- });
17
- function loadImage(img, cacheOptions) {
18
- if (cacheOptions === void 0) { cacheOptions = true; }
19
- var cacheOptionsIsObject = typeof cacheOptions === 'object';
20
- var _cacheOptions = {
21
- useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
22
- autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
23
- cacheKey: ut2.defaultTo(cacheOptionsIsObject ? cacheOptions.cacheKey : undefined, typeof img === 'string' ? img : undefined)
24
- };
25
- return asyncMemo
26
- .run(function () {
27
- return new Promise(function (resolve, reject) {
28
- var imgIsBlob = ut2.isBlob(img);
29
- var url = imgIsBlob ? native.createObjectURL(img) : img;
30
- var image = new Image();
31
- if (!imgIsBlob) {
32
- image.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.onload = function () {
35
- resolve({
36
- data: image,
37
- r: _cacheOptions.autoRevokeOnDel
38
- });
39
- };
40
- image.onerror = function (err) {
41
- if (imgIsBlob) {
42
- native.revokeObjectURL(url);
43
- }
44
- console.error("[loadImage] The image load failed, '".concat(img, "'."));
45
- reject(err);
46
- };
47
- image.src = url;
48
- });
49
- }, _cacheOptions.useCache && _cacheOptions.cacheKey ? _cacheOptions.cacheKey : undefined)
50
- .then(function (res) { return res.data; });
21
+ console.error("[loadImage] The image load failed, '".concat(img, "'."));
22
+ reject(err);
23
+ };
24
+ image.src = url;
25
+ });
51
26
  }
52
27
 
53
28
  module.exports = loadImage;