tools-min-ns 1.16.2 → 1.17.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 +10 -0
- package/esm/func/FunctionUtil.d.ts +2 -2
- package/esm/func/FunctionUtil.js +24 -33
- package/esm/storage/StorageUtil.d.ts +2 -2
- package/esm/storage/StorageUtil.js +4 -3
- package/lib/func/FunctionUtil.d.ts +2 -2
- package/lib/func/FunctionUtil.js +24 -33
- package/lib/storage/StorageUtil.d.ts +2 -2
- package/lib/storage/StorageUtil.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ declare namespace FunctionUtil {
|
|
|
34
34
|
* query()
|
|
35
35
|
* query() => 3
|
|
36
36
|
*/
|
|
37
|
-
function debounceFn<T extends
|
|
37
|
+
function debounceFn<T extends (...args: any[]) => any>(fn: T, t?: number, immediate?: boolean): T;
|
|
38
38
|
/**
|
|
39
39
|
* 函数节流
|
|
40
40
|
* @param fn 需要节流的函数
|
|
@@ -45,7 +45,7 @@ declare namespace FunctionUtil {
|
|
|
45
45
|
* query()
|
|
46
46
|
* query()
|
|
47
47
|
*/
|
|
48
|
-
function throttleFn<T extends
|
|
48
|
+
function throttleFn<T extends (...args: any[]) => any>(fn: T, t?: number): T;
|
|
49
49
|
/**
|
|
50
50
|
* 函数只能调用一次
|
|
51
51
|
* @param { Function } fn 需要被处理的函数
|
package/esm/func/FunctionUtil.js
CHANGED
|
@@ -100,32 +100,22 @@ var FunctionUtil;
|
|
|
100
100
|
immediate = true;
|
|
101
101
|
}
|
|
102
102
|
if (!BaseUtil.isFunction(fn)) throw new Error('第一个参数必须是方法');
|
|
103
|
-
var time;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
clearTimeout(time);
|
|
120
|
-
var that = this;
|
|
121
|
-
var arg = arguments;
|
|
122
|
-
time = setTimeout(function () {
|
|
123
|
-
setTimeout(time);
|
|
124
|
-
fn.apply(that, arg);
|
|
125
|
-
time = null;
|
|
126
|
-
}, t);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
103
|
+
var time = null;
|
|
104
|
+
var debounceFunction = function debounceFunction() {
|
|
105
|
+
var args = [];
|
|
106
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
107
|
+
args[_i] = arguments[_i];
|
|
108
|
+
}
|
|
109
|
+
clearTimeout(time);
|
|
110
|
+
if (immediate && !time) {
|
|
111
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
112
|
+
}
|
|
113
|
+
time = setTimeout(function () {
|
|
114
|
+
time = null;
|
|
115
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
116
|
+
}, t);
|
|
117
|
+
};
|
|
118
|
+
return debounceFunction;
|
|
129
119
|
}
|
|
130
120
|
FunctionUtil.debounceFn = debounceFn;
|
|
131
121
|
/**
|
|
@@ -143,24 +133,25 @@ var FunctionUtil;
|
|
|
143
133
|
t = 2000;
|
|
144
134
|
}
|
|
145
135
|
if (!BaseUtil.isFunction(fn)) throw new Error('第一个参数必须是方法');
|
|
146
|
-
var _fn = fn;
|
|
147
136
|
var time = null;
|
|
148
137
|
var first = true;
|
|
149
|
-
|
|
150
|
-
var
|
|
151
|
-
var
|
|
138
|
+
var throttleFunction = function throttleFunction() {
|
|
139
|
+
var args = [];
|
|
140
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
141
|
+
args[_i] = arguments[_i];
|
|
142
|
+
}
|
|
152
143
|
if (first) {
|
|
153
|
-
|
|
144
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
154
145
|
first = false;
|
|
155
146
|
return;
|
|
156
147
|
}
|
|
157
148
|
if (time) return;
|
|
158
149
|
time = setTimeout(function () {
|
|
159
|
-
setTimeout(time);
|
|
160
150
|
time = null;
|
|
161
|
-
|
|
151
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
162
152
|
}, t);
|
|
163
153
|
};
|
|
154
|
+
return throttleFunction;
|
|
164
155
|
}
|
|
165
156
|
FunctionUtil.throttleFn = throttleFn;
|
|
166
157
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionOpts } from
|
|
1
|
+
import { SessionOpts } from '../types';
|
|
2
2
|
declare namespace StorageUtil {
|
|
3
3
|
function setItem<T>(name: string, data: T, opts?: SessionOpts): void;
|
|
4
4
|
function getItem<T>(name: string, opts?: SessionOpts): T;
|
|
@@ -14,6 +14,6 @@ declare namespace StorageUtil {
|
|
|
14
14
|
* 设置全局缓存类型
|
|
15
15
|
* @param type "session" | "local"
|
|
16
16
|
*/
|
|
17
|
-
const setGlobalCacheType: (type: SessionOpts[
|
|
17
|
+
const setGlobalCacheType: (type: SessionOpts['type']) => void;
|
|
18
18
|
}
|
|
19
19
|
export default StorageUtil;
|
|
@@ -20,19 +20,20 @@ var __read = this && this.__read || function (o, n) {
|
|
|
20
20
|
}
|
|
21
21
|
return ar;
|
|
22
22
|
};
|
|
23
|
-
import
|
|
23
|
+
import PasswordUtil from '../pwd/PasswordUtil';
|
|
24
|
+
import config from '../config';
|
|
24
25
|
var StorageUtil;
|
|
25
26
|
(function (StorageUtil) {
|
|
26
27
|
function setItem(name, data, opts) {
|
|
27
28
|
var cacheType = (opts === null || opts === void 0 ? void 0 : opts.type) || config.cacheType;
|
|
28
|
-
if (name && data !== undefined) window["".concat(cacheType, "Storage")].setItem((opts === null || opts === void 0 ? void 0 : opts.itemName) || "".concat(config.title).concat(name), JSON.stringify(data));
|
|
29
|
+
if (name && data !== undefined) window["".concat(cacheType, "Storage")].setItem((opts === null || opts === void 0 ? void 0 : opts.itemName) || "".concat(config.title).concat(name), PasswordUtil.strEncrypt(JSON.stringify(data)));
|
|
29
30
|
}
|
|
30
31
|
StorageUtil.setItem = setItem;
|
|
31
32
|
function getItem(name, opts) {
|
|
32
33
|
var cacheType = (opts === null || opts === void 0 ? void 0 : opts.type) || config.cacheType;
|
|
33
34
|
var item = window["".concat(cacheType, "Storage")].getItem((opts === null || opts === void 0 ? void 0 : opts.itemName) || "".concat(config.title).concat(name));
|
|
34
35
|
try {
|
|
35
|
-
return JSON.parse(item);
|
|
36
|
+
return JSON.parse(PasswordUtil.strDecrypt(item));
|
|
36
37
|
} catch (error) {
|
|
37
38
|
return item;
|
|
38
39
|
}
|
|
@@ -34,7 +34,7 @@ declare namespace FunctionUtil {
|
|
|
34
34
|
* query()
|
|
35
35
|
* query() => 3
|
|
36
36
|
*/
|
|
37
|
-
function debounceFn<T extends
|
|
37
|
+
function debounceFn<T extends (...args: any[]) => any>(fn: T, t?: number, immediate?: boolean): T;
|
|
38
38
|
/**
|
|
39
39
|
* 函数节流
|
|
40
40
|
* @param fn 需要节流的函数
|
|
@@ -45,7 +45,7 @@ declare namespace FunctionUtil {
|
|
|
45
45
|
* query()
|
|
46
46
|
* query()
|
|
47
47
|
*/
|
|
48
|
-
function throttleFn<T extends
|
|
48
|
+
function throttleFn<T extends (...args: any[]) => any>(fn: T, t?: number): T;
|
|
49
49
|
/**
|
|
50
50
|
* 函数只能调用一次
|
|
51
51
|
* @param { Function } fn 需要被处理的函数
|
package/lib/func/FunctionUtil.js
CHANGED
|
@@ -110,32 +110,22 @@ var FunctionUtil;
|
|
|
110
110
|
immediate = true;
|
|
111
111
|
}
|
|
112
112
|
if (!BaseUtil_1.default.isFunction(fn)) throw new Error('第一个参数必须是方法');
|
|
113
|
-
var time;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
clearTimeout(time);
|
|
130
|
-
var that = this;
|
|
131
|
-
var arg = arguments;
|
|
132
|
-
time = setTimeout(function () {
|
|
133
|
-
setTimeout(time);
|
|
134
|
-
fn.apply(that, arg);
|
|
135
|
-
time = null;
|
|
136
|
-
}, t);
|
|
137
|
-
};
|
|
138
|
-
}
|
|
113
|
+
var time = null;
|
|
114
|
+
var debounceFunction = function debounceFunction() {
|
|
115
|
+
var args = [];
|
|
116
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
117
|
+
args[_i] = arguments[_i];
|
|
118
|
+
}
|
|
119
|
+
clearTimeout(time);
|
|
120
|
+
if (immediate && !time) {
|
|
121
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
122
|
+
}
|
|
123
|
+
time = setTimeout(function () {
|
|
124
|
+
time = null;
|
|
125
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
126
|
+
}, t);
|
|
127
|
+
};
|
|
128
|
+
return debounceFunction;
|
|
139
129
|
}
|
|
140
130
|
FunctionUtil.debounceFn = debounceFn;
|
|
141
131
|
/**
|
|
@@ -153,24 +143,25 @@ var FunctionUtil;
|
|
|
153
143
|
t = 2000;
|
|
154
144
|
}
|
|
155
145
|
if (!BaseUtil_1.default.isFunction(fn)) throw new Error('第一个参数必须是方法');
|
|
156
|
-
var _fn = fn;
|
|
157
146
|
var time = null;
|
|
158
147
|
var first = true;
|
|
159
|
-
|
|
160
|
-
var
|
|
161
|
-
var
|
|
148
|
+
var throttleFunction = function throttleFunction() {
|
|
149
|
+
var args = [];
|
|
150
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
151
|
+
args[_i] = arguments[_i];
|
|
152
|
+
}
|
|
162
153
|
if (first) {
|
|
163
|
-
|
|
154
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
164
155
|
first = false;
|
|
165
156
|
return;
|
|
166
157
|
}
|
|
167
158
|
if (time) return;
|
|
168
159
|
time = setTimeout(function () {
|
|
169
|
-
setTimeout(time);
|
|
170
160
|
time = null;
|
|
171
|
-
|
|
161
|
+
fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
172
162
|
}, t);
|
|
173
163
|
};
|
|
164
|
+
return throttleFunction;
|
|
174
165
|
}
|
|
175
166
|
FunctionUtil.throttleFn = throttleFn;
|
|
176
167
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionOpts } from
|
|
1
|
+
import { SessionOpts } from '../types';
|
|
2
2
|
declare namespace StorageUtil {
|
|
3
3
|
function setItem<T>(name: string, data: T, opts?: SessionOpts): void;
|
|
4
4
|
function getItem<T>(name: string, opts?: SessionOpts): T;
|
|
@@ -14,6 +14,6 @@ declare namespace StorageUtil {
|
|
|
14
14
|
* 设置全局缓存类型
|
|
15
15
|
* @param type "session" | "local"
|
|
16
16
|
*/
|
|
17
|
-
const setGlobalCacheType: (type: SessionOpts[
|
|
17
|
+
const setGlobalCacheType: (type: SessionOpts['type']) => void;
|
|
18
18
|
}
|
|
19
19
|
export default StorageUtil;
|
|
@@ -30,19 +30,20 @@ var __importDefault = this && this.__importDefault || function (mod) {
|
|
|
30
30
|
Object.defineProperty(exports, "__esModule", {
|
|
31
31
|
value: true
|
|
32
32
|
});
|
|
33
|
+
var PasswordUtil_1 = __importDefault(require("../pwd/PasswordUtil"));
|
|
33
34
|
var config_1 = __importDefault(require("../config"));
|
|
34
35
|
var StorageUtil;
|
|
35
36
|
(function (StorageUtil) {
|
|
36
37
|
function setItem(name, data, opts) {
|
|
37
38
|
var cacheType = (opts === null || opts === void 0 ? void 0 : opts.type) || config_1.default.cacheType;
|
|
38
|
-
if (name && data !== undefined) window["".concat(cacheType, "Storage")].setItem((opts === null || opts === void 0 ? void 0 : opts.itemName) || "".concat(config_1.default.title).concat(name), JSON.stringify(data));
|
|
39
|
+
if (name && data !== undefined) window["".concat(cacheType, "Storage")].setItem((opts === null || opts === void 0 ? void 0 : opts.itemName) || "".concat(config_1.default.title).concat(name), PasswordUtil_1.default.strEncrypt(JSON.stringify(data)));
|
|
39
40
|
}
|
|
40
41
|
StorageUtil.setItem = setItem;
|
|
41
42
|
function getItem(name, opts) {
|
|
42
43
|
var cacheType = (opts === null || opts === void 0 ? void 0 : opts.type) || config_1.default.cacheType;
|
|
43
44
|
var item = window["".concat(cacheType, "Storage")].getItem((opts === null || opts === void 0 ? void 0 : opts.itemName) || "".concat(config_1.default.title).concat(name));
|
|
44
45
|
try {
|
|
45
|
-
return JSON.parse(item);
|
|
46
|
+
return JSON.parse(PasswordUtil_1.default.strDecrypt(item));
|
|
46
47
|
} catch (error) {
|
|
47
48
|
return item;
|
|
48
49
|
}
|