xctc-utils 1.5.3 → 1.5.4
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/dist/format/index.js +1 -0
- package/dist/mobile/index.js +1 -0
- package/dist/storage/index.d.ts +24 -0
- package/dist/storage/index.js +36 -0
- package/dist/time/index.js +9 -3
- package/package.json +1 -1
package/dist/format/index.js
CHANGED
package/dist/mobile/index.js
CHANGED
package/dist/storage/index.d.ts
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param key 需要存储的数据key值
|
|
4
|
+
* @param value 需要存储的数据
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
1
7
|
export declare function useLocalStorage(key: string, value: any): false | undefined;
|
|
2
8
|
export declare function getLocalStorage(key: string): any;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param key 需要存储的数据key值
|
|
12
|
+
* @param value 需要存储的数据
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
3
15
|
export declare function useSessionStorage(key: string, value: any): false | undefined;
|
|
4
16
|
export declare function getSessionStorage(key: string): any;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param key 需要删除的key值
|
|
20
|
+
* @param isAll 是否删除所有缓存
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
5
23
|
export declare function removeSessionStorage(key?: string, isAll?: boolean): void;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param key 需要删除的key值
|
|
27
|
+
* @param isAll 是否删除所有缓存
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
6
30
|
export declare function removeLocalStorage(key?: string, isAll?: boolean): void;
|
package/dist/storage/index.js
CHANGED
|
@@ -5,6 +5,12 @@ var is_1 = require("../is");
|
|
|
5
5
|
var wls = window.localStorage;
|
|
6
6
|
var wss = window.sessionStorage;
|
|
7
7
|
var utils_1 = require("../utils");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param key 需要存储的数据key值
|
|
11
|
+
* @param value 需要存储的数据
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
8
14
|
function useLocalStorage(key, value) {
|
|
9
15
|
if (!key || !value) {
|
|
10
16
|
console.log("useLocalStorage存储时缺少key:value");
|
|
@@ -19,6 +25,12 @@ function getLocalStorage(key) {
|
|
|
19
25
|
return getStorage(key, wls);
|
|
20
26
|
}
|
|
21
27
|
exports.getLocalStorage = getLocalStorage;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @param key 需要存储的数据key值
|
|
31
|
+
* @param value 需要存储的数据
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
22
34
|
function useSessionStorage(key, value) {
|
|
23
35
|
if (!key || !value) {
|
|
24
36
|
console.log("useSessionStorage存储时缺少key:value");
|
|
@@ -33,6 +45,12 @@ function getSessionStorage(key) {
|
|
|
33
45
|
return getStorage(key, wss);
|
|
34
46
|
}
|
|
35
47
|
exports.getSessionStorage = getSessionStorage;
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param key 需要存储的数据key值
|
|
51
|
+
* @param value 需要存储的数据
|
|
52
|
+
* @param obj localStorage或者sessionStorage对象
|
|
53
|
+
*/
|
|
36
54
|
function useStorage(key, value, obj) {
|
|
37
55
|
if (value instanceof Object) {
|
|
38
56
|
obj.setItem(key, JSON.stringify(value));
|
|
@@ -41,6 +59,12 @@ function useStorage(key, value, obj) {
|
|
|
41
59
|
obj.setItem(key, value);
|
|
42
60
|
}
|
|
43
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
*
|
|
64
|
+
* @param key 需要获取的数据key值
|
|
65
|
+
* @param obj localStorage或者sessionStorage对象
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
44
68
|
function getStorage(key, obj) {
|
|
45
69
|
var val = obj.getItem(key);
|
|
46
70
|
if (val == 'undefined' || val == null) {
|
|
@@ -51,6 +75,12 @@ function getStorage(key, obj) {
|
|
|
51
75
|
val = data;
|
|
52
76
|
return val;
|
|
53
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param key 需要删除的key值
|
|
81
|
+
* @param isAll 是否删除所有缓存
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
54
84
|
function removeSessionStorage(key, isAll) {
|
|
55
85
|
if ((0, is_1.isBoolean)(isAll) && isAll) {
|
|
56
86
|
wss.clear();
|
|
@@ -61,6 +91,12 @@ function removeSessionStorage(key, isAll) {
|
|
|
61
91
|
removeStorage(key, wss);
|
|
62
92
|
}
|
|
63
93
|
exports.removeSessionStorage = removeSessionStorage;
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @param key 需要删除的key值
|
|
97
|
+
* @param isAll 是否删除所有缓存
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
64
100
|
function removeLocalStorage(key, isAll) {
|
|
65
101
|
if ((0, is_1.isBoolean)(isAll) && isAll) {
|
|
66
102
|
wls.clear();
|
package/dist/time/index.js
CHANGED
|
@@ -19,6 +19,7 @@ exports.getTime = getTime;
|
|
|
19
19
|
function formatTimeStamp(num, format) {
|
|
20
20
|
if (!format)
|
|
21
21
|
format = "YYYY-MM-DD HH:mm:ss";
|
|
22
|
+
num = Number(num); // 先将数据转换为数据类型
|
|
22
23
|
if (!num)
|
|
23
24
|
return "";
|
|
24
25
|
// 传入秒 时间戳
|
|
@@ -70,8 +71,13 @@ function isExist(str, key) {
|
|
|
70
71
|
function formatStrTime(str) {
|
|
71
72
|
if (!str)
|
|
72
73
|
return "";
|
|
73
|
-
var
|
|
74
|
-
timestamp =
|
|
75
|
-
|
|
74
|
+
var strDate = new Date(str);
|
|
75
|
+
var timestamp = "";
|
|
76
|
+
if (strDate) {
|
|
77
|
+
timestamp = strDate.getTime();
|
|
78
|
+
timestamp = timestamp / 1000;
|
|
79
|
+
return parseInt(timestamp);
|
|
80
|
+
}
|
|
81
|
+
return "";
|
|
76
82
|
}
|
|
77
83
|
exports.formatStrTime = formatStrTime;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xctc-utils",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|