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.
- package/dist/util-helpers.js +844 -961
- package/dist/util-helpers.js.map +1 -1
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/VERSION.js +1 -1
- package/esm/compressImage.js +2 -2
- package/esm/formatBankCard.js +3 -5
- package/esm/formatMobile.js +4 -6
- package/esm/getImageInfo.js +16 -43
- package/esm/index.js +0 -8
- package/esm/isBusinessLicense.js +1 -2
- package/esm/isSocialCreditCode.js +1 -3
- package/esm/loadImage.js +20 -45
- package/esm/loadImageWithBlob.js +19 -46
- package/lib/VERSION.js +1 -1
- package/lib/compressImage.js +2 -2
- package/lib/formatBankCard.js +3 -5
- package/lib/formatMobile.js +4 -6
- package/lib/getImageInfo.js +15 -42
- package/lib/index.js +1 -9
- package/lib/isBusinessLicense.js +1 -2
- package/lib/isSocialCreditCode.js +1 -3
- package/lib/loadImage.js +18 -43
- package/lib/loadImageWithBlob.js +18 -45
- package/package.json +1 -1
- package/types/compressImage.d.ts +2 -4
- package/types/formatBankCard.d.ts +1 -3
- package/types/formatMobile.d.ts +0 -2
- package/types/getImageInfo.d.ts +10 -12
- package/types/index.d.ts +0 -8
- package/types/isBusinessLicense.d.ts +0 -2
- package/types/isSocialCreditCode.d.ts +0 -2
- package/types/loadImage.d.ts +1 -12
- package/types/loadImageWithBlob.d.ts +6 -10
- package/esm/blobToDataURL.js +0 -7
- package/esm/isPromiseLike.js +0 -7
- package/esm/normalizeString.js +0 -7
- package/esm/waitTime.js +0 -8
- package/lib/blobToDataURL.js +0 -9
- package/lib/isPromiseLike.js +0 -9
- package/lib/normalizeString.js +0 -9
- package/lib/waitTime.js +0 -10
- package/types/blobToDataURL.d.ts +0 -29
- package/types/isPromiseLike.d.ts +0 -19
- package/types/normalizeString.d.ts +0 -26
- package/types/utils/Cache.d.ts +0 -14
- package/types/waitTime.d.ts +0 -24
package/esm/VERSION.js
CHANGED
package/esm/compressImage.js
CHANGED
|
@@ -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.
|
|
16
|
-
loadImageWithBlob(img,
|
|
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);
|
package/esm/formatBankCard.js
CHANGED
|
@@ -2,13 +2,11 @@ import { toString } from 'ut2';
|
|
|
2
2
|
|
|
3
3
|
function formatBankCard(bankCardNo, options) {
|
|
4
4
|
if (bankCardNo === void 0) { bankCardNo = ''; }
|
|
5
|
-
|
|
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(
|
|
7
|
+
var regChar = new RegExp("".concat(spaceMark), 'g');
|
|
10
8
|
var realValue = toString(bankCardNo).replace(regChar, '');
|
|
11
|
-
var str = realValue.replace(reg, "$1".concat(
|
|
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
|
|
package/esm/formatMobile.js
CHANGED
|
@@ -2,16 +2,14 @@ import { toString } from 'ut2';
|
|
|
2
2
|
|
|
3
3
|
function formatMobile(mobileNo, options) {
|
|
4
4
|
if (mobileNo === void 0) { mobileNo = ''; }
|
|
5
|
-
|
|
6
|
-
var
|
|
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(
|
|
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(
|
|
12
|
+
return realValue.replace(/^(...)/g, "$1".concat(spaceMark));
|
|
15
13
|
}
|
|
16
14
|
return realValue;
|
|
17
15
|
}
|
package/esm/getImageInfo.js
CHANGED
|
@@ -1,55 +1,28 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 };
|
package/esm/isBusinessLicense.js
CHANGED
|
@@ -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.
|
|
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
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import AsyncMemo from './AsyncMemo.js';
|
|
1
|
+
import { isBlob } from 'ut2';
|
|
2
|
+
import { createObjectURL, revokeObjectURL } from './utils/native.js';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 };
|
package/esm/loadImageWithBlob.js
CHANGED
|
@@ -1,51 +1,24 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
package/lib/compressImage.js
CHANGED
|
@@ -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.
|
|
18
|
-
loadImageWithBlob(img,
|
|
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);
|
package/lib/formatBankCard.js
CHANGED
|
@@ -4,13 +4,11 @@ var ut2 = require('ut2');
|
|
|
4
4
|
|
|
5
5
|
function formatBankCard(bankCardNo, options) {
|
|
6
6
|
if (bankCardNo === void 0) { bankCardNo = ''; }
|
|
7
|
-
|
|
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(
|
|
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(
|
|
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
|
|
package/lib/formatMobile.js
CHANGED
|
@@ -4,16 +4,14 @@ var ut2 = require('ut2');
|
|
|
4
4
|
|
|
5
5
|
function formatMobile(mobileNo, options) {
|
|
6
6
|
if (mobileNo === void 0) { mobileNo = ''; }
|
|
7
|
-
|
|
8
|
-
var
|
|
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(
|
|
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(
|
|
14
|
+
return realValue.replace(/^(...)/g, "$1".concat(spaceMark));
|
|
17
15
|
}
|
|
18
16
|
return realValue;
|
|
19
17
|
}
|
package/lib/getImageInfo.js
CHANGED
|
@@ -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,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
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;
|
package/lib/isBusinessLicense.js
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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;
|