util-helpers 4.21.0 → 4.21.2
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 +275 -43
- 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 +12 -2
- package/esm/getImageInfo.js +25 -9
- package/esm/index.js +1 -1
- package/esm/loadImage.js +25 -13
- package/esm/loadImageWithBlob.js +25 -11
- package/esm/node_modules/.pnpm/emitter-pro@1.0.3/node_modules/emitter-pro/dist/emitter-pro.esm.js +72 -0
- package/esm/utils/Cache.js +47 -0
- package/lib/VERSION.js +1 -1
- package/lib/compressImage.js +12 -2
- package/lib/getImageInfo.js +25 -9
- package/lib/index.js +1 -1
- package/lib/loadImage.js +24 -12
- package/lib/loadImageWithBlob.js +24 -10
- package/lib/node_modules/.pnpm/emitter-pro@1.0.3/node_modules/emitter-pro/dist/emitter-pro.esm.js +74 -0
- package/lib/utils/Cache.js +49 -0
- package/package.json +17 -13
- package/types/compressImage.d.ts +1 -1
- package/types/getImageInfo.d.ts +13 -2
- package/types/loadImage.d.ts +10 -2
- package/types/loadImageWithBlob.d.ts +5 -2
- package/types/utils/Cache.d.ts +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "4.21.
|
|
3
|
+
"version": "4.21.2",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -51,17 +51,17 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://doly-dev.github.io/util-helpers/index.html",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@babel/core": "^7.23.
|
|
55
|
-
"@babel/preset-env": "^7.
|
|
56
|
-
"@babel/preset-typescript": "^7.23.
|
|
57
|
-
"@commitlint/cli": "^17.
|
|
58
|
-
"@commitlint/config-conventional": "^17.
|
|
59
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
54
|
+
"@babel/core": "^7.23.9",
|
|
55
|
+
"@babel/preset-env": "^7.23.9",
|
|
56
|
+
"@babel/preset-typescript": "^7.23.3",
|
|
57
|
+
"@commitlint/cli": "^17.8.1",
|
|
58
|
+
"@commitlint/config-conventional": "^17.8.1",
|
|
59
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
60
60
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
61
|
-
"@rollup/plugin-replace": "^5.0.
|
|
61
|
+
"@rollup/plugin-replace": "^5.0.5",
|
|
62
62
|
"@rollup/plugin-terser": "^0.4.4",
|
|
63
|
-
"@rollup/plugin-typescript": "^11.1.
|
|
64
|
-
"@types/jest": "^29.5.
|
|
63
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
64
|
+
"@types/jest": "^29.5.12",
|
|
65
65
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
66
66
|
"@typescript-eslint/parser": "^5.62.0",
|
|
67
67
|
"babel-jest": "^29.7.0",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"cross-env": "^7.0.3",
|
|
70
70
|
"cz-conventional-changelog": "^3.3.0",
|
|
71
71
|
"docdash": "^2.0.2",
|
|
72
|
-
"eslint": "^8.
|
|
72
|
+
"eslint": "^8.56.0",
|
|
73
73
|
"husky": "^8.0.3",
|
|
74
74
|
"jest": "^29.7.0",
|
|
75
75
|
"jest-canvas-mock": "^2.5.2",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"lint-staged": "^13.3.0",
|
|
79
79
|
"prettier": "^2.8.8",
|
|
80
80
|
"rollup": "^3.29.4",
|
|
81
|
-
"typescript": "^5.
|
|
81
|
+
"typescript": "^5.3.3"
|
|
82
82
|
},
|
|
83
83
|
"lint-staged": {
|
|
84
84
|
"**/*.ts": "eslint",
|
|
@@ -90,7 +90,11 @@
|
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
|
+
"emitter-pro": "^1.0.3",
|
|
93
94
|
"tslib": "^2.6.2",
|
|
94
|
-
"ut2": "^1.
|
|
95
|
+
"ut2": "^1.7.1"
|
|
96
|
+
},
|
|
97
|
+
"publishConfig": {
|
|
98
|
+
"registry": "https://registry.npmjs.org/"
|
|
95
99
|
}
|
|
96
100
|
}
|
package/types/compressImage.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ type Options = {
|
|
|
19
19
|
beforeCompress?: (imageWithBlob: Pick<Info, 'image' | 'blob'>, options: Options) => void;
|
|
20
20
|
beforeDraw?: (info: Info, options: Options) => void;
|
|
21
21
|
afterDraw?: (info: Info, options: Options) => void;
|
|
22
|
-
cacheImage?: boolean;
|
|
22
|
+
cacheImage?: boolean | Parameters<typeof loadImageWithBlob>[1];
|
|
23
23
|
ajaxOptions?: Parameters<typeof loadImageWithBlob>[2];
|
|
24
24
|
};
|
|
25
25
|
declare function compressImage(img: string | Blob, options: Omit<Options, 'format'> & {
|
package/types/getImageInfo.d.ts
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import loadImageWithBlob from './loadImageWithBlob';
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Object} ImageInfo 图片信息
|
|
4
|
+
* @property {number} width 宽度
|
|
5
|
+
* @property {number} height 高度
|
|
6
|
+
* @property {string} contrast 宽高比
|
|
7
|
+
* @property {string} measure 尺寸
|
|
8
|
+
* @property {string} size 大小
|
|
9
|
+
* @property {number} bytes 大小,单位字节
|
|
10
|
+
* @property {HTMLImageElement} image HTML图片元素
|
|
11
|
+
* @property {Blob} blob 图片 Blob 对象
|
|
12
|
+
*/
|
|
2
13
|
/**
|
|
3
14
|
* 获取图片信息。
|
|
4
15
|
*
|
|
@@ -8,7 +19,7 @@ import loadImageWithBlob from './loadImageWithBlob';
|
|
|
8
19
|
* @alias module:Other.getImageInfo
|
|
9
20
|
* @since 4.20.0
|
|
10
21
|
* @param {string | Blob} img 图片地址或 blob 对象
|
|
11
|
-
* @param {boolean} [
|
|
22
|
+
* @param {boolean | CacheOptions} [cacheOptions=true] 是否使用缓存。开启后,自动缓存最近上一次成功的结果,当图片地址或 blob 对象一致时,直接返回该缓存。避免连续请求同一个图片资源,重复加载。当缓存下一次成功加载的图片时,会自动释放上一次缓存的图片,也可以通过 `autoRevokeOnDel` 设置不释放缓存。
|
|
12
23
|
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
|
13
24
|
* @returns {Promise<ImageInfo>} 图片信息
|
|
14
25
|
* @example
|
|
@@ -26,7 +37,7 @@ import loadImageWithBlob from './loadImageWithBlob';
|
|
|
26
37
|
* });
|
|
27
38
|
*
|
|
28
39
|
*/
|
|
29
|
-
declare function getImageInfo(img: string | Blob,
|
|
40
|
+
declare function getImageInfo(img: string | Blob, cacheOptions?: boolean | Parameters<typeof loadImageWithBlob>[1], ajaxOptions?: Parameters<typeof loadImageWithBlob>[2]): Promise<{
|
|
30
41
|
width: number;
|
|
31
42
|
height: number;
|
|
32
43
|
contrast: string;
|
package/types/loadImage.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} CacheOptions 缓存配置
|
|
3
|
+
* @property {boolean} [useCache=true] 是否使用缓存
|
|
4
|
+
* @property {boolean} [autoRevokeOnDel=true] 删除时自动释放缓存
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* 加载图片。
|
|
3
8
|
*
|
|
@@ -7,7 +12,7 @@
|
|
|
7
12
|
* @alias module:Other.loadImage
|
|
8
13
|
* @since 4.20.0
|
|
9
14
|
* @param {string | Blob} img 图片地址或 blob 对象
|
|
10
|
-
* @param {boolean} [
|
|
15
|
+
* @param {boolean | CacheOptions} [cacheOptions=true] 是否使用缓存。开启后,自动缓存最近上一次成功的结果,当图片地址或 blob 对象一致时,直接返回该缓存。避免连续请求同一个图片资源,重复加载。当缓存下一次成功加载的图片时,会自动释放上一次缓存的图片,也可以通过 `autoRevokeOnDel` 设置不释放缓存。
|
|
11
16
|
* @returns {Promise<HTMLImageElement>} HTML图片元素
|
|
12
17
|
* @example
|
|
13
18
|
*
|
|
@@ -24,5 +29,8 @@
|
|
|
24
29
|
* });
|
|
25
30
|
*
|
|
26
31
|
*/
|
|
27
|
-
declare function loadImage(img: string | Blob,
|
|
32
|
+
declare function loadImage(img: string | Blob, cacheOptions?: boolean | {
|
|
33
|
+
useCache?: boolean;
|
|
34
|
+
autoRevokeOnDel?: boolean;
|
|
35
|
+
}): Promise<HTMLImageElement>;
|
|
28
36
|
export default loadImage;
|
|
@@ -13,7 +13,7 @@ import getFileBlob from './getFileBlob';
|
|
|
13
13
|
* @alias module:Other.loadImageWithBlob
|
|
14
14
|
* @since 4.20.0
|
|
15
15
|
* @param {string | Blob} img 图片地址或 blob 对象
|
|
16
|
-
* @param {boolean} [
|
|
16
|
+
* @param {boolean | CacheOptions} [cacheOptions=true] 是否使用缓存。开启后,自动缓存最近上一次成功的结果,当图片地址或 blob 对象一致时,直接返回该缓存。避免连续请求同一个图片资源,重复加载。当缓存下一次成功加载的图片时,会自动释放上一次缓存的图片,也可以通过 `autoRevokeOnDel` 设置不释放缓存。
|
|
17
17
|
* @param {AjaxOptions} [ajaxOptions] ajax 请求配置项,当传入的图片为字符串时才会触发请求。
|
|
18
18
|
* @returns {Promise<ImageWithBlob>} HTML图片元素和 blob 对象
|
|
19
19
|
* @example
|
|
@@ -31,7 +31,10 @@ import getFileBlob from './getFileBlob';
|
|
|
31
31
|
* });
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
|
-
declare function loadImageWithBlob(img: string | Blob,
|
|
34
|
+
declare function loadImageWithBlob(img: string | Blob, cacheOptions?: boolean | {
|
|
35
|
+
useCache?: boolean;
|
|
36
|
+
autoRevokeOnDel?: boolean;
|
|
37
|
+
}, ajaxOptions?: Parameters<typeof getFileBlob>[1]): Promise<{
|
|
35
38
|
image: HTMLImageElement;
|
|
36
39
|
blob: Blob;
|
|
37
40
|
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Emitter from 'emitter-pro';
|
|
2
|
+
type Options = {
|
|
3
|
+
max: number;
|
|
4
|
+
};
|
|
5
|
+
declare class Cache<V = any, K = any> extends Emitter<(v: V, k: K) => void> {
|
|
6
|
+
private data;
|
|
7
|
+
private options;
|
|
8
|
+
constructor(options?: Options);
|
|
9
|
+
has(k: K): boolean;
|
|
10
|
+
get(k: K): V | undefined;
|
|
11
|
+
private checkLimit;
|
|
12
|
+
set(k: K, v: V): void;
|
|
13
|
+
}
|
|
14
|
+
export default Cache;
|