@base-web-kits/base-tools-web 0.8.6 → 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 CHANGED
@@ -1,32 +1,43 @@
1
- # Base Tools
2
-
3
- web前端团队常用工具库,包含`ts`、`web`、`react`、`vue`、`uni`模块。
4
-
5
- **安装**
6
-
7
- 用哪个模块就安装哪个,模块之间不会相互依赖
8
-
9
- - `npm i @base-web-kits/base-tools-ts`
10
- - `npm i @base-web-kits/base-tools-web`
11
- - `npm i @base-web-kits/base-tools-react`
12
- - `npm i @base-web-kits/base-tools-vue`
13
- - `npm i @base-web-kits/base-tools-uni`
14
-
15
- **快速使用**
16
-
17
- ```ts
18
- // 通用 TS 模块
19
- import { toDayjs, getUrlParam, toMaskPhone } from '@base-web-kits/base-tools-ts';
20
-
21
- // Web 模块
22
- import { copyText, isPC, download, setCookie } from '@base-web-kits/base-tools-web';
23
-
24
- // React 模块
25
- import { useCountDown } from '@base-web-kits/base-tools-react';
26
-
27
- // Vue 模块
28
- import { useResizeObserver } from '@base-web-kits/base-tools-vue';
29
-
30
- // Uni 模块
31
- import { chooseMedia, toPayWx } from '@base-web-kits/base-tools-uni';
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 = Math.floor(days * 24 * 60 * 60 * 1e3);
418
- toStore = { __l_val: value, __l_exp: Date.now() + ms };
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
- const obj = parsed;
429
- if ("__l_exp" in obj && "__l_val" in obj) {
430
- const exp = obj.__l_exp;
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 = Math.floor(days * 24 * 60 * 60 * 1e3);
350
- toStore = { __l_val: value, __l_exp: Date.now() + ms };
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
- const obj = parsed;
361
- if ("__l_exp" in obj && "__l_val" in obj) {
362
- const exp = obj.__l_exp;
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":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,QAWzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI,CAoBlE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,QAE7C"}
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.6",
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": "./dist/index.cjs",
15
- "module": "./dist/index.js",
16
- "types": "./dist/index.d.ts",
13
+ "main": "./index.js",
14
+ "module": "./index.js",
15
+ "types": "./index.d.ts",
17
16
  "exports": {
18
17
  ".": {
19
- "types": {
20
- "import": "./dist/index.d.ts",
21
- "require": "./dist/index.d.ts",
22
- "default": "./dist/index.d.ts"
23
- },
24
- "import": {
25
- "types": "./dist/index.d.ts",
26
- "default": "./dist/index.js"
27
- },
28
- "require": {
29
- "types": "./dist/index.d.ts",
30
- "default": "./dist/index.cjs"
31
- },
32
- "default": "./dist/index.js"
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
  },