util-helpers 4.22.2 → 4.23.1
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/README.md +3 -0
- package/dist/util-helpers.js +594 -560
- 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/getImageInfo.js +34 -40
- package/esm/index.js +2 -1
- package/esm/loadImage.js +32 -34
- package/esm/loadImageWithBlob.js +23 -24
- package/esm/randomString.js +26 -12
- package/esm/transformObjectValue.js +25 -0
- package/esm/validatePassword.js +4 -13
- package/lib/VERSION.js +1 -1
- package/lib/getImageInfo.js +33 -39
- package/lib/index.js +3 -1
- package/lib/loadImage.js +31 -33
- package/lib/loadImageWithBlob.js +23 -24
- package/lib/randomString.js +25 -11
- package/lib/transformObjectValue.js +27 -0
- package/lib/validatePassword.js +4 -13
- package/package.json +11 -11
- package/types/AsyncMemo.d.ts +16 -2
- package/types/ajax.d.ts +2 -2
- package/types/blobToDataURL.d.ts +1 -1
- package/types/calculateCursorPosition.d.ts +2 -2
- package/types/compressImage.d.ts +1 -1
- package/types/dataURLToBlob.d.ts +1 -1
- package/types/download.d.ts +3 -3
- package/types/fileReader.d.ts +1 -1
- package/types/gcd.d.ts +1 -1
- package/types/getImageInfo.d.ts +11 -10
- package/types/index.d.ts +3 -2
- package/types/isBankCard.d.ts +1 -1
- package/types/isBusinessLicense.d.ts +1 -1
- package/types/isChinese.d.ts +3 -3
- package/types/isHMCard.d.ts +1 -1
- package/types/isIdCard.d.ts +2 -2
- package/types/isPassport.d.ts +1 -1
- package/types/isPassword.d.ts +1 -1
- package/types/isSocialCreditCode.d.ts +1 -1
- package/types/isSwiftCode.d.ts +1 -1
- package/types/isTWCard.d.ts +1 -1
- package/types/isUrl.d.ts +1 -1
- package/types/isVehicle.d.ts +1 -1
- package/types/lcm.d.ts +1 -1
- package/types/loadImage.d.ts +2 -0
- package/types/loadImageWithBlob.d.ts +6 -4
- package/types/normalizeString.d.ts +1 -1
- package/types/numberToChinese.d.ts +1 -1
- package/types/parseIdCard.d.ts +1 -1
- package/types/randomString.d.ts +7 -3
- package/types/safeDate.d.ts +1 -1
- package/types/setDataURLPrefix.d.ts +2 -2
- package/types/transformObjectValue.d.ts +67 -0
- package/types/validatePassword.d.ts +1 -1
- package/esm/utils/Cache.js +0 -47
- package/lib/utils/Cache.js +0 -49
package/lib/loadImageWithBlob.js
CHANGED
|
@@ -2,42 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
var native = require('./utils/native.js');
|
|
4
4
|
var getFileBlob = require('./getFileBlob.js');
|
|
5
|
-
var
|
|
5
|
+
var AsyncMemo = require('./AsyncMemo.js');
|
|
6
|
+
var ut2 = require('ut2');
|
|
6
7
|
|
|
7
|
-
var
|
|
8
|
-
cache.on('del', function (v) {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
|
|
9
|
+
asyncMemo.cache.on('del', function (k, v) {
|
|
10
|
+
try {
|
|
11
|
+
if (v.r) {
|
|
11
12
|
native.revokeObjectURL(v.data.image.src);
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
15
16
|
}
|
|
16
17
|
});
|
|
17
18
|
function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
|
|
18
19
|
if (cacheOptions === void 0) { cacheOptions = true; }
|
|
20
|
+
var cacheOptionsIsObject = typeof cacheOptions === 'object';
|
|
19
21
|
var _cacheOptions = {
|
|
20
|
-
useCache:
|
|
21
|
-
autoRevokeOnDel:
|
|
22
|
+
useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
|
|
23
|
+
autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
|
|
24
|
+
cacheKey: ut2.defaultTo(cacheOptionsIsObject ? cacheOptions.cacheKey : undefined, typeof img === 'string' ? img : undefined)
|
|
22
25
|
};
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
26
|
+
return asyncMemo
|
|
27
|
+
.run(function () {
|
|
28
|
+
return new Promise(function (resolve, reject) {
|
|
28
29
|
getFileBlob(img, ajaxOptions)
|
|
29
30
|
.then(function (blob) {
|
|
30
31
|
var url = native.createObjectURL(blob);
|
|
31
32
|
var image = new Image();
|
|
32
33
|
image.onload = function () {
|
|
33
|
-
var
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
resolve(result);
|
|
34
|
+
var data = { blob: blob, image: image };
|
|
35
|
+
resolve({
|
|
36
|
+
data: data,
|
|
37
|
+
r: _cacheOptions.autoRevokeOnDel
|
|
38
|
+
});
|
|
41
39
|
};
|
|
42
40
|
image.onerror = function (err) {
|
|
43
41
|
native.revokeObjectURL(url);
|
|
@@ -47,8 +45,9 @@ function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
|
|
|
47
45
|
image.src = url;
|
|
48
46
|
})
|
|
49
47
|
.catch(reject);
|
|
50
|
-
}
|
|
51
|
-
})
|
|
48
|
+
});
|
|
49
|
+
}, _cacheOptions.useCache && _cacheOptions.cacheKey ? _cacheOptions.cacheKey : undefined)
|
|
50
|
+
.then(function (res) { return res.data; });
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
module.exports = loadImageWithBlob;
|
package/lib/randomString.js
CHANGED
|
@@ -2,21 +2,35 @@
|
|
|
2
2
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
var letter = 'abcdefghijklmnopqrstuvwxyz';
|
|
6
|
+
var chars = {
|
|
7
|
+
number: '0123456789',
|
|
8
|
+
lower: letter,
|
|
9
|
+
upper: letter.toUpperCase()
|
|
10
|
+
};
|
|
11
|
+
var allChars = chars.number + chars.lower + chars.upper;
|
|
12
|
+
function internalRandomString(len, pool, prefix) {
|
|
9
13
|
if (prefix === void 0) { prefix = ''; }
|
|
10
14
|
while (len-- > 0) {
|
|
11
|
-
var r =
|
|
12
|
-
return internalRandomString(len,
|
|
15
|
+
var r = pool[ut2.randomInt(0, pool.length - 1)];
|
|
16
|
+
return internalRandomString(len, pool, prefix + r);
|
|
13
17
|
}
|
|
14
18
|
return prefix;
|
|
15
19
|
}
|
|
16
|
-
function
|
|
20
|
+
var randomString = function (len, pool) {
|
|
17
21
|
if (len === void 0) { len = 0; }
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
var _pool;
|
|
23
|
+
if (typeof pool !== 'string') {
|
|
24
|
+
_pool = allChars;
|
|
25
|
+
}
|
|
26
|
+
else if (chars[pool]) {
|
|
27
|
+
_pool = chars[pool];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
_pool = pool;
|
|
31
|
+
}
|
|
32
|
+
return internalRandomString(ut2.toNumber(len), _pool);
|
|
33
|
+
};
|
|
34
|
+
var randomString$1 = randomString;
|
|
21
35
|
|
|
22
|
-
module.exports = randomString;
|
|
36
|
+
module.exports = randomString$1;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ut2 = require('ut2');
|
|
4
|
+
|
|
5
|
+
var transformObjectValue = function (data, fn, deep) {
|
|
6
|
+
if (deep === void 0) { deep = true; }
|
|
7
|
+
if (ut2.isPlainObject(data)) {
|
|
8
|
+
var result_1 = {};
|
|
9
|
+
ut2.forEach(data, function (value, key) {
|
|
10
|
+
var newValue = deep && (ut2.isPlainObject(value) || ut2.isArray(value)) ? transformObjectValue(value, fn) : fn(value, key);
|
|
11
|
+
result_1[key] = newValue;
|
|
12
|
+
});
|
|
13
|
+
return result_1;
|
|
14
|
+
}
|
|
15
|
+
else if (ut2.isArray(data)) {
|
|
16
|
+
var result_2 = [];
|
|
17
|
+
ut2.forEach(data, function (value, index) {
|
|
18
|
+
var newValue = deep && (ut2.isPlainObject(value) || ut2.isArray(value)) ? transformObjectValue(value, fn) : fn(value, index);
|
|
19
|
+
result_2.push(newValue);
|
|
20
|
+
});
|
|
21
|
+
return result_2;
|
|
22
|
+
}
|
|
23
|
+
return data;
|
|
24
|
+
};
|
|
25
|
+
var transformObjectValue$1 = transformObjectValue;
|
|
26
|
+
|
|
27
|
+
module.exports = transformObjectValue$1;
|
package/lib/validatePassword.js
CHANGED
|
@@ -2,19 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var devWarn = require('./utils/devWarn.js');
|
|
4
4
|
|
|
5
|
-
var regNumber =
|
|
5
|
+
var regNumber = /\d/;
|
|
6
6
|
var regLowerCaseLetter = /[a-z]/;
|
|
7
7
|
var regUpperCaseLetter = /[A-Z]/;
|
|
8
8
|
var regAllNumberAndLetter = /[\d|a-z]/gi;
|
|
9
|
-
function hasNumber(val) {
|
|
10
|
-
return regNumber.test(val);
|
|
11
|
-
}
|
|
12
|
-
function hasLowerCaseLetter(val) {
|
|
13
|
-
return regLowerCaseLetter.test(val);
|
|
14
|
-
}
|
|
15
|
-
function hasUpperCaseLetter(val) {
|
|
16
|
-
return regUpperCaseLetter.test(val);
|
|
17
|
-
}
|
|
18
9
|
function hasHex(val) {
|
|
19
10
|
return val.indexOf('\\x') > -1 || val.indexOf('\\u') > -1;
|
|
20
11
|
}
|
|
@@ -72,9 +63,9 @@ function validatePassword(value, options) {
|
|
|
72
63
|
valStr = '';
|
|
73
64
|
}
|
|
74
65
|
var currentLevel = 0;
|
|
75
|
-
var containesNumber =
|
|
76
|
-
var containesLowerCaseLetter =
|
|
77
|
-
var containesUpperCaseLetter =
|
|
66
|
+
var containesNumber = regNumber.test(valStr);
|
|
67
|
+
var containesLowerCaseLetter = regLowerCaseLetter.test(valStr);
|
|
68
|
+
var containesUpperCaseLetter = regUpperCaseLetter.test(valStr);
|
|
78
69
|
var containesSpecialCharacter = hasSpecialCharacter(valStr, special);
|
|
79
70
|
var containesUnallowableCharacter = hasUnallowableCharacter(valStr, special);
|
|
80
71
|
if (containesNumber) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.23.1",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -51,20 +51,20 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://doly-dev.github.io/util-helpers/index.html",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/core": "^7.24.
|
|
55
|
-
"@babel/preset-env": "^7.24.
|
|
56
|
-
"@babel/preset-typescript": "^7.24.
|
|
54
|
+
"@babel/core": "^7.24.7",
|
|
55
|
+
"@babel/preset-env": "^7.24.7",
|
|
56
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
57
57
|
"@commitlint/cli": "^17.8.1",
|
|
58
58
|
"@commitlint/config-conventional": "^17.8.1",
|
|
59
59
|
"@commitlint/cz-commitlint": "^17.8.1",
|
|
60
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
60
|
+
"@rollup/plugin-commonjs": "^25.0.8",
|
|
61
61
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
62
|
-
"@rollup/plugin-replace": "^5.0.
|
|
62
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
63
63
|
"@rollup/plugin-terser": "^0.4.4",
|
|
64
64
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
65
65
|
"@types/jest": "^29.5.12",
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
67
|
-
"@typescript-eslint/parser": "^7.
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
|
67
|
+
"@typescript-eslint/parser": "^7.13.0",
|
|
68
68
|
"babel-jest": "^29.7.0",
|
|
69
69
|
"babel-plugin-minify-replace": "^0.5.0",
|
|
70
70
|
"commitizen": "^4.3.0",
|
|
@@ -78,8 +78,8 @@
|
|
|
78
78
|
"jest-environment-jsdom": "^29.7.0",
|
|
79
79
|
"jsdoc": "^4.0.3",
|
|
80
80
|
"lint-staged": "^13.3.0",
|
|
81
|
-
"prettier": "^3.2
|
|
82
|
-
"rollup": "^4.
|
|
81
|
+
"prettier": "^3.3.2",
|
|
82
|
+
"rollup": "^4.18.0",
|
|
83
83
|
"typescript": "^5.4.5"
|
|
84
84
|
},
|
|
85
85
|
"lint-staged": {
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"dependencies": {
|
|
95
95
|
"cache2": "^2.0.5",
|
|
96
96
|
"emitter-pro": "^1.2.1",
|
|
97
|
-
"tslib": "^2.6.
|
|
97
|
+
"tslib": "^2.6.3",
|
|
98
98
|
"ut2": "^1.9.1"
|
|
99
99
|
},
|
|
100
100
|
"publishConfig": {
|
package/types/AsyncMemo.d.ts
CHANGED
|
@@ -2,11 +2,25 @@ import { Cache, CacheOptions } from 'cache2';
|
|
|
2
2
|
/**
|
|
3
3
|
* 异步缓存
|
|
4
4
|
*
|
|
5
|
+
* 特点:
|
|
6
|
+
* 1. 共享异步。同一个缓存键的异步,最多同时运行一个异步,异步结果共享。
|
|
7
|
+
* 2. 持久化数据。存在缓存结果,不再执行异步方法,直接返回该结果。
|
|
8
|
+
* 3. 每个实例都有独立的缓存空间。相互之间隔离,缓存灵活配置,更多配置请查阅 [`cache2`](https://www.npmjs.com/package/cache2)。
|
|
9
|
+
*
|
|
5
10
|
* @class
|
|
6
|
-
* @see {@link https://www.npmjs.com/package/cache2
|
|
11
|
+
* @see {@link https://www.npmjs.com/package/cache2 cache2}
|
|
7
12
|
* @param {Object} [options] 缓存配置项,更多配置项可参考 [`cache2`](https://www.npmjs.com/package/cache2)
|
|
8
13
|
* @param {number} [options.max] 最大缓存数量
|
|
9
14
|
* @param {'replaced' | 'limited'} [options.maxStrategy] 缓存策略
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* const asyncMemo = new AsyncMemo({ max: 20, maxStrategy: 'replaced' });
|
|
18
|
+
* asyncMemo.run(()=>download({ fssid: 'a' }), 'a');
|
|
19
|
+
* asyncMemo.run(()=>download({ fssid: 'b' }), 'b');
|
|
20
|
+
* asyncMemo.run(()=>download({ fssid: 'a' }), 'a'); // 如果有缓存结果直接返回,如果有异步执行中,不会重复触发异步,但共享异步结果。
|
|
21
|
+
*
|
|
22
|
+
* asyncMemo.run(()=>download({ fssid: 'a' }), 'a', { persisted: false }); // 不读取缓存结果,但是异步执行结果还是会缓存。
|
|
23
|
+
* asyncMemo.run(()=>download({ fssid: 'a' })); // 没有缓存键时,直接执行异步方法,不读取缓存结果,也不会缓存异步结果。
|
|
10
24
|
*/
|
|
11
25
|
declare class AsyncMemo<DataType = any> {
|
|
12
26
|
private promiseCache;
|
|
@@ -28,6 +42,6 @@ declare class AsyncMemo<DataType = any> {
|
|
|
28
42
|
run(asyncFn: (...args: any[]) => Promise<DataType>, key?: string, options?: {
|
|
29
43
|
ttl?: number;
|
|
30
44
|
persisted?: boolean;
|
|
31
|
-
}): Promise<
|
|
45
|
+
}): Promise<DataType>;
|
|
32
46
|
}
|
|
33
47
|
export default AsyncMemo;
|
package/types/ajax.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ type AjaxOptions = {
|
|
|
19
19
|
onLoadEnd?: XMLHttpRequestListener;
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest
|
|
22
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest XMLHttpRequest}
|
|
23
23
|
* @typedef {Object} AjaxOptions ajax 配置项
|
|
24
24
|
* @property {string} [method="get"] 创建请求时使用的方法
|
|
25
25
|
* @property {boolean} [async=true] 是否异步执行操作
|
|
@@ -47,7 +47,7 @@ type AjaxOptions = {
|
|
|
47
47
|
* @static
|
|
48
48
|
* @alias module:Other.ajax
|
|
49
49
|
* @since 4.16.0
|
|
50
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest
|
|
50
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/XMLHttpRequest XMLHttpRequest}
|
|
51
51
|
* @param {string} url 地址
|
|
52
52
|
* @param {AjaxOptions} [options] 配置项
|
|
53
53
|
* @returns {Promise<object>} XHR 事件对象
|
package/types/blobToDataURL.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @static
|
|
8
8
|
* @alias module:Processor.blobToDataURL
|
|
9
9
|
* @since 4.1.0
|
|
10
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL
|
|
10
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL FileReader.readAsDataURL()}
|
|
11
11
|
* @deprecated 请使用 `fileReader` 方法
|
|
12
12
|
* @param {Blob} blob Blob 或 File 对象
|
|
13
13
|
* @returns {Promise<string>} data:URL 格式的 Base64 字符串。
|
|
@@ -9,8 +9,8 @@ type CalculateCursorPositionOptions = {
|
|
|
9
9
|
* @static
|
|
10
10
|
* @alias module:Other.calculateCursorPosition
|
|
11
11
|
* @since 4.6.0
|
|
12
|
-
* @see {@link https://2950v9.csb.app/
|
|
13
|
-
* @see {@link https://33ccy9.csb.app/
|
|
12
|
+
* @see {@link https://2950v9.csb.app/ h5示例}
|
|
13
|
+
* @see {@link https://33ccy9.csb.app/ react示例}
|
|
14
14
|
* @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
|
|
15
15
|
* @param {string} prevCtrlValue 上一个格式化后的值
|
|
16
16
|
* @param {string} rawValue 当前输入原值
|
package/types/compressImage.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ interface CompressImage {
|
|
|
38
38
|
* @function
|
|
39
39
|
* @alias module:Other.compressImage
|
|
40
40
|
* @since 4.20.0
|
|
41
|
-
* @see {@link https://sytpwg.csb.app/
|
|
41
|
+
* @see {@link https://sytpwg.csb.app/ 在线示例}
|
|
42
42
|
* @param {string | Blob} img 图片地址或 blob 对象
|
|
43
43
|
* @param {Object} [options] 配置项
|
|
44
44
|
* @param {number} [options.width] 自定义图片宽度,默认图片自身宽度
|
package/types/dataURLToBlob.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @static
|
|
5
5
|
* @alias module:Processor.dataURLToBlob
|
|
6
6
|
* @since 4.1.0
|
|
7
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64
|
|
7
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 Base64}
|
|
8
8
|
* @param {string} data data: 协议的URL
|
|
9
9
|
* @returns {Blob} Blob 对象
|
|
10
10
|
* @example
|
package/types/download.d.ts
CHANGED
|
@@ -38,9 +38,9 @@ type DownloadOptions = {
|
|
|
38
38
|
* @static
|
|
39
39
|
* @alias module:Other.download
|
|
40
40
|
* @since 4.16.0
|
|
41
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
|
|
42
|
-
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展
|
|
43
|
-
* @see {@link https://9ykc9s.csb.app/
|
|
41
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers Access-Control-Expose-Headers}
|
|
42
|
+
* @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 MIME}
|
|
43
|
+
* @see {@link https://9ykc9s.csb.app/ 在线示例}
|
|
44
44
|
* @param {string|Blob|ArrayBuffer|TypedArray} data 字符串、blob数据或url地址
|
|
45
45
|
* @param {string|DownloadOptions} [options] 文件名称 或 配置项
|
|
46
46
|
* @returns {Promise<void>}
|
package/types/fileReader.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ interface FileReader {
|
|
|
16
16
|
*
|
|
17
17
|
* @function
|
|
18
18
|
* @alias module:Processor.fileReader
|
|
19
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader
|
|
19
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader FileReader}
|
|
20
20
|
* @since 4.16.0
|
|
21
21
|
* @param {Blob} blob Blob 或 File 对象
|
|
22
22
|
* @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型
|
package/types/gcd.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @static
|
|
13
13
|
* @alias module:Math.gcd
|
|
14
14
|
* @since 4.20.0
|
|
15
|
-
* @see {@link https://baike.baidu.com/item/最大公约数
|
|
15
|
+
* @see {@link https://baike.baidu.com/item/最大公约数 最大公约数}
|
|
16
16
|
* @param {...(number|string)} nums 两个或多个整数。
|
|
17
17
|
* @returns {number} 最大公约数。
|
|
18
18
|
* @example
|
package/types/getImageInfo.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import loadImageWithBlob from './loadImageWithBlob';
|
|
2
|
+
type Result = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
contrast: string;
|
|
6
|
+
measure: string;
|
|
7
|
+
size: string;
|
|
8
|
+
bytes: number;
|
|
9
|
+
image: HTMLImageElement;
|
|
10
|
+
blob: Blob;
|
|
11
|
+
};
|
|
2
12
|
/**
|
|
3
13
|
* @typedef {Object} ImageInfo 图片信息
|
|
4
14
|
* @property {number} width 宽度
|
|
@@ -37,14 +47,5 @@ import loadImageWithBlob from './loadImageWithBlob';
|
|
|
37
47
|
* });
|
|
38
48
|
*
|
|
39
49
|
*/
|
|
40
|
-
declare function getImageInfo(img: string | Blob, cacheOptions?: boolean | Parameters<typeof loadImageWithBlob>[1], ajaxOptions?: Parameters<typeof loadImageWithBlob>[2]): Promise<
|
|
41
|
-
width: number;
|
|
42
|
-
height: number;
|
|
43
|
-
contrast: string;
|
|
44
|
-
measure: string;
|
|
45
|
-
size: string;
|
|
46
|
-
bytes: number;
|
|
47
|
-
image: HTMLImageElement;
|
|
48
|
-
blob: Blob;
|
|
49
|
-
}>;
|
|
50
|
+
declare function getImageInfo(img: string | Blob, cacheOptions?: boolean | Parameters<typeof loadImageWithBlob>[1], ajaxOptions?: Parameters<typeof loadImageWithBlob>[2]): Promise<Result>;
|
|
50
51
|
export default getImageInfo;
|
package/types/index.d.ts
CHANGED
|
@@ -47,13 +47,14 @@ export { default as normalizeString } from './normalizeString';
|
|
|
47
47
|
export { default as safeDate } from './safeDate';
|
|
48
48
|
export { default as formatMobile } from './formatMobile';
|
|
49
49
|
export { default as padZero } from './padZero';
|
|
50
|
+
export { default as transformObjectValue } from './transformObjectValue';
|
|
50
51
|
/**
|
|
51
52
|
* 数学计算,修正浮点数计算问题
|
|
52
53
|
*
|
|
53
54
|
* @module Math
|
|
54
55
|
* @since 3.1.0
|
|
55
|
-
* @see {@link https://github.com/camsong/blog/issues/9
|
|
56
|
-
* @see {@link https://2zbuy.csb.app/
|
|
56
|
+
* @see {@link https://github.com/camsong/blog/issues/9 JavaScript 浮点数陷阱及解法}
|
|
57
|
+
* @see {@link https://2zbuy.csb.app/ JS浮点数计算测试}
|
|
57
58
|
* @example
|
|
58
59
|
* // 从 4.12.0 版本开始,规范了有效数值。(注意:4.12.3 对有效数值重新定义)
|
|
59
60
|
* // 有效数值即能通过 Number(value) 转为数字,且不能为 NaN 。
|
package/types/isBankCard.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ type Options = {
|
|
|
8
8
|
* @static
|
|
9
9
|
* @alias module:Validator.isBankCard
|
|
10
10
|
* @since 1.1.0
|
|
11
|
-
* @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html
|
|
11
|
+
* @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html 常用银行账号位数参考}
|
|
12
12
|
* @param {*} value 要检测的值
|
|
13
13
|
* @param {Object} [options] 配置项
|
|
14
14
|
* @param {boolean} [options.loose=false] 宽松模式,8-30位数字
|
|
@@ -9,7 +9,7 @@ type Options = {
|
|
|
9
9
|
* @static
|
|
10
10
|
* @alias module:Validator.isBusinessLicense
|
|
11
11
|
* @since 3.5.0
|
|
12
|
-
* @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html
|
|
12
|
+
* @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html GS15—2006 工商行政管理市场主体注册号编制规则}
|
|
13
13
|
* @param {*} value 要检测的值
|
|
14
14
|
* @param {Object} [options] 配置项
|
|
15
15
|
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
package/types/isChinese.d.ts
CHANGED
|
@@ -8,9 +8,9 @@ type Options = {
|
|
|
8
8
|
* @static
|
|
9
9
|
* @alias module:Validator.isChinese
|
|
10
10
|
* @since 1.1.0
|
|
11
|
-
* @see {@link http://www.unicode.org/reports/tr38/#BlockListing
|
|
12
|
-
* @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射
|
|
13
|
-
* @see {@link https://zh.wikipedia.org/wiki/Unicode區段
|
|
11
|
+
* @see {@link http://www.unicode.org/reports/tr38/#BlockListing 4.4 Listing of Characters Covered by the Unihan Database}
|
|
12
|
+
* @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射 Unicode字符平面映射}
|
|
13
|
+
* @see {@link https://zh.wikipedia.org/wiki/Unicode區段 Unicode区段}
|
|
14
14
|
* @param {*} value 要检测的值
|
|
15
15
|
* @param {Object} [options] 配置项
|
|
16
16
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
|
package/types/isHMCard.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @static
|
|
5
5
|
* @alias module:Validator.isHMCard
|
|
6
6
|
* @since 4.0.0
|
|
7
|
-
* @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证
|
|
7
|
+
* @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证 港澳居民来往内地通行证}
|
|
8
8
|
* @param {*} value 要检测的值
|
|
9
9
|
* @returns {boolean} 是否为港澳居民来往内地通行证
|
|
10
10
|
* @example
|
package/types/isIdCard.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ type Options = {
|
|
|
10
10
|
* @static
|
|
11
11
|
* @alias module:Validator.isIdCard
|
|
12
12
|
* @since 1.1.0
|
|
13
|
-
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码
|
|
14
|
-
* @see {@link https://baike.baidu.com/item/居民身份证号码
|
|
13
|
+
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码 中华人民共和国公民身份号码}
|
|
14
|
+
* @see {@link https://baike.baidu.com/item/居民身份证号码 居民身份证号码}
|
|
15
15
|
* @param {*} value 要检测的值
|
|
16
16
|
* @param {Object} [options] 配置项
|
|
17
17
|
* @param {boolean} [options.loose=false] 宽松模式,支持15位身份证号码
|
package/types/isPassport.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @static
|
|
6
6
|
* @alias module:Validator.isPassport
|
|
7
7
|
* @since 1.1.0
|
|
8
|
-
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页
|
|
8
|
+
* @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页 中华人民共和国护照#个人资料页}
|
|
9
9
|
* @param {*} value 要检测的值
|
|
10
10
|
* @returns {boolean} 值是否为护照号
|
|
11
11
|
* @example
|
package/types/isPassword.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import validatePassword from './validatePassword';
|
|
|
8
8
|
* @alias module:Validator.isPassword
|
|
9
9
|
* @requires module:Validator.validatePassword
|
|
10
10
|
* @since 1.1.0
|
|
11
|
-
* @see {@link https://baike.baidu.com/item/ASCII#3
|
|
11
|
+
* @see {@link https://baike.baidu.com/item/ASCII#3 ASCII}
|
|
12
12
|
* @param {*} value 要检测的值
|
|
13
13
|
* @param {Object} [options] 配置项
|
|
14
14
|
* @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
|
|
@@ -9,7 +9,7 @@ type Options = {
|
|
|
9
9
|
* @static
|
|
10
10
|
* @alias module:Validator.isSocialCreditCode
|
|
11
11
|
* @since 1.1.0
|
|
12
|
-
* @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则
|
|
12
|
+
* @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则 GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
|
|
13
13
|
* @param {*} value 要检测的值
|
|
14
14
|
* @param {Object} [options] 配置项
|
|
15
15
|
* @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
|
package/types/isSwiftCode.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @static
|
|
5
5
|
* @alias module:Validator.isSwiftCode
|
|
6
6
|
* @since 4.9.0
|
|
7
|
-
* @see {@link https://zh.wikipedia.org/wiki/ISO_9362
|
|
7
|
+
* @see {@link https://zh.wikipedia.org/wiki/ISO_9362 ISO 9362}
|
|
8
8
|
* @param {*} value 要检测的值
|
|
9
9
|
* @returns {boolean} 值是否为 Swift Code
|
|
10
10
|
* @example
|
package/types/isTWCard.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type Options = {
|
|
|
7
7
|
* @static
|
|
8
8
|
* @alias module:Validator.isTWCard
|
|
9
9
|
* @since 4.0.0
|
|
10
|
-
* @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证
|
|
10
|
+
* @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证 台湾居民来往大陆通行证}
|
|
11
11
|
* @param {*} value 要检测的值
|
|
12
12
|
* @param {Object} [options] 配置项
|
|
13
13
|
* @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
|
package/types/isUrl.d.ts
CHANGED
package/types/isVehicle.d.ts
CHANGED
package/types/lcm.d.ts
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* @static
|
|
15
15
|
* @alias module:Math.lcm
|
|
16
16
|
* @since 4.20.0
|
|
17
|
-
* @see {@link https://baike.baidu.com/item/最小公倍数
|
|
17
|
+
* @see {@link https://baike.baidu.com/item/最小公倍数 最小公倍数}
|
|
18
18
|
* @param {...(number|string)} nums 两个或多个整数。
|
|
19
19
|
* @returns {number} 最小公倍数。
|
|
20
20
|
* @example
|
package/types/loadImage.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @typedef {Object} CacheOptions 缓存配置
|
|
3
3
|
* @property {boolean} [useCache=true] 是否使用缓存
|
|
4
4
|
* @property {boolean} [autoRevokeOnDel=true] 删除时自动释放缓存
|
|
5
|
+
* @property {string} [cacheKey] 缓存键
|
|
5
6
|
*/
|
|
6
7
|
/**
|
|
7
8
|
* 加载图片。
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
*/
|
|
32
33
|
declare function loadImage(img: string | Blob, cacheOptions?: boolean | {
|
|
33
34
|
useCache?: boolean;
|
|
35
|
+
cacheKey?: string;
|
|
34
36
|
autoRevokeOnDel?: boolean;
|
|
35
37
|
}): Promise<HTMLImageElement>;
|
|
36
38
|
export default loadImage;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import getFileBlob from './getFileBlob';
|
|
2
|
+
type Result = {
|
|
3
|
+
image: HTMLImageElement;
|
|
4
|
+
blob: Blob;
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* @typedef {Object} ImageWithBlob HTML图片元素和 blob 对象
|
|
4
8
|
* @property {HTMLImageElement} image HTML图片元素
|
|
@@ -33,9 +37,7 @@ import getFileBlob from './getFileBlob';
|
|
|
33
37
|
*/
|
|
34
38
|
declare function loadImageWithBlob(img: string | Blob, cacheOptions?: boolean | {
|
|
35
39
|
useCache?: boolean;
|
|
40
|
+
cacheKey?: string;
|
|
36
41
|
autoRevokeOnDel?: boolean;
|
|
37
|
-
}, ajaxOptions?: Parameters<typeof getFileBlob>[1]): Promise<
|
|
38
|
-
image: HTMLImageElement;
|
|
39
|
-
blob: Blob;
|
|
40
|
-
}>;
|
|
42
|
+
}, ajaxOptions?: Parameters<typeof getFileBlob>[1]): Promise<Result>;
|
|
41
43
|
export default loadImageWithBlob;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @static
|
|
6
6
|
* @alias module:Processor.normalizeString
|
|
7
7
|
* @since 4.3.0
|
|
8
|
-
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances
|
|
8
|
+
* @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances String}
|
|
9
9
|
* @deprecated 即将废弃,请使用 `import { toString } 'ut2'`
|
|
10
10
|
* @param {*} value 待处理的值
|
|
11
11
|
* @returns {string} 规整化的值
|
|
@@ -17,7 +17,7 @@ type Options = {
|
|
|
17
17
|
* @static
|
|
18
18
|
* @alias module:Processor.numberToChinese
|
|
19
19
|
* @since 1.2.0
|
|
20
|
-
* @see {@link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=F5DAC3377DA99C8D78AE66735B6359C7
|
|
20
|
+
* @see {@link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=F5DAC3377DA99C8D78AE66735B6359C7 出版物上数字用法}
|
|
21
21
|
* @param {number} num 数字
|
|
22
22
|
* @param {Object} [options] 配置项
|
|
23
23
|
* @param {boolean} [options.big5=false] 繁体
|
package/types/parseIdCard.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ type IdCardInfo = {
|
|
|
36
36
|
* @static
|
|
37
37
|
* @alias module:Processor.parseIdCard
|
|
38
38
|
* @since 4.0.0
|
|
39
|
-
* @see {@link https://baike.baidu.com/item/居民身份证号码
|
|
39
|
+
* @see {@link https://baike.baidu.com/item/居民身份证号码 居民身份证号码}
|
|
40
40
|
* @param {string} id 身份证号码,支持15位
|
|
41
41
|
* @returns {IdCardInfo | null} 省份、生日、性别,省/市/区/年/月/日/性别编码。如果解析失败将返回 null 。
|
|
42
42
|
* @example
|