util-helpers 4.23.1 → 4.23.3
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 +23 -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/VERSION.js +1 -1
- package/esm/getImageInfo.js +5 -3
- package/esm/index.js +1 -1
- package/esm/loadImage.js +5 -3
- package/esm/loadImageWithBlob.js +4 -3
- package/esm/utils/getCacheKey.js +15 -0
- package/lib/VERSION.js +1 -1
- package/lib/getImageInfo.js +4 -2
- package/lib/index.js +1 -1
- package/lib/loadImage.js +4 -2
- package/lib/loadImageWithBlob.js +4 -3
- package/lib/utils/getCacheKey.js +17 -0
- package/package.json +4 -3
- package/types/utils/getCacheKey.d.ts +2 -0
- package/types/utils/Cache.d.ts +0 -14
package/esm/VERSION.js
CHANGED
package/esm/getImageInfo.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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
6
|
import { revokeObjectURL } from './utils/native.js';
|
|
7
7
|
import AsyncMemo from './AsyncMemo.js';
|
|
8
|
+
import getCacheKey from './utils/getCacheKey.js';
|
|
8
9
|
|
|
9
10
|
var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
|
|
10
11
|
asyncMemo.cache.on('del', function (k, v) {
|
|
@@ -26,8 +27,9 @@ function getImageInfo(img, cacheOptions, ajaxOptions) {
|
|
|
26
27
|
var _cacheOptions = {
|
|
27
28
|
useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
|
|
28
29
|
autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
|
|
29
|
-
cacheKey:
|
|
30
|
+
cacheKey: cacheOptionsIsObject ? cacheOptions.cacheKey : undefined
|
|
30
31
|
};
|
|
32
|
+
var cacheKey = _cacheOptions.useCache ? getCacheKey(_cacheOptions.cacheKey || img) : undefined;
|
|
31
33
|
return asyncMemo
|
|
32
34
|
.run(function () {
|
|
33
35
|
return loadImageWithBlob(img, false, ajaxOptions).then(function (_a) {
|
|
@@ -48,7 +50,7 @@ function getImageInfo(img, cacheOptions, ajaxOptions) {
|
|
|
48
50
|
r: _cacheOptions.autoRevokeOnDel
|
|
49
51
|
};
|
|
50
52
|
});
|
|
51
|
-
},
|
|
53
|
+
}, cacheKey)
|
|
52
54
|
.then(function (res) { return res.data; });
|
|
53
55
|
}
|
|
54
56
|
|
package/esm/index.js
CHANGED
package/esm/loadImage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isBlob } from 'ut2';
|
|
2
2
|
import { revokeObjectURL, createObjectURL } from './utils/native.js';
|
|
3
3
|
import AsyncMemo from './AsyncMemo.js';
|
|
4
|
+
import getCacheKey from './utils/getCacheKey.js';
|
|
4
5
|
|
|
5
6
|
var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
|
|
6
7
|
asyncMemo.cache.on('del', function (k, v) {
|
|
@@ -18,8 +19,9 @@ function loadImage(img, cacheOptions) {
|
|
|
18
19
|
var _cacheOptions = {
|
|
19
20
|
useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
|
|
20
21
|
autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
|
|
21
|
-
cacheKey:
|
|
22
|
+
cacheKey: cacheOptionsIsObject ? cacheOptions.cacheKey : undefined
|
|
22
23
|
};
|
|
24
|
+
var cacheKey = _cacheOptions.useCache ? getCacheKey(_cacheOptions.cacheKey || img) : undefined;
|
|
23
25
|
return asyncMemo
|
|
24
26
|
.run(function () {
|
|
25
27
|
return new Promise(function (resolve, reject) {
|
|
@@ -44,7 +46,7 @@ function loadImage(img, cacheOptions) {
|
|
|
44
46
|
};
|
|
45
47
|
image.src = url;
|
|
46
48
|
});
|
|
47
|
-
},
|
|
49
|
+
}, cacheKey)
|
|
48
50
|
.then(function (res) { return res.data; });
|
|
49
51
|
}
|
|
50
52
|
|
package/esm/loadImageWithBlob.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { revokeObjectURL, createObjectURL } from './utils/native.js';
|
|
2
2
|
import getFileBlob from './getFileBlob.js';
|
|
3
3
|
import AsyncMemo from './AsyncMemo.js';
|
|
4
|
-
import
|
|
4
|
+
import getCacheKey from './utils/getCacheKey.js';
|
|
5
5
|
|
|
6
6
|
var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
|
|
7
7
|
asyncMemo.cache.on('del', function (k, v) {
|
|
@@ -19,8 +19,9 @@ function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
|
|
|
19
19
|
var _cacheOptions = {
|
|
20
20
|
useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
|
|
21
21
|
autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
|
|
22
|
-
cacheKey:
|
|
22
|
+
cacheKey: cacheOptionsIsObject ? cacheOptions.cacheKey : undefined
|
|
23
23
|
};
|
|
24
|
+
var cacheKey = _cacheOptions.useCache ? getCacheKey(_cacheOptions.cacheKey || img) : undefined;
|
|
24
25
|
return asyncMemo
|
|
25
26
|
.run(function () {
|
|
26
27
|
return new Promise(function (resolve, reject) {
|
|
@@ -44,7 +45,7 @@ function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
|
|
|
44
45
|
})
|
|
45
46
|
.catch(reject);
|
|
46
47
|
});
|
|
47
|
-
},
|
|
48
|
+
}, cacheKey)
|
|
48
49
|
.then(function (res) { return res.data; });
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { uniqueId } from 'ut2';
|
|
2
|
+
|
|
3
|
+
var wm = new WeakMap();
|
|
4
|
+
var getCacheKey = function (obj) {
|
|
5
|
+
if (typeof obj === 'string' || !obj) {
|
|
6
|
+
return obj;
|
|
7
|
+
}
|
|
8
|
+
if (!wm.has(obj)) {
|
|
9
|
+
wm.set(obj, uniqueId('__uh_cache_key__'));
|
|
10
|
+
}
|
|
11
|
+
return wm.get(obj);
|
|
12
|
+
};
|
|
13
|
+
var getCacheKey$1 = getCacheKey;
|
|
14
|
+
|
|
15
|
+
export { getCacheKey$1 as default };
|
package/lib/VERSION.js
CHANGED
package/lib/getImageInfo.js
CHANGED
|
@@ -7,6 +7,7 @@ var loadImageWithBlob = require('./loadImageWithBlob.js');
|
|
|
7
7
|
var bytesToSize = require('./bytesToSize.js');
|
|
8
8
|
var native = require('./utils/native.js');
|
|
9
9
|
var AsyncMemo = require('./AsyncMemo.js');
|
|
10
|
+
var getCacheKey = require('./utils/getCacheKey.js');
|
|
10
11
|
|
|
11
12
|
var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
|
|
12
13
|
asyncMemo.cache.on('del', function (k, v) {
|
|
@@ -28,8 +29,9 @@ function getImageInfo(img, cacheOptions, ajaxOptions) {
|
|
|
28
29
|
var _cacheOptions = {
|
|
29
30
|
useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
|
|
30
31
|
autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
|
|
31
|
-
cacheKey:
|
|
32
|
+
cacheKey: cacheOptionsIsObject ? cacheOptions.cacheKey : undefined
|
|
32
33
|
};
|
|
34
|
+
var cacheKey = _cacheOptions.useCache ? getCacheKey(_cacheOptions.cacheKey || img) : undefined;
|
|
33
35
|
return asyncMemo
|
|
34
36
|
.run(function () {
|
|
35
37
|
return loadImageWithBlob(img, false, ajaxOptions).then(function (_a) {
|
|
@@ -50,7 +52,7 @@ function getImageInfo(img, cacheOptions, ajaxOptions) {
|
|
|
50
52
|
r: _cacheOptions.autoRevokeOnDel
|
|
51
53
|
};
|
|
52
54
|
});
|
|
53
|
-
},
|
|
55
|
+
}, cacheKey)
|
|
54
56
|
.then(function (res) { return res.data; });
|
|
55
57
|
}
|
|
56
58
|
|
package/lib/index.js
CHANGED
|
@@ -68,7 +68,7 @@ var config = require('./utils/config.js');
|
|
|
68
68
|
var VERSION = require('./VERSION.js');
|
|
69
69
|
var AsyncMemo = require('./AsyncMemo.js');
|
|
70
70
|
|
|
71
|
-
exports.version = "4.23.
|
|
71
|
+
exports.version = "4.23.3";
|
|
72
72
|
|
|
73
73
|
exports.isMobile = isMobile;
|
|
74
74
|
exports.isTelephone = isTelephone;
|
package/lib/loadImage.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var ut2 = require('ut2');
|
|
4
4
|
var native = require('./utils/native.js');
|
|
5
5
|
var AsyncMemo = require('./AsyncMemo.js');
|
|
6
|
+
var getCacheKey = require('./utils/getCacheKey.js');
|
|
6
7
|
|
|
7
8
|
var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
|
|
8
9
|
asyncMemo.cache.on('del', function (k, v) {
|
|
@@ -20,8 +21,9 @@ function loadImage(img, cacheOptions) {
|
|
|
20
21
|
var _cacheOptions = {
|
|
21
22
|
useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
|
|
22
23
|
autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
|
|
23
|
-
cacheKey:
|
|
24
|
+
cacheKey: cacheOptionsIsObject ? cacheOptions.cacheKey : undefined
|
|
24
25
|
};
|
|
26
|
+
var cacheKey = _cacheOptions.useCache ? getCacheKey(_cacheOptions.cacheKey || img) : undefined;
|
|
25
27
|
return asyncMemo
|
|
26
28
|
.run(function () {
|
|
27
29
|
return new Promise(function (resolve, reject) {
|
|
@@ -46,7 +48,7 @@ function loadImage(img, cacheOptions) {
|
|
|
46
48
|
};
|
|
47
49
|
image.src = url;
|
|
48
50
|
});
|
|
49
|
-
},
|
|
51
|
+
}, cacheKey)
|
|
50
52
|
.then(function (res) { return res.data; });
|
|
51
53
|
}
|
|
52
54
|
|
package/lib/loadImageWithBlob.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var native = require('./utils/native.js');
|
|
4
4
|
var getFileBlob = require('./getFileBlob.js');
|
|
5
5
|
var AsyncMemo = require('./AsyncMemo.js');
|
|
6
|
-
var
|
|
6
|
+
var getCacheKey = require('./utils/getCacheKey.js');
|
|
7
7
|
|
|
8
8
|
var asyncMemo = new AsyncMemo({ max: 1, maxStrategy: 'replaced' });
|
|
9
9
|
asyncMemo.cache.on('del', function (k, v) {
|
|
@@ -21,8 +21,9 @@ function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
|
|
|
21
21
|
var _cacheOptions = {
|
|
22
22
|
useCache: cacheOptionsIsObject ? cacheOptions.useCache !== false : cacheOptions !== false,
|
|
23
23
|
autoRevokeOnDel: cacheOptionsIsObject ? cacheOptions.autoRevokeOnDel !== false : !!cacheOptions,
|
|
24
|
-
cacheKey:
|
|
24
|
+
cacheKey: cacheOptionsIsObject ? cacheOptions.cacheKey : undefined
|
|
25
25
|
};
|
|
26
|
+
var cacheKey = _cacheOptions.useCache ? getCacheKey(_cacheOptions.cacheKey || img) : undefined;
|
|
26
27
|
return asyncMemo
|
|
27
28
|
.run(function () {
|
|
28
29
|
return new Promise(function (resolve, reject) {
|
|
@@ -46,7 +47,7 @@ function loadImageWithBlob(img, cacheOptions, ajaxOptions) {
|
|
|
46
47
|
})
|
|
47
48
|
.catch(reject);
|
|
48
49
|
});
|
|
49
|
-
},
|
|
50
|
+
}, cacheKey)
|
|
50
51
|
.then(function (res) { return res.data; });
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ut2 = require('ut2');
|
|
4
|
+
|
|
5
|
+
var wm = new WeakMap();
|
|
6
|
+
var getCacheKey = function (obj) {
|
|
7
|
+
if (typeof obj === 'string' || !obj) {
|
|
8
|
+
return obj;
|
|
9
|
+
}
|
|
10
|
+
if (!wm.has(obj)) {
|
|
11
|
+
wm.set(obj, ut2.uniqueId('__uh_cache_key__'));
|
|
12
|
+
}
|
|
13
|
+
return wm.get(obj);
|
|
14
|
+
};
|
|
15
|
+
var getCacheKey$1 = getCacheKey;
|
|
16
|
+
|
|
17
|
+
module.exports = getCacheKey$1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "util-helpers",
|
|
3
|
-
"version": "4.23.
|
|
3
|
+
"version": "4.23.3",
|
|
4
4
|
"description": "一个基于业务场景的工具方法库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -92,12 +92,13 @@
|
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"cache2": "^
|
|
95
|
+
"cache2": "^3.0.0",
|
|
96
96
|
"emitter-pro": "^1.2.1",
|
|
97
97
|
"tslib": "^2.6.3",
|
|
98
98
|
"ut2": "^1.9.1"
|
|
99
99
|
},
|
|
100
100
|
"publishConfig": {
|
|
101
|
-
"registry": "https://registry.npmjs.org/"
|
|
101
|
+
"registry": "https://registry.npmjs.org/",
|
|
102
|
+
"tag": "latest-4"
|
|
102
103
|
}
|
|
103
104
|
}
|
package/types/utils/Cache.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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;
|