tools-for-js 1.5.5 → 2.0.0
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 +37 -2
- package/lib/index.js +190 -1
- package/lib/web/browser.js +65 -0
- package/lib/web/core.js +65 -0
- package/lib/web/files.js +108 -0
- package/lib/web/mobile.js +29 -0
- package/lib/web/route.js +80 -0
- package/lib/web/store.js +150 -0
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
### 项目名称
|
|
2
2
|
|
|
3
|
-
> tools-for-js ——
|
|
3
|
+
> tools-for-js —— JavaScript 前端工具库
|
|
4
4
|
|
|
5
5
|
### 安装
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ npm install tools-for-js --save
|
|
|
14
14
|
import { API } from 'tools-for-js'
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
### API
|
|
17
|
+
### JS API
|
|
18
18
|
|
|
19
19
|
| 名称 | API |
|
|
20
20
|
| ------------------------------------------------ | ----------------- |
|
|
@@ -71,3 +71,38 @@ import { API } from 'tools-for-js'
|
|
|
71
71
|
| 验证运动账号 | checkSports |
|
|
72
72
|
| 判断是否为 json 字符串 | isJSONString |
|
|
73
73
|
| 待更新 | function |
|
|
74
|
+
|
|
75
|
+
### WEB 相关 API
|
|
76
|
+
|
|
77
|
+
| 名称 | API |
|
|
78
|
+
| -------------------------- | ---------------- |
|
|
79
|
+
| store2:localStorage 缓存 | local |
|
|
80
|
+
| store2:sessionStorage 缓存 | session |
|
|
81
|
+
| 设置有效期信息 | setExpires |
|
|
82
|
+
| 获取有效期信息 | getExpires |
|
|
83
|
+
| 移除有效期信息 | removeExpires |
|
|
84
|
+
| 获取 cookie | getCookie |
|
|
85
|
+
| 获取所有 cookie | getCookies |
|
|
86
|
+
| 设置 cookie | setCookie |
|
|
87
|
+
| 删除指定 cookie | removeCookie |
|
|
88
|
+
| 删除所有 cookie | removeCookies |
|
|
89
|
+
| 将 txt 的 blob 转文本内容 | blobToText |
|
|
90
|
+
| 下载流文件 | downloadStream |
|
|
91
|
+
| 图片转 base64 | getBase64 |
|
|
92
|
+
| 浏览器内核 | kernelInfo |
|
|
93
|
+
| 移动端/PC 端 | isMobile |
|
|
94
|
+
| 是否 android 终端 | isAndroid |
|
|
95
|
+
| 是否 ios 终端 | isIOS |
|
|
96
|
+
| 是否微信环境 | isWeiXn |
|
|
97
|
+
| 是否 QQ 环境 | isQQ |
|
|
98
|
+
| 是否钉钉环境 | isDingTalk |
|
|
99
|
+
| 是否微博环境 | isWeiBo |
|
|
100
|
+
| 获取哈希路由参数 | getHashParam |
|
|
101
|
+
| 获取路由参数 | getQueryParams |
|
|
102
|
+
| 获取当前路径 | getPath |
|
|
103
|
+
| 清除.html 后缀 | wrapperCleanUrls |
|
|
104
|
+
| 获取移动端转换比例 | getScale |
|
|
105
|
+
| 移动端自适应尺寸转换 | sizeConvert |
|
|
106
|
+
| 创建 script 标签加载 js | createScript |
|
|
107
|
+
| 清除.html 后缀 | wrapperCleanUrls |
|
|
108
|
+
| 复制文本 | copyText |
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -27,6 +28,12 @@ Object.defineProperty(exports, "arrayToTree", {
|
|
|
27
28
|
return _array.arrayToTree;
|
|
28
29
|
}
|
|
29
30
|
});
|
|
31
|
+
Object.defineProperty(exports, "blobToText", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function get() {
|
|
34
|
+
return _files.blobToText;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
30
37
|
Object.defineProperty(exports, "checkCode", {
|
|
31
38
|
enumerable: true,
|
|
32
39
|
get: function get() {
|
|
@@ -75,6 +82,12 @@ Object.defineProperty(exports, "convertSmallHump", {
|
|
|
75
82
|
return _transform.convertSmallHump;
|
|
76
83
|
}
|
|
77
84
|
});
|
|
85
|
+
Object.defineProperty(exports, "copyText", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function get() {
|
|
88
|
+
return _core.copyText;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
78
91
|
Object.defineProperty(exports, "countDown", {
|
|
79
92
|
enumerable: true,
|
|
80
93
|
get: function get() {
|
|
@@ -93,6 +106,12 @@ Object.defineProperty(exports, "createDate", {
|
|
|
93
106
|
return _time.createDate;
|
|
94
107
|
}
|
|
95
108
|
});
|
|
109
|
+
Object.defineProperty(exports, "createScript", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function get() {
|
|
112
|
+
return _core.createScript;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
96
115
|
Object.defineProperty(exports, "createUUID", {
|
|
97
116
|
enumerable: true,
|
|
98
117
|
get: function get() {
|
|
@@ -123,6 +142,12 @@ Object.defineProperty(exports, "deepCopy", {
|
|
|
123
142
|
return _common.deepCopy;
|
|
124
143
|
}
|
|
125
144
|
});
|
|
145
|
+
Object.defineProperty(exports, "downloadStream", {
|
|
146
|
+
enumerable: true,
|
|
147
|
+
get: function get() {
|
|
148
|
+
return _files.downloadStream;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
126
151
|
Object.defineProperty(exports, "encrypt", {
|
|
127
152
|
enumerable: true,
|
|
128
153
|
get: function get() {
|
|
@@ -153,18 +178,66 @@ Object.defineProperty(exports, "getAfterNDays", {
|
|
|
153
178
|
return _time.getAfterNDays;
|
|
154
179
|
}
|
|
155
180
|
});
|
|
181
|
+
Object.defineProperty(exports, "getBase64", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
get: function get() {
|
|
184
|
+
return _files.getBase64;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(exports, "getCookie", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
get: function get() {
|
|
190
|
+
return _store.getCookie;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(exports, "getCookies", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
get: function get() {
|
|
196
|
+
return _store.getCookies;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
Object.defineProperty(exports, "getExpires", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
get: function get() {
|
|
202
|
+
return _store.getExpires;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
156
205
|
Object.defineProperty(exports, "getExpiresEndTime", {
|
|
157
206
|
enumerable: true,
|
|
158
207
|
get: function get() {
|
|
159
208
|
return _time.getExpiresEndTime;
|
|
160
209
|
}
|
|
161
210
|
});
|
|
211
|
+
Object.defineProperty(exports, "getHashParam", {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
get: function get() {
|
|
214
|
+
return _route.getHashParam;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
162
217
|
Object.defineProperty(exports, "getPagination", {
|
|
163
218
|
enumerable: true,
|
|
164
219
|
get: function get() {
|
|
165
220
|
return _array.getPagination;
|
|
166
221
|
}
|
|
167
222
|
});
|
|
223
|
+
Object.defineProperty(exports, "getPath", {
|
|
224
|
+
enumerable: true,
|
|
225
|
+
get: function get() {
|
|
226
|
+
return _route.getPath;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
Object.defineProperty(exports, "getQueryParams", {
|
|
230
|
+
enumerable: true,
|
|
231
|
+
get: function get() {
|
|
232
|
+
return _route.getQueryParams;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
Object.defineProperty(exports, "getScale", {
|
|
236
|
+
enumerable: true,
|
|
237
|
+
get: function get() {
|
|
238
|
+
return _mobile.getScale;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
168
241
|
Object.defineProperty(exports, "getStrLength", {
|
|
169
242
|
enumerable: true,
|
|
170
243
|
get: function get() {
|
|
@@ -195,6 +268,18 @@ Object.defineProperty(exports, "invertSelection", {
|
|
|
195
268
|
return _array.invertSelection;
|
|
196
269
|
}
|
|
197
270
|
});
|
|
271
|
+
Object.defineProperty(exports, "isAndroid", {
|
|
272
|
+
enumerable: true,
|
|
273
|
+
get: function get() {
|
|
274
|
+
return _browser.isAndroid;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
Object.defineProperty(exports, "isDingTalk", {
|
|
278
|
+
enumerable: true,
|
|
279
|
+
get: function get() {
|
|
280
|
+
return _browser.isDingTalk;
|
|
281
|
+
}
|
|
282
|
+
});
|
|
198
283
|
Object.defineProperty(exports, "isEmpty", {
|
|
199
284
|
enumerable: true,
|
|
200
285
|
get: function get() {
|
|
@@ -213,18 +298,60 @@ Object.defineProperty(exports, "isExpires", {
|
|
|
213
298
|
return _time.isExpires;
|
|
214
299
|
}
|
|
215
300
|
});
|
|
301
|
+
Object.defineProperty(exports, "isIOS", {
|
|
302
|
+
enumerable: true,
|
|
303
|
+
get: function get() {
|
|
304
|
+
return _browser.isIOS;
|
|
305
|
+
}
|
|
306
|
+
});
|
|
216
307
|
Object.defineProperty(exports, "isJsonString", {
|
|
217
308
|
enumerable: true,
|
|
218
309
|
get: function get() {
|
|
219
310
|
return _object.isJsonString;
|
|
220
311
|
}
|
|
221
312
|
});
|
|
313
|
+
Object.defineProperty(exports, "isMobile", {
|
|
314
|
+
enumerable: true,
|
|
315
|
+
get: function get() {
|
|
316
|
+
return _browser.isMobile;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
Object.defineProperty(exports, "isQQ", {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
get: function get() {
|
|
322
|
+
return _browser.isQQ;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
Object.defineProperty(exports, "isWeiBo", {
|
|
326
|
+
enumerable: true,
|
|
327
|
+
get: function get() {
|
|
328
|
+
return _browser.isWeiBo;
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
Object.defineProperty(exports, "isWeiXn", {
|
|
332
|
+
enumerable: true,
|
|
333
|
+
get: function get() {
|
|
334
|
+
return _browser.isWeiXn;
|
|
335
|
+
}
|
|
336
|
+
});
|
|
222
337
|
Object.defineProperty(exports, "jsonParse", {
|
|
223
338
|
enumerable: true,
|
|
224
339
|
get: function get() {
|
|
225
340
|
return _object.jsonParse;
|
|
226
341
|
}
|
|
227
342
|
});
|
|
343
|
+
Object.defineProperty(exports, "kernelInfo", {
|
|
344
|
+
enumerable: true,
|
|
345
|
+
get: function get() {
|
|
346
|
+
return _browser.kernelInfo;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
Object.defineProperty(exports, "local", {
|
|
350
|
+
enumerable: true,
|
|
351
|
+
get: function get() {
|
|
352
|
+
return _store.local;
|
|
353
|
+
}
|
|
354
|
+
});
|
|
228
355
|
Object.defineProperty(exports, "lowercaseKeys", {
|
|
229
356
|
enumerable: true,
|
|
230
357
|
get: function get() {
|
|
@@ -297,18 +424,60 @@ Object.defineProperty(exports, "randomNumEnum", {
|
|
|
297
424
|
return _random.randomNumEnum;
|
|
298
425
|
}
|
|
299
426
|
});
|
|
427
|
+
Object.defineProperty(exports, "removeCookie", {
|
|
428
|
+
enumerable: true,
|
|
429
|
+
get: function get() {
|
|
430
|
+
return _store.removeCookie;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
Object.defineProperty(exports, "removeCookies", {
|
|
434
|
+
enumerable: true,
|
|
435
|
+
get: function get() {
|
|
436
|
+
return _store.removeCookies;
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
Object.defineProperty(exports, "removeExpires", {
|
|
440
|
+
enumerable: true,
|
|
441
|
+
get: function get() {
|
|
442
|
+
return _store.removeExpires;
|
|
443
|
+
}
|
|
444
|
+
});
|
|
300
445
|
Object.defineProperty(exports, "replacePath", {
|
|
301
446
|
enumerable: true,
|
|
302
447
|
get: function get() {
|
|
303
448
|
return _string.replacePath;
|
|
304
449
|
}
|
|
305
450
|
});
|
|
451
|
+
Object.defineProperty(exports, "session", {
|
|
452
|
+
enumerable: true,
|
|
453
|
+
get: function get() {
|
|
454
|
+
return _store.session;
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
Object.defineProperty(exports, "setCookie", {
|
|
458
|
+
enumerable: true,
|
|
459
|
+
get: function get() {
|
|
460
|
+
return _store.setCookie;
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
Object.defineProperty(exports, "setExpires", {
|
|
464
|
+
enumerable: true,
|
|
465
|
+
get: function get() {
|
|
466
|
+
return _store.setExpires;
|
|
467
|
+
}
|
|
468
|
+
});
|
|
306
469
|
Object.defineProperty(exports, "shuffleArray", {
|
|
307
470
|
enumerable: true,
|
|
308
471
|
get: function get() {
|
|
309
472
|
return _array.shuffleArray;
|
|
310
473
|
}
|
|
311
474
|
});
|
|
475
|
+
Object.defineProperty(exports, "sizeConvert", {
|
|
476
|
+
enumerable: true,
|
|
477
|
+
get: function get() {
|
|
478
|
+
return _mobile.sizeConvert;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
312
481
|
Object.defineProperty(exports, "sortByKeyAndTime", {
|
|
313
482
|
enumerable: true,
|
|
314
483
|
get: function get() {
|
|
@@ -327,6 +496,12 @@ Object.defineProperty(exports, "splitToFileName", {
|
|
|
327
496
|
return _string.splitToFileName;
|
|
328
497
|
}
|
|
329
498
|
});
|
|
499
|
+
Object.defineProperty(exports, "store", {
|
|
500
|
+
enumerable: true,
|
|
501
|
+
get: function get() {
|
|
502
|
+
return _store["default"];
|
|
503
|
+
}
|
|
504
|
+
});
|
|
330
505
|
Object.defineProperty(exports, "summation", {
|
|
331
506
|
enumerable: true,
|
|
332
507
|
get: function get() {
|
|
@@ -369,6 +544,12 @@ Object.defineProperty(exports, "upperCaseKeys", {
|
|
|
369
544
|
return _transform.upperCaseKeys;
|
|
370
545
|
}
|
|
371
546
|
});
|
|
547
|
+
Object.defineProperty(exports, "wrapperCleanUrls", {
|
|
548
|
+
enumerable: true,
|
|
549
|
+
get: function get() {
|
|
550
|
+
return _route.wrapperCleanUrls;
|
|
551
|
+
}
|
|
552
|
+
});
|
|
372
553
|
var _transform = require("./utils/transform");
|
|
373
554
|
var _time = require("./utils/time");
|
|
374
555
|
var _array = require("./utils/array");
|
|
@@ -377,4 +558,12 @@ var _common = require("./utils/common");
|
|
|
377
558
|
var _string = require("./utils/string");
|
|
378
559
|
var _random = require("./utils/random");
|
|
379
560
|
var _object = require("./utils/object");
|
|
380
|
-
var _regexp = require("./utils/regexp");
|
|
561
|
+
var _regexp = require("./utils/regexp");
|
|
562
|
+
var _files = require("./web/files");
|
|
563
|
+
var _store = _interopRequireWildcard(require("./web/store"));
|
|
564
|
+
var _browser = require("./web/browser");
|
|
565
|
+
var _route = require("./web/route");
|
|
566
|
+
var _mobile = require("./web/mobile");
|
|
567
|
+
var _core = require("./web/core");
|
|
568
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
569
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.kernelInfo = exports.isWeiXn = exports.isWeiBo = exports.isQQ = exports.isMobile = exports.isIOS = exports.isDingTalk = exports.isAndroid = void 0;
|
|
7
|
+
/*******
|
|
8
|
+
* @description: 浏览器信息
|
|
9
|
+
* @author: 琴时
|
|
10
|
+
*/
|
|
11
|
+
var ua = '';
|
|
12
|
+
if (typeof window !== 'undefined') {
|
|
13
|
+
ua = navigator.userAgent; // 获取设备信息
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/*******
|
|
17
|
+
* @description: 浏览器内核
|
|
18
|
+
* @author: 琴时
|
|
19
|
+
* @return {Object} 返回内核信息
|
|
20
|
+
*/
|
|
21
|
+
var kernelInfo = exports.kernelInfo = {
|
|
22
|
+
trident: ua.indexOf('Trident') > -1,
|
|
23
|
+
//IE内核
|
|
24
|
+
presto: ua.indexOf('Presto') > -1,
|
|
25
|
+
//opera内核
|
|
26
|
+
webKit: ua.indexOf('AppleWebKit') > -1,
|
|
27
|
+
//苹果、谷歌内核
|
|
28
|
+
gecko: ua.indexOf('Gecko') > -1 && ua.indexOf('KHTML') == -1 //火狐内核
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/*******
|
|
32
|
+
* @description: 检测移动端/PC端
|
|
33
|
+
* [移动端:true - PC端:false]
|
|
34
|
+
*/
|
|
35
|
+
var isMobile = exports.isMobile = Boolean(ua.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i));
|
|
36
|
+
|
|
37
|
+
/*******
|
|
38
|
+
* @description: android终端
|
|
39
|
+
*/
|
|
40
|
+
var isAndroid = exports.isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1;
|
|
41
|
+
|
|
42
|
+
/*******
|
|
43
|
+
* @description: ios终端
|
|
44
|
+
*/
|
|
45
|
+
var isIOS = exports.isIOS = Boolean(ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/));
|
|
46
|
+
|
|
47
|
+
/*******
|
|
48
|
+
* @description: 微信环境
|
|
49
|
+
*/
|
|
50
|
+
var isWeiXn = exports.isWeiXn = ua.toLowerCase().includes('micromessenger');
|
|
51
|
+
|
|
52
|
+
/*******
|
|
53
|
+
* @description: QQ环境
|
|
54
|
+
*/
|
|
55
|
+
var isQQ = exports.isQQ = ua.toLowerCase().includes('qqbrowser');
|
|
56
|
+
|
|
57
|
+
/*******
|
|
58
|
+
* @description: 钉钉环境
|
|
59
|
+
*/
|
|
60
|
+
var isDingTalk = exports.isDingTalk = ua.toLowerCase().includes('dingtalk');
|
|
61
|
+
|
|
62
|
+
/*******
|
|
63
|
+
* @description: 微博环境
|
|
64
|
+
*/
|
|
65
|
+
var isWeiBo = exports.isWeiBo = ua.toLowerCase().includes('weibo');
|
package/lib/web/core.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.copyText = copyText;
|
|
7
|
+
exports.createScript = void 0;
|
|
8
|
+
/*******
|
|
9
|
+
* @description: 创建script标签加载js
|
|
10
|
+
* @author: 琴时
|
|
11
|
+
* @param {String} url
|
|
12
|
+
* @return {*}
|
|
13
|
+
*/
|
|
14
|
+
var createScript = exports.createScript = function createScript() {
|
|
15
|
+
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
16
|
+
if (typeof window === 'undefined') return;
|
|
17
|
+
var scriptTags = window.document.querySelectorAll('script');
|
|
18
|
+
var len = scriptTags.length;
|
|
19
|
+
var i = 0;
|
|
20
|
+
// 截取字符串,去掉可能url是相对路径的
|
|
21
|
+
url = url.indexOf('.') === 0 ? url.substr(1) : url;
|
|
22
|
+
var _url = location.origin + url;
|
|
23
|
+
return new Promise(function (resolve, reject) {
|
|
24
|
+
var isHas = false;
|
|
25
|
+
for (i = 0; i < len; i++) {
|
|
26
|
+
var src = scriptTags[i].src;
|
|
27
|
+
if (src && src === _url) {
|
|
28
|
+
isHas = true;
|
|
29
|
+
resolve();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (!isHas) {
|
|
33
|
+
var node = document.createElement('script');
|
|
34
|
+
node.type = 'text/javascript';
|
|
35
|
+
node.src = url;
|
|
36
|
+
node.onload = resolve;
|
|
37
|
+
document.body.appendChild(node);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/*******
|
|
43
|
+
* @description: 复制文本
|
|
44
|
+
* @author: 琴时
|
|
45
|
+
* @param {String} text
|
|
46
|
+
* @return {*}
|
|
47
|
+
*/
|
|
48
|
+
function copyText(text) {
|
|
49
|
+
if (typeof window === 'undefined') return;
|
|
50
|
+
if (navigator.clipboard) {
|
|
51
|
+
exports.copyText = copyText = function copyText(text) {
|
|
52
|
+
navigator.clipboard.writeText(text);
|
|
53
|
+
};
|
|
54
|
+
} else {
|
|
55
|
+
exports.copyText = copyText = function copyText(text) {
|
|
56
|
+
var input = document.createElement('input');
|
|
57
|
+
input.setAttribute('value', text);
|
|
58
|
+
document.body.appendChild(input);
|
|
59
|
+
input.select();
|
|
60
|
+
document.execCommand('copy');
|
|
61
|
+
document.body.removeChild(input);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
copyText(text);
|
|
65
|
+
}
|
package/lib/web/files.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getBase64 = exports.downloadStream = exports.blobToText = void 0;
|
|
7
|
+
/*******
|
|
8
|
+
* @description: 将txt的blob转文本内容
|
|
9
|
+
* @author: 琴时
|
|
10
|
+
* @param {*} blob
|
|
11
|
+
* @return {*}
|
|
12
|
+
*/
|
|
13
|
+
var blobToText = exports.blobToText = function blobToText(blob) {
|
|
14
|
+
return new Promise(function (resolve, reject) {
|
|
15
|
+
if (typeof FileReader === 'undefined') {
|
|
16
|
+
reject(new Error('浏览器不支持FileReader对象'));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
var reader = new FileReader();
|
|
20
|
+
reader.onload = function () {
|
|
21
|
+
resolve(reader.result);
|
|
22
|
+
};
|
|
23
|
+
reader.onerror = function () {
|
|
24
|
+
reject(new Error('无法读取Blob对象'));
|
|
25
|
+
};
|
|
26
|
+
if (blob.constructor !== File) {
|
|
27
|
+
reject(new Error('该数据不是blob'));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
reader.readAsText(blob);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/*******
|
|
35
|
+
* @description: 下载流文件
|
|
36
|
+
* @author: 琴时
|
|
37
|
+
* @param {*} stream 文件流
|
|
38
|
+
* @param {String} fileName 文件名
|
|
39
|
+
* @return {*}
|
|
40
|
+
*/
|
|
41
|
+
var downloadStream = exports.downloadStream = function downloadStream(stream, fileName) {
|
|
42
|
+
try {
|
|
43
|
+
if (typeof window === 'undefined') return;
|
|
44
|
+
var fileTypeMime = {
|
|
45
|
+
png: 'image/png',
|
|
46
|
+
jpeg: 'image/jpeg',
|
|
47
|
+
gif: 'image/gif',
|
|
48
|
+
svg: 'image/svg+xml',
|
|
49
|
+
tiff: 'image/tiff',
|
|
50
|
+
doc: 'application/msword',
|
|
51
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
52
|
+
txt: 'text/plain',
|
|
53
|
+
pdf: 'application/pdf',
|
|
54
|
+
mp4: 'video/mp4',
|
|
55
|
+
mp3: 'audio/mpeg',
|
|
56
|
+
rar: 'application/x-rar-compressed',
|
|
57
|
+
html: 'text/html',
|
|
58
|
+
xml: 'text/xml',
|
|
59
|
+
json: 'application/json',
|
|
60
|
+
css: 'text/css',
|
|
61
|
+
js: 'text/javascript',
|
|
62
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
63
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
64
|
+
csv: 'text/csv',
|
|
65
|
+
xls: 'application/vnd.ms-excel',
|
|
66
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
67
|
+
zip: 'application/zip',
|
|
68
|
+
'7z': 'application/x-7z-compressed'
|
|
69
|
+
};
|
|
70
|
+
var suffix = fileName.slice(fileName.indexOf('.') + 1); //获取文件后缀
|
|
71
|
+
var blob = new Blob([stream], {
|
|
72
|
+
type: fileTypeMime[suffix]
|
|
73
|
+
}); //创建blob对象
|
|
74
|
+
var aLink = document.createElement('a'); //创建a标签
|
|
75
|
+
document.body.appendChild(aLink); //末尾添加新的子节点
|
|
76
|
+
aLink.style.display = 'none'; //将a标签隐藏
|
|
77
|
+
var blobURL = URL.createObjectURL(blob); //将blob转换成URL
|
|
78
|
+
aLink.href = aLink.download = fileName; //配置下载文件名
|
|
79
|
+
aLink.click(); //自动触发点击a标签[下载文件]
|
|
80
|
+
document.body.removeChild(aLink); //移除a标签
|
|
81
|
+
URL.revokeObjectURL(blobURL); // 释放blob URL地址
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.log('下载异常:', error.message);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/*******
|
|
88
|
+
* @description: 图片转base64
|
|
89
|
+
* @author: 琴时
|
|
90
|
+
* @param {File} fil
|
|
91
|
+
* @return {*}
|
|
92
|
+
*/
|
|
93
|
+
var getBase64 = exports.getBase64 = function getBase64(file) {
|
|
94
|
+
return new Promise(function (resolve, reject) {
|
|
95
|
+
if (typeof FileReader === 'undefined') {
|
|
96
|
+
reject(new Error('浏览器不支持FileReader对象'));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
var reader = new FileReader();
|
|
100
|
+
reader.readAsDataURL(file);
|
|
101
|
+
reader.onload = function () {
|
|
102
|
+
return resolve(reader.result);
|
|
103
|
+
};
|
|
104
|
+
reader.onerror = function (error) {
|
|
105
|
+
return reject(error);
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sizeConvert = exports.getScale = void 0;
|
|
7
|
+
var _calculate = require("../utils/calculate");
|
|
8
|
+
/*******
|
|
9
|
+
* @description: 获取移动端转换比例
|
|
10
|
+
* @return {*}
|
|
11
|
+
*/
|
|
12
|
+
var getScale = exports.getScale = function getScale() {
|
|
13
|
+
var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 75;
|
|
14
|
+
if (typeof window === 'undefined') return 1;
|
|
15
|
+
var htmlElement = document.documentElement;
|
|
16
|
+
var fontSize = window.getComputedStyle(htmlElement).fontSize;
|
|
17
|
+
var scale = (0, _calculate.countNumber)(parseFloat(fontSize), size, 'divide');
|
|
18
|
+
return scale;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/*******
|
|
22
|
+
* @description: 移动端自适应尺寸转换
|
|
23
|
+
* @return {*}
|
|
24
|
+
*/
|
|
25
|
+
var sizeConvert = exports.sizeConvert = function sizeConvert(number, fontSize) {
|
|
26
|
+
var scale = getScale(fontSize);
|
|
27
|
+
var value = (0, _calculate.countNumber)(number, scale, 'multiply');
|
|
28
|
+
return value;
|
|
29
|
+
};
|
package/lib/web/route.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getHashParam = void 0;
|
|
7
|
+
exports.getPath = getPath;
|
|
8
|
+
exports.getQueryParams = void 0;
|
|
9
|
+
exports.wrapperCleanUrls = wrapperCleanUrls;
|
|
10
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
15
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
18
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
19
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
|
+
/*******
|
|
21
|
+
* @description: 获取哈希路由参数
|
|
22
|
+
* @author: 琴时
|
|
23
|
+
* @param {String} key
|
|
24
|
+
* @return {*}
|
|
25
|
+
*/
|
|
26
|
+
var getHashParam = exports.getHashParam = function getHashParam(key) {
|
|
27
|
+
if (typeof window === 'undefined') return null;
|
|
28
|
+
var reg = new RegExp('(^|&)' + key + '=([^&]*)(&|$)');
|
|
29
|
+
// 只有当在浏览器环境中时才执行下面的代码
|
|
30
|
+
var queryString = window.location.href.split('?')[1] || '';
|
|
31
|
+
var result = queryString.match(reg);
|
|
32
|
+
return result ? decodeURIComponent(result[2]) : null;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/*******
|
|
36
|
+
* @description: 获取路由参数
|
|
37
|
+
* @author: 琴时
|
|
38
|
+
* @return {*}
|
|
39
|
+
*/
|
|
40
|
+
var getQueryParams = exports.getQueryParams = function getQueryParams() {
|
|
41
|
+
if (typeof window === 'undefined') return null;
|
|
42
|
+
var queryString = window.location.href.split('?')[1] || '';
|
|
43
|
+
if (!queryString) return null;
|
|
44
|
+
var params = {};
|
|
45
|
+
queryString.split('&').forEach(function (param) {
|
|
46
|
+
var _param$split = param.split('='),
|
|
47
|
+
_param$split2 = _slicedToArray(_param$split, 2),
|
|
48
|
+
key = _param$split2[0],
|
|
49
|
+
value = _param$split2[1];
|
|
50
|
+
params[decodeURIComponent(key)] = decodeURIComponent(value);
|
|
51
|
+
});
|
|
52
|
+
return params;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// 获取当前路径
|
|
56
|
+
function getPath() {
|
|
57
|
+
if (typeof window === 'undefined') return [];
|
|
58
|
+
var pathname = window.location.pathname;
|
|
59
|
+
var currentPath = pathname.replace(/.html$/, '');
|
|
60
|
+
// 兼容中文路径
|
|
61
|
+
var okPaths = [currentPath, decodeURIComponent(currentPath)];
|
|
62
|
+
// 兼容 /(index.md)
|
|
63
|
+
if (currentPath.endsWith('/')) {
|
|
64
|
+
okPaths.push.apply(okPaths, ["".concat(currentPath, "index"), "".concat(decodeURIComponent(currentPath), "index")]);
|
|
65
|
+
}
|
|
66
|
+
return _toConsumableArray(new Set(okPaths));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*******
|
|
70
|
+
* @description: 清除.html后缀
|
|
71
|
+
* @author: 琴时
|
|
72
|
+
* @param {Boolean} cleanUrls [是否清除]
|
|
73
|
+
* @param {String} path
|
|
74
|
+
* @return {String}
|
|
75
|
+
*/
|
|
76
|
+
function wrapperCleanUrls(cleanUrls) {
|
|
77
|
+
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
78
|
+
var tempUrl = path.replace(/\.html$/, '');
|
|
79
|
+
return cleanUrls ? tempUrl : "".concat(tempUrl, ".html");
|
|
80
|
+
}
|
package/lib/web/store.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setExpires = exports.setCookie = exports.session = exports.removeExpires = exports.removeCookies = exports.removeCookie = exports.local = exports.getExpires = exports.getCookies = exports.getCookie = exports["default"] = void 0;
|
|
7
|
+
var _store = _interopRequireDefault(require("store2"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /*******
|
|
15
|
+
* @description: 缓存工具
|
|
16
|
+
* @author: 琴时
|
|
17
|
+
*/
|
|
18
|
+
var _default = exports["default"] = _store["default"];
|
|
19
|
+
/*******
|
|
20
|
+
* @description: localStorage缓存
|
|
21
|
+
* get:获取缓存|set:设置缓存|remove:删除缓存
|
|
22
|
+
*/
|
|
23
|
+
var local = exports.local = _store["default"].local;
|
|
24
|
+
local.getItem = local.get;
|
|
25
|
+
local.setItem = local.set;
|
|
26
|
+
local.removeItem = local.remove;
|
|
27
|
+
/*******
|
|
28
|
+
* @description: sessionStorage缓存
|
|
29
|
+
* get:获取缓存|set:设置缓存|remove:删除缓存
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
var session = exports.session = _store["default"].session;
|
|
33
|
+
session.getItem = session.get;
|
|
34
|
+
session.setItem = session.set;
|
|
35
|
+
session.removeItem = session.remove;
|
|
36
|
+
/*******
|
|
37
|
+
* @description: 设置有效期信息
|
|
38
|
+
* @author: 琴时
|
|
39
|
+
* @param {Number} value [到期时间,单位毫秒] [默认30分钟]
|
|
40
|
+
*/
|
|
41
|
+
var setExpires = exports.setExpires = function setExpires() {
|
|
42
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 30 * 60 * 1000;
|
|
43
|
+
session.set('user_last_time', +new Date()); //最后一次设置缓存时间
|
|
44
|
+
session.set('user_expires', value); //设置到期时间,单位毫秒
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/*******
|
|
48
|
+
* @description: 获取有效期信息
|
|
49
|
+
* @author: 琴时
|
|
50
|
+
* @return {Boolean} true:未过期 false:已过期
|
|
51
|
+
*/
|
|
52
|
+
var getExpires = exports.getExpires = function getExpires() {
|
|
53
|
+
var lastTime = session.get('user_last_time'); //最后登录时间
|
|
54
|
+
var expires = session.get('user_expires'); //过期时间
|
|
55
|
+
if (!lastTime || !expires) return false; //无记录==>过期
|
|
56
|
+
var nowTime = +new Date(); // 当前时间戳
|
|
57
|
+
var times = nowTime - (lastTime + expires); // 剩余时间总毫秒数
|
|
58
|
+
return times < 0;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/*******
|
|
62
|
+
* @description: 移除有效期信息
|
|
63
|
+
* @author: 琴时
|
|
64
|
+
*/
|
|
65
|
+
var removeExpires = exports.removeExpires = function removeExpires() {
|
|
66
|
+
session.remove('user_last_time');
|
|
67
|
+
session.remove('user_expires');
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/*******
|
|
71
|
+
* @description: 获取cookie
|
|
72
|
+
* @author: 琴时
|
|
73
|
+
* @param {String} key
|
|
74
|
+
* @return {String}
|
|
75
|
+
*/
|
|
76
|
+
var getCookie = exports.getCookie = function getCookie(key) {
|
|
77
|
+
if (typeof document === 'undefined') return '';
|
|
78
|
+
var name = key + '=';
|
|
79
|
+
var ca = document.cookie.split(';');
|
|
80
|
+
for (var i = 0; i < ca.length; i++) {
|
|
81
|
+
var c = ca[i].trim();
|
|
82
|
+
if (c.indexOf(name) === 0) {
|
|
83
|
+
return c.substring(name.length, c.length);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return '';
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/*******
|
|
90
|
+
* @description: 获取所有cookie
|
|
91
|
+
* @author: 琴时
|
|
92
|
+
* @return {Array}
|
|
93
|
+
*/
|
|
94
|
+
var getCookies = exports.getCookies = function getCookies() {
|
|
95
|
+
var cookies = [];
|
|
96
|
+
if (typeof document === 'undefined') return cookies;
|
|
97
|
+
if (document.cookie.length === 0) return cookies;
|
|
98
|
+
var array = document.cookie.split('; '); //通过分号连空格将字符串切割成数组
|
|
99
|
+
cookies = array.map(function (item) {
|
|
100
|
+
var _item$split = item.split('='),
|
|
101
|
+
_item$split2 = _slicedToArray(_item$split, 2),
|
|
102
|
+
key = _item$split2[0],
|
|
103
|
+
value = _item$split2[1]; // 通过=再次切割
|
|
104
|
+
return {
|
|
105
|
+
key: key,
|
|
106
|
+
value: value
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
return cookies;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/*******
|
|
113
|
+
* @description: 设置cookie
|
|
114
|
+
* @author: 琴时
|
|
115
|
+
* @param {String} key [键名]
|
|
116
|
+
* @param {String} value [键值]
|
|
117
|
+
* @param {Number} day [有效期/天] | 不传默认当前会话有效
|
|
118
|
+
* @return {*}
|
|
119
|
+
*/
|
|
120
|
+
var setCookie = exports.setCookie = function setCookie(key, value, day) {
|
|
121
|
+
var cookie = key + '=' + value + '; path=/';
|
|
122
|
+
if (day != undefined) {
|
|
123
|
+
var d = new Date();
|
|
124
|
+
d.setTime(d.getTime() + day * 24 * 60 * 60 * 1000);
|
|
125
|
+
var expires = '; expires=' + d.toGMTString();
|
|
126
|
+
cookie += expires;
|
|
127
|
+
}
|
|
128
|
+
if (typeof document === 'undefined') return;
|
|
129
|
+
document.cookie = cookie;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/*******
|
|
133
|
+
* @description: 删除指定cookie
|
|
134
|
+
* @author: 琴时
|
|
135
|
+
* @param {*} key [指定cookies的键]
|
|
136
|
+
* @return {*}
|
|
137
|
+
*/
|
|
138
|
+
var removeCookie = exports.removeCookie = function removeCookie(key) {
|
|
139
|
+
setCookie(key, '', -1); // 将生命周期改为-1
|
|
140
|
+
};
|
|
141
|
+
/*******
|
|
142
|
+
* @description:删除所有cookie
|
|
143
|
+
* @author: 琴时
|
|
144
|
+
* @return {*}
|
|
145
|
+
*/
|
|
146
|
+
var removeCookies = exports.removeCookies = function removeCookies() {
|
|
147
|
+
getCookies().forEach(function (cookie) {
|
|
148
|
+
setCookie(cookie.key, '', -1); //将生命周期改为-1==>使其失效
|
|
149
|
+
});
|
|
150
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tools-for-js",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "基于babel构建的
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "基于babel构建的JavaScript前端工具库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"start": "nodemon",
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
"url": "https://github.com/kimshift/tools-for-js/issues"
|
|
17
17
|
},
|
|
18
18
|
"keywords": [
|
|
19
|
-
"
|
|
20
|
-
"tools"
|
|
19
|
+
"web",
|
|
20
|
+
"tools",
|
|
21
|
+
"JavaScript"
|
|
21
22
|
],
|
|
22
23
|
"author": "kimshift",
|
|
23
24
|
"license": "ISC",
|
|
@@ -33,7 +34,8 @@
|
|
|
33
34
|
"nodemon": "^3.1.0"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"dayjs": "^1.11.11"
|
|
37
|
+
"dayjs": "^1.11.11",
|
|
38
|
+
"store2": "^2.14.3"
|
|
37
39
|
},
|
|
38
40
|
"volta": {
|
|
39
41
|
"node": "20.12.2"
|