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 CHANGED
@@ -5,6 +5,16 @@ pnpm i tools-min-ns --save
5
5
  ```
6
6
 
7
7
  # updates
8
+ ## v1.17.1
9
+ >StorageUtil
10
+ PasswordUtil引用路径bug
11
+ ## v1.17.0
12
+ >StorageUtil
13
+ 加解密
14
+
15
+ ## v1.16.3
16
+ >FunctionUti
17
+ 防抖节流兼容小程序
8
18
  ## v1.16.2
9
19
  > PasswordUtil
10
20
  新增minEncryptData/minDecryptData
@@ -34,7 +34,7 @@ declare namespace FunctionUtil {
34
34
  * query()
35
35
  * query() => 3
36
36
  */
37
- function debounceFn<T extends Function>(fn: T, t?: number, immediate?: boolean): T;
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 Function>(fn: T, t?: number): T;
48
+ function throttleFn<T extends (...args: any[]) => any>(fn: T, t?: number): T;
49
49
  /**
50
50
  * 函数只能调用一次
51
51
  * @param { Function } fn 需要被处理的函数
@@ -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
- if (immediate) {
106
- return function () {
107
- clearTimeout(time);
108
- if (!time) {
109
- fn.apply(this, arguments);
110
- }
111
- time = setTimeout(function () {
112
- setTimeout(time);
113
- time = null;
114
- }, t);
115
- };
116
- } else {
117
- // 满足 time 时间结束之后自动执行一次该方法
118
- return function () {
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
- return function () {
150
- var arg = arguments;
151
- var _this = this;
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
- _fn.apply(_this, arg);
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
- _fn.apply(_this, arg);
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 "../types";
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["type"]) => void;
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 config from "../config";
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 Function>(fn: T, t?: number, immediate?: boolean): T;
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 Function>(fn: T, t?: number): T;
48
+ function throttleFn<T extends (...args: any[]) => any>(fn: T, t?: number): T;
49
49
  /**
50
50
  * 函数只能调用一次
51
51
  * @param { Function } fn 需要被处理的函数
@@ -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
- if (immediate) {
116
- return function () {
117
- clearTimeout(time);
118
- if (!time) {
119
- fn.apply(this, arguments);
120
- }
121
- time = setTimeout(function () {
122
- setTimeout(time);
123
- time = null;
124
- }, t);
125
- };
126
- } else {
127
- // 满足 time 时间结束之后自动执行一次该方法
128
- return function () {
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
- return function () {
160
- var arg = arguments;
161
- var _this = this;
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
- _fn.apply(_this, arg);
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
- _fn.apply(_this, arg);
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 "../types";
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["type"]) => void;
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
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tools-min-ns",
3
3
  "description": "工具包适用于前端以及node",
4
- "version": "1.16.2",
4
+ "version": "1.17.1",
5
5
  "main": "lib/index.js",
6
6
  "license": "MIT",
7
7
  "author": "nanshen",