@base-web-kits/base-tools-web 0.8.7 → 0.8.9
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 +43 -32
- package/dist/index.cjs +16 -11
- package/dist/index.js +16 -11
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +26 -22
package/README.md
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
|
-
# Base Tools
|
|
2
|
-
|
|
3
|
-
web前端团队常用工具库,包含`ts`、`web`、`react`、`vue`、`uni`模块。
|
|
4
|
-
|
|
5
|
-
**安装**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
# Base Tools
|
|
2
|
+
|
|
3
|
+
web前端团队常用工具库,包含`ts`、`web`、`react`、`vue`、`uni`模块。
|
|
4
|
+
|
|
5
|
+
**安装**
|
|
6
|
+
|
|
7
|
+
按需安装即可,模块之间不相互依赖
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
// 通用 TS 模块
|
|
11
|
+
npm i @base-web-kits/base-tools-ts
|
|
12
|
+
|
|
13
|
+
// Web 模块
|
|
14
|
+
npm i @base-web-kits/base-tools-web
|
|
15
|
+
|
|
16
|
+
// React 模块
|
|
17
|
+
npm i @base-web-kits/base-tools-react
|
|
18
|
+
|
|
19
|
+
// Vue 模块
|
|
20
|
+
npm i @base-web-kits/base-tools-vue
|
|
21
|
+
|
|
22
|
+
// Uni 模块
|
|
23
|
+
npm i @base-web-kits/base-tools-uni
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**快速使用**
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// 通用 TS 模块
|
|
30
|
+
import { toDayjs, getUrlParam, toMaskPhone } from '@base-web-kits/base-tools-ts';
|
|
31
|
+
|
|
32
|
+
// Web 模块
|
|
33
|
+
import { copyText, isPC, download, setCookie } from '@base-web-kits/base-tools-web';
|
|
34
|
+
|
|
35
|
+
// React 模块
|
|
36
|
+
import { useCountDown } from '@base-web-kits/base-tools-react';
|
|
37
|
+
|
|
38
|
+
// Vue 模块
|
|
39
|
+
import { useResizeObserver } from '@base-web-kits/base-tools-vue';
|
|
40
|
+
|
|
41
|
+
// Uni 模块
|
|
42
|
+
import { chooseMedia, toPayWx } from '@base-web-kits/base-tools-uni';
|
|
43
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -407,6 +407,11 @@ function preloadImage(src) {
|
|
|
407
407
|
}
|
|
408
408
|
|
|
409
409
|
// src/web/storage/index.ts
|
|
410
|
+
var WK = {
|
|
411
|
+
val: "__l_val",
|
|
412
|
+
exp: "__l_exp",
|
|
413
|
+
wrap: "__l_wrap"
|
|
414
|
+
};
|
|
410
415
|
function setLocalStorage(key, value, days) {
|
|
411
416
|
if (value === void 0 || value === null) {
|
|
412
417
|
removeLocalStorage(key);
|
|
@@ -414,8 +419,12 @@ function setLocalStorage(key, value, days) {
|
|
|
414
419
|
}
|
|
415
420
|
let toStore = value;
|
|
416
421
|
if (typeof days === "number" && days > 0) {
|
|
417
|
-
const ms =
|
|
418
|
-
toStore = {
|
|
422
|
+
const ms = days * 24 * 60 * 60 * 1e3;
|
|
423
|
+
toStore = {
|
|
424
|
+
[WK.wrap]: true,
|
|
425
|
+
[WK.val]: value,
|
|
426
|
+
[WK.exp]: Date.now() + ms
|
|
427
|
+
};
|
|
419
428
|
}
|
|
420
429
|
localStorage.setItem(key, JSON.stringify(toStore));
|
|
421
430
|
}
|
|
@@ -424,16 +433,12 @@ function getLocalStorage(key) {
|
|
|
424
433
|
if (raw === null) return null;
|
|
425
434
|
try {
|
|
426
435
|
const parsed = JSON.parse(raw);
|
|
427
|
-
if (parsed && typeof parsed === "object") {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
if (typeof exp === "number" && Date.now() >= exp) {
|
|
432
|
-
removeLocalStorage(key);
|
|
433
|
-
return null;
|
|
434
|
-
}
|
|
435
|
-
return obj.__l_val;
|
|
436
|
+
if (parsed && typeof parsed === "object" && WK.wrap in parsed && WK.exp in parsed) {
|
|
437
|
+
if (Date.now() > parsed[WK.exp]) {
|
|
438
|
+
removeLocalStorage(key);
|
|
439
|
+
return null;
|
|
436
440
|
}
|
|
441
|
+
return parsed[WK.val];
|
|
437
442
|
}
|
|
438
443
|
return parsed;
|
|
439
444
|
} catch {
|
package/dist/index.js
CHANGED
|
@@ -339,6 +339,11 @@ function preloadImage(src) {
|
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
// src/web/storage/index.ts
|
|
342
|
+
var WK = {
|
|
343
|
+
val: "__l_val",
|
|
344
|
+
exp: "__l_exp",
|
|
345
|
+
wrap: "__l_wrap"
|
|
346
|
+
};
|
|
342
347
|
function setLocalStorage(key, value, days) {
|
|
343
348
|
if (value === void 0 || value === null) {
|
|
344
349
|
removeLocalStorage(key);
|
|
@@ -346,8 +351,12 @@ function setLocalStorage(key, value, days) {
|
|
|
346
351
|
}
|
|
347
352
|
let toStore = value;
|
|
348
353
|
if (typeof days === "number" && days > 0) {
|
|
349
|
-
const ms =
|
|
350
|
-
toStore = {
|
|
354
|
+
const ms = days * 24 * 60 * 60 * 1e3;
|
|
355
|
+
toStore = {
|
|
356
|
+
[WK.wrap]: true,
|
|
357
|
+
[WK.val]: value,
|
|
358
|
+
[WK.exp]: Date.now() + ms
|
|
359
|
+
};
|
|
351
360
|
}
|
|
352
361
|
localStorage.setItem(key, JSON.stringify(toStore));
|
|
353
362
|
}
|
|
@@ -356,16 +365,12 @@ function getLocalStorage(key) {
|
|
|
356
365
|
if (raw === null) return null;
|
|
357
366
|
try {
|
|
358
367
|
const parsed = JSON.parse(raw);
|
|
359
|
-
if (parsed && typeof parsed === "object") {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (typeof exp === "number" && Date.now() >= exp) {
|
|
364
|
-
removeLocalStorage(key);
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
return obj.__l_val;
|
|
368
|
+
if (parsed && typeof parsed === "object" && WK.wrap in parsed && WK.exp in parsed) {
|
|
369
|
+
if (Date.now() > parsed[WK.exp]) {
|
|
370
|
+
removeLocalStorage(key);
|
|
371
|
+
return null;
|
|
368
372
|
}
|
|
373
|
+
return parsed[WK.val];
|
|
369
374
|
}
|
|
370
375
|
return parsed;
|
|
371
376
|
} catch {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web/storage/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/web/storage/index.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,QAiBzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAiBlE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,QAE7C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@base-web-kits/base-tools-web",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.8.9",
|
|
5
4
|
"sideEffects": false,
|
|
6
5
|
"description": "Independent Web utilities package built from src/web.",
|
|
7
6
|
"keywords": [
|
|
@@ -11,25 +10,33 @@
|
|
|
11
10
|
"thin-wrapper"
|
|
12
11
|
],
|
|
13
12
|
"license": "MIT",
|
|
14
|
-
"main": "./
|
|
15
|
-
"module": "./
|
|
16
|
-
"types": "./
|
|
13
|
+
"main": "./index.js",
|
|
14
|
+
"module": "./index.js",
|
|
15
|
+
"types": "./index.d.ts",
|
|
17
16
|
"exports": {
|
|
18
17
|
".": {
|
|
19
|
-
"types":
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
18
|
+
"types": "./index.d.ts",
|
|
19
|
+
"import": "./index.js",
|
|
20
|
+
"require": "./index.cjs",
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
},
|
|
23
|
+
"./index": {
|
|
24
|
+
"types": "./index.d.ts",
|
|
25
|
+
"import": "./index.js",
|
|
26
|
+
"require": "./index.cjs",
|
|
27
|
+
"default": "./index.js"
|
|
28
|
+
},
|
|
29
|
+
"./index.js": {
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"import": "./index.js",
|
|
32
|
+
"require": "./index.cjs",
|
|
33
|
+
"default": "./index.js"
|
|
34
|
+
},
|
|
35
|
+
"./dist/*": {
|
|
36
|
+
"types": "./dist/*.d.ts",
|
|
37
|
+
"import": "./dist/*.js",
|
|
38
|
+
"require": "./dist/*.cjs",
|
|
39
|
+
"default": "./dist/*.js"
|
|
33
40
|
},
|
|
34
41
|
"./package.json": "./package.json"
|
|
35
42
|
},
|
|
@@ -48,9 +55,6 @@
|
|
|
48
55
|
"README.md"
|
|
49
56
|
],
|
|
50
57
|
"dependencies": {},
|
|
51
|
-
"scripts": {
|
|
52
|
-
"prepublishOnly": "cd ../.. && npm run build"
|
|
53
|
-
},
|
|
54
58
|
"publishConfig": {
|
|
55
59
|
"registry": "https://registry.npmjs.org"
|
|
56
60
|
}
|