util-helpers 5.6.0 → 5.7.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/dist/util-helpers.js +14 -18
- 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/AsyncMemo.js +4 -3
- package/esm/VERSION.js +1 -1
- package/esm/ajax.js +1 -1
- package/esm/divide.js +1 -1
- package/esm/getFileType.js +1 -1
- package/lib/AsyncMemo.js +3 -2
- package/lib/VERSION.js +1 -1
- package/lib/ajax.js +1 -1
- package/lib/getFileType.js +1 -1
- package/package.json +6 -6
- package/types/AsyncMemo.d.ts +11 -5
- package/types/ajax.d.ts +21 -1
- package/types/getFileType.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/isUnifiedIdentifier.d.ts +2 -0
package/esm/AsyncMemo.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { __assign } from 'tslib';
|
|
2
2
|
import { Cache } from 'cache2';
|
|
3
|
-
import { isString
|
|
3
|
+
import { isString } from 'ut2';
|
|
4
4
|
|
|
5
5
|
var AsyncMemo = (function () {
|
|
6
|
-
function AsyncMemo(options) {
|
|
6
|
+
function AsyncMemo(options, ns) {
|
|
7
|
+
if (ns === void 0) { ns = 'uh_async_memo'; }
|
|
7
8
|
this.promiseCache = {};
|
|
8
|
-
this.cache = new Cache(
|
|
9
|
+
this.cache = new Cache(ns, options);
|
|
9
10
|
}
|
|
10
11
|
AsyncMemo.prototype.run = function (asyncFn, key, options) {
|
|
11
12
|
var _this = this;
|
package/esm/VERSION.js
CHANGED
package/esm/ajax.js
CHANGED
package/esm/divide.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNaN } from 'ut2';
|
|
2
|
-
import { transformEffectiveNumber, float2Fixed,
|
|
2
|
+
import { transformEffectiveNumber, float2Fixed, strip, digitLength, checkBoundary } from './utils/math.util.js';
|
|
3
3
|
import times from './times.js';
|
|
4
4
|
|
|
5
5
|
function divide() {
|
package/esm/getFileType.js
CHANGED
|
@@ -3,7 +3,7 @@ import checkFileType from './checkFileType.js';
|
|
|
3
3
|
import { isUploadFile } from './utils/file.util.js';
|
|
4
4
|
|
|
5
5
|
var config = {
|
|
6
|
-
image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff',
|
|
6
|
+
image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.cur,.tif,.tiff,.jfif,.pjpeg,.pjp',
|
|
7
7
|
audio: 'audio/*,.mp3,.wav,.aac,.flac',
|
|
8
8
|
video: 'video/*,.mp4,.webm,.ogg,.mov',
|
|
9
9
|
pdf: 'application/pdf,.pdf',
|
package/lib/AsyncMemo.js
CHANGED
|
@@ -5,9 +5,10 @@ var cache2 = require('cache2');
|
|
|
5
5
|
var ut2 = require('ut2');
|
|
6
6
|
|
|
7
7
|
var AsyncMemo = (function () {
|
|
8
|
-
function AsyncMemo(options) {
|
|
8
|
+
function AsyncMemo(options, ns) {
|
|
9
|
+
if (ns === void 0) { ns = 'uh_async_memo'; }
|
|
9
10
|
this.promiseCache = {};
|
|
10
|
-
this.cache = new cache2.Cache(
|
|
11
|
+
this.cache = new cache2.Cache(ns, options);
|
|
11
12
|
}
|
|
12
13
|
AsyncMemo.prototype.run = function (asyncFn, key, options) {
|
|
13
14
|
var _this = this;
|
package/lib/VERSION.js
CHANGED
package/lib/ajax.js
CHANGED
package/lib/getFileType.js
CHANGED
|
@@ -5,7 +5,7 @@ var checkFileType = require('./checkFileType.js');
|
|
|
5
5
|
var file_util = require('./utils/file.util.js');
|
|
6
6
|
|
|
7
7
|
var config = {
|
|
8
|
-
image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff',
|
|
8
|
+
image: 'image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.cur,.tif,.tiff,.jfif,.pjpeg,.pjp',
|
|
9
9
|
audio: 'audio/*,.mp3,.wav,.aac,.flac',
|
|
10
10
|
video: 'video/*,.mp4,.webm,.ogg,.mov',
|
|
11
11
|
pdf: 'application/pdf,.pdf',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.7.1",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
"jest-environment-jsdom": "^29.7.0",
|
|
72
72
|
"jsdoc": "^4.0.4",
|
|
73
73
|
"lint-staged": "^13.3.0",
|
|
74
|
-
"prettier": "^3.
|
|
75
|
-
"rollup": "^4.
|
|
76
|
-
"ts-jest": "^29.2.
|
|
77
|
-
"typescript": "^5.
|
|
74
|
+
"prettier": "^3.5.3",
|
|
75
|
+
"rollup": "^4.36.0",
|
|
76
|
+
"ts-jest": "^29.2.6",
|
|
77
|
+
"typescript": "^5.8.2"
|
|
78
78
|
},
|
|
79
79
|
"lint-staged": {
|
|
80
80
|
"**/*.ts": "eslint",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"cache2": "^3.1.2",
|
|
90
90
|
"tslib": "^2.8.1",
|
|
91
|
-
"ut2": "^1.
|
|
91
|
+
"ut2": "^1.17.0"
|
|
92
92
|
},
|
|
93
93
|
"publishConfig": {
|
|
94
94
|
"registry": "https://registry.npmjs.org/"
|
package/types/AsyncMemo.d.ts
CHANGED
|
@@ -9,18 +9,24 @@ import { Cache, CacheOptions } from 'cache2';
|
|
|
9
9
|
*
|
|
10
10
|
* @class
|
|
11
11
|
* @see {@link https://www.npmjs.com/package/cache2 cache2}
|
|
12
|
-
* @param {Object} [options] 缓存配置项,更多配置项可参考 [`cache2`](https://www.npmjs.com/package/cache2)
|
|
13
|
-
* @param {number} [options.max]
|
|
14
|
-
* @param {'replaced' | 'limited'} [options.maxStrategy]
|
|
12
|
+
* @param {Object} [options] 缓存配置项,更多配置项可参考 [`cache2`](https://www.npmjs.com/package/cache2)。
|
|
13
|
+
* @param {number} [options.max] 最大缓存数量。
|
|
14
|
+
* @param {'replaced' | 'limited'} [options.maxStrategy] 缓存策略。
|
|
15
|
+
* @param {string} [options.prefix] 缓存健前缀。
|
|
16
|
+
* @param {string} [ns='uh_async_memo'] 缓存命名空间。默认 `uh_async_memo`。
|
|
15
17
|
* @example
|
|
16
18
|
*
|
|
17
|
-
* const asyncMemo = new AsyncMemo({ max: 20, maxStrategy: 'replaced' });
|
|
19
|
+
* const asyncMemo = new AsyncMemo({ max: 20, maxStrategy: 'replaced', prefix: 'some key' });
|
|
18
20
|
* asyncMemo.run(()=>download({ fssid: 'a' }), 'a');
|
|
19
21
|
* asyncMemo.run(()=>download({ fssid: 'b' }), 'b');
|
|
20
22
|
* asyncMemo.run(()=>download({ fssid: 'a' }), 'a'); // 如果有缓存结果直接返回,如果有异步执行中,不会重复触发异步,但共享异步结果。
|
|
21
23
|
*
|
|
22
24
|
* asyncMemo.run(()=>download({ fssid: 'a' }), 'a', { persisted: false }); // 不读取缓存结果,但是异步执行结果还是会缓存。
|
|
23
25
|
* asyncMemo.run(()=>download({ fssid: 'a' })); // 没有缓存键时,直接执行异步方法,不读取缓存结果,也不会缓存异步结果。
|
|
26
|
+
*
|
|
27
|
+
* // 自定义命名空间
|
|
28
|
+
* const asyncMemo2 = new AsyncMemo({}, 'namespace');
|
|
29
|
+
*
|
|
24
30
|
*/
|
|
25
31
|
declare class AsyncMemo<DataType = any> {
|
|
26
32
|
private promiseCache;
|
|
@@ -28,7 +34,7 @@ declare class AsyncMemo<DataType = any> {
|
|
|
28
34
|
* @summary cache2 实例,用于管理缓存
|
|
29
35
|
*/
|
|
30
36
|
cache: Cache<DataType>;
|
|
31
|
-
constructor(options?: Partial<CacheOptions
|
|
37
|
+
constructor(options?: Partial<CacheOptions>, ns?: string);
|
|
32
38
|
/**
|
|
33
39
|
* 执行异步方法
|
|
34
40
|
*
|
package/types/ajax.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
type XMLHttpRequestListener = XMLHttpRequest['onloadstart'];
|
|
2
|
+
type DataType = Parameters<XMLHttpRequest['send']>[0];
|
|
2
3
|
type AjaxOptions = {
|
|
3
4
|
method?: string;
|
|
4
5
|
async?: boolean;
|
|
5
6
|
user?: string | null;
|
|
6
7
|
password?: string | null;
|
|
7
|
-
data?:
|
|
8
|
+
data?: DataType;
|
|
8
9
|
headers?: Record<string, string>;
|
|
9
10
|
responseType?: XMLHttpRequestResponseType;
|
|
10
11
|
timeout?: number;
|
|
@@ -75,6 +76,25 @@ type AjaxOptions = {
|
|
|
75
76
|
* ajax('/api', { method: 'post' }).then(res=>{
|
|
76
77
|
* // do something
|
|
77
78
|
* });
|
|
79
|
+
*
|
|
80
|
+
* // 中断请求
|
|
81
|
+
* let xhr: XMLHttpRequest | null = null;
|
|
82
|
+
* ajax('./download/test.txt', {
|
|
83
|
+
* onLoadStart(e) {
|
|
84
|
+
* console.log('onLoadStart', e);
|
|
85
|
+
* xhr = e.target;
|
|
86
|
+
* }
|
|
87
|
+
* }).finally(() => {
|
|
88
|
+
* console.log('finally');
|
|
89
|
+
* xhr = null;
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* if(ABORT_CONDITION){
|
|
93
|
+
* if(xhr){
|
|
94
|
+
* xhr.abort();
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
78
98
|
*/
|
|
79
99
|
declare function ajax(url: string, options?: AjaxOptions): Promise<ProgressEvent<EventTarget>>;
|
|
80
100
|
export default ajax;
|
package/types/getFileType.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { UploadFile } from './utils/file.util';
|
|
|
18
18
|
*
|
|
19
19
|
* | 类型 | 说明符 |
|
|
20
20
|
* |---|---|
|
|
21
|
-
* | `image` | `image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.tif,.tiff` |
|
|
21
|
+
* | `image` | `image/*,.jpeg,.jpg,.gif,.bmp,.png,.webp,.svg,.apng,.avif,.ico,.cur,.tif,.tiff,.jfif,.pjpeg,.pjp` |
|
|
22
22
|
* | `audio` | `audio/*,.mp3,.wav,.aac,.flac` |
|
|
23
23
|
* | `video` | `video/*,.mp4,.webm,.ogg,.mov` |
|
|
24
24
|
* | `pdf` | `application/pdf,.pdf` |
|
package/types/index.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export { default as transformObjectValue } from './transformObjectValue';
|
|
|
55
55
|
* // 以下为有效数值:
|
|
56
56
|
* // 1. 数字: 1, -1, 1e-2, 1.312, 0.1, Infinity
|
|
57
57
|
* // 2. 字符串: '1', '10e2', '-1', '0.1', '', ' ', ' 15', ' 15 '
|
|
58
|
-
* //
|
|
58
|
+
* // 3. 其他类型: null, new Date(), [], new Array(), true, false,...
|
|
59
59
|
*
|
|
60
60
|
* // 以下为无效数值:
|
|
61
61
|
* // 1. 字符串: '1a', '-12a', '10.2.2', '10e2.1'
|
|
@@ -4,6 +4,8 @@ type Options = {
|
|
|
4
4
|
/**
|
|
5
5
|
* 检测值是否为统一社会信用代码,也叫三证合一组织代码。由18位数字和大写字母组成,不使用I、O、Z、S、V。
|
|
6
6
|
*
|
|
7
|
+
* 之前版本的方法名为 `isSocialCreditCode` 。
|
|
8
|
+
*
|
|
7
9
|
* @alias module:Validator.isUnifiedIdentifier
|
|
8
10
|
* @since 5.6.0
|
|
9
11
|
* @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则 GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
|