xctc-utils 1.5.2 → 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.
@@ -8,6 +8,7 @@ function makePhone(tel) {
8
8
  }
9
9
  }
10
10
  exports.makePhone = makePhone;
11
+ // 将手机号后四位转换为***
11
12
  function formatMobile(mobile) {
12
13
  if (!mobile)
13
14
  return;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isMobile = void 0;
4
4
  var w = window;
5
+ // 是否是手机端环境
5
6
  function isMobile() {
6
7
  var info = w.navigator.userAgent;
7
8
  var isPhone = /mobile/i.test(info);
@@ -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;
@@ -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();
@@ -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 timestamp = new Date(str).getTime();
74
- timestamp = timestamp / 1000;
75
- return parseInt(timestamp);
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;
@@ -29,6 +29,7 @@ interface ShareOptions {
29
29
  data?: any;
30
30
  iv?: string;
31
31
  key?: string;
32
+ shareUrl?: string;
32
33
  }
33
34
  export declare function weixinShareInit(options: ShareOptions): void;
34
35
  /**
@@ -328,6 +328,8 @@ function weixinShareInit(options) {
328
328
  link = "".concat(link, "?state=").concat(state);
329
329
  }
330
330
  }
331
+ if (options['shareUrl'])
332
+ link = options['shareUrl'];
331
333
  var wx = weixinInit();
332
334
  (0, index_1.useSessionStorage)("weixinShareUrl", link);
333
335
  wx.ready(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.5.2",
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",