xctc-utils 1.3.4 → 1.3.6

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
@@ -6,10 +6,8 @@
6
6
 
7
7
  #### LocalStorage使用,存取值时数据已经过处理
8
8
  ```
9
-
10
9
  存储: utils.useLocalStorage(key,value)
11
10
  取值: utils.getLocalStorage(key)
12
-
13
11
  ```
14
12
 
15
13
  #### sessionStorage使用,存取值时数据已经过处理
@@ -19,7 +17,26 @@
19
17
  取值: utils.getSessionStorage(key)
20
18
 
21
19
  ```
20
+ #### 删除缓存
21
+ ```
22
+ key:string 需要删除的缓存键
23
+ isAll:boolean 为true时删除调用方法的所有缓存,否则只删除当前传入的 key 值
24
+ 如果 isAll 为 true 时,方法会优先执行缓存的clear函数, key 传任意值,
25
+ 删除临时缓存: utils.removeSessionStorage(key,isAll)
26
+ 删除永久缓存: utils.removeLocalStorage(key,isAll)
22
27
 
28
+ ```
29
+ #### 类型判断
30
+ ```
31
+ utils.type.isFunction(val) // 是否是函数
32
+ utils.type.isObject(val) // 是否是对象 null 类型为对象,该方法已对null进行过滤
33
+ utils.type.isDate(val) // 是否是时间对象
34
+ utils.type.isNumber(val) // 是否是number类型
35
+ utils.type.isString(val) // 是否是字符串类型
36
+ utils.type.isBoolean(val) // 是否是boolean类型
37
+ utils.type.isWindow(val) // 是否在浏览器环境下运行
38
+
39
+ ```
23
40
  #### 获取当前设备环境
24
41
  设备环境:
25
42
  ```
@@ -31,13 +48,15 @@
31
48
  ```
32
49
 
33
50
 
34
- #### 加密解密方法
51
+ #### crypto-js 加密解密方法
35
52
  ```
36
53
  word: 需要加密的数据,数据可是字符串,对象等
37
54
  key: 加密 密钥
38
55
  iv: 密钥偏移量
39
56
  对同一个数据进行加密、解密时,encrypt和decrypt的iv和key保持一致
40
- 对数据进行加密
57
+ 对word进行CryptoJS.enc.Utf8.parse转义
58
+ CryptoJS.AES.encrypt加密,加密模式:CBC ; padding: CryptoJS.pad.Pkcs7
59
+ 对数据进行加密
41
60
  utils.encrypt(word:any,key:any,iv:any)
42
61
  // 对数据进行解密
43
62
  utils.decrypt(word:any,key:any,iv:any)
@@ -0,0 +1,2 @@
1
+ export declare function makePhone(tel: string): void;
2
+ export declare function formatMobile(mobile: string): string | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatMobile = exports.makePhone = void 0;
4
+ // h5页面拨打电话
5
+ function makePhone(tel) {
6
+ if (tel) {
7
+ window.location.href = "tel://".concat(tel);
8
+ }
9
+ }
10
+ exports.makePhone = makePhone;
11
+ function formatMobile(mobile) {
12
+ if (!mobile)
13
+ return;
14
+ return mobile.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
15
+ }
16
+ exports.formatMobile = formatMobile;
package/dist/index.js CHANGED
@@ -40,5 +40,7 @@ var crypto = __importStar(require("./crypto"));
40
40
  var weixin = __importStar(require("./weixin"));
41
41
  var time = __importStar(require("./time"));
42
42
  var mobile = __importStar(require("./mobile"));
43
- var obj = __assign(__assign(__assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto), time), mobile);
43
+ var format = __importStar(require("./format"));
44
+ var is = __importStar(require("./is"));
45
+ var obj = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto), time), mobile), format), { type: __assign({}, is) });
44
46
  exports.default = obj;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @description: 判断传入的值是否为指定类型
3
+ */
4
+ export declare function is(val: unknown, type: string): boolean;
5
+ /**
6
+ * @description: 是否为函数
7
+ */
8
+ export declare function isFunction<T = Function>(val: unknown): val is T;
9
+ /**
10
+ * @description: 是否为对象
11
+ */
12
+ export declare const isObject: (val: any) => val is Record<any, any>;
13
+ /**
14
+ * @description: 是否为时间对象
15
+ */
16
+ export declare function isDate(val: unknown): val is Date;
17
+ /**
18
+ * @description: 是否为number类型
19
+ */
20
+ export declare function isNumber(val: unknown): val is number;
21
+ /**
22
+ * @description: 是否为字符串
23
+ */
24
+ export declare function isString(val: unknown): val is string;
25
+ /**
26
+ * @description: 是否为boolean类型
27
+ */
28
+ export declare function isBoolean(val: unknown): val is boolean;
29
+ /**
30
+ * @description: 是否为数组
31
+ */
32
+ export declare function isArray(val: any): val is Array<any>;
33
+ /**
34
+ * @description: 是否为浏览器
35
+ */
36
+ export declare const isWindow: (val: any) => val is Window;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWindow = exports.isArray = exports.isBoolean = exports.isString = exports.isNumber = exports.isDate = exports.isObject = exports.isFunction = exports.is = void 0;
4
+ var toString = Object.prototype.toString;
5
+ /**
6
+ * @description: 判断传入的值是否为指定类型
7
+ */
8
+ function is(val, type) {
9
+ if (!type)
10
+ return false;
11
+ return toString.call(val) === "[object ".concat(type, "]");
12
+ }
13
+ exports.is = is;
14
+ /**
15
+ * @description: 是否为函数
16
+ */
17
+ function isFunction(val) {
18
+ if (!val)
19
+ return false;
20
+ return is(val, "Function");
21
+ }
22
+ exports.isFunction = isFunction;
23
+ /**
24
+ * @description: 是否为对象
25
+ */
26
+ var isObject = function (val) {
27
+ return val !== null && is(val, "Object");
28
+ };
29
+ exports.isObject = isObject;
30
+ /**
31
+ * @description: 是否为时间对象
32
+ */
33
+ function isDate(val) {
34
+ if (!val)
35
+ return false;
36
+ return is(val, "Date");
37
+ }
38
+ exports.isDate = isDate;
39
+ /**
40
+ * @description: 是否为number类型
41
+ */
42
+ function isNumber(val) {
43
+ return is(val, "Number");
44
+ }
45
+ exports.isNumber = isNumber;
46
+ /**
47
+ * @description: 是否为字符串
48
+ */
49
+ function isString(val) {
50
+ return is(val, "String");
51
+ }
52
+ exports.isString = isString;
53
+ /**
54
+ * @description: 是否为boolean类型
55
+ */
56
+ function isBoolean(val) {
57
+ return is(val, "Boolean");
58
+ }
59
+ exports.isBoolean = isBoolean;
60
+ /**
61
+ * @description: 是否为数组
62
+ */
63
+ function isArray(val) {
64
+ return val && Array.isArray(val);
65
+ }
66
+ exports.isArray = isArray;
67
+ /**
68
+ * @description: 是否为浏览器
69
+ */
70
+ var isWindow = function (val) {
71
+ return typeof window !== "undefined" && is(val, "Window");
72
+ };
73
+ exports.isWindow = isWindow;
@@ -2,3 +2,5 @@ export declare function useLocalStorage(key: string, value: any): false | undefi
2
2
  export declare function getLocalStorage(key: string): any;
3
3
  export declare function useSessionStorage(key: string, value: any): false | undefined;
4
4
  export declare function getSessionStorage(key: string): any;
5
+ export declare function removeSessionStorage(key?: string, isAll?: boolean): void;
6
+ export declare function removeLocalStorage(key?: string, isAll?: boolean): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSessionStorage = exports.useSessionStorage = exports.getLocalStorage = exports.useLocalStorage = void 0;
3
+ exports.removeLocalStorage = exports.removeSessionStorage = exports.getSessionStorage = exports.useSessionStorage = exports.getLocalStorage = exports.useLocalStorage = void 0;
4
+ var is_1 = require("../is");
4
5
  var wls = window.localStorage;
5
6
  var wss = window.sessionStorage;
6
7
  var utils_1 = require("../utils");
@@ -50,3 +51,26 @@ function getStorage(key, obj) {
50
51
  val = data;
51
52
  return val;
52
53
  }
54
+ function removeSessionStorage(key, isAll) {
55
+ if ((0, is_1.isBoolean)(isAll) && isAll) {
56
+ wss.clear();
57
+ return;
58
+ }
59
+ if (!key)
60
+ return;
61
+ removeStorage(key, wss);
62
+ }
63
+ exports.removeSessionStorage = removeSessionStorage;
64
+ function removeLocalStorage(key, isAll) {
65
+ if ((0, is_1.isBoolean)(isAll) && isAll) {
66
+ wls.clear();
67
+ return;
68
+ }
69
+ if (!key)
70
+ return;
71
+ removeStorage(key, wls);
72
+ }
73
+ exports.removeLocalStorage = removeLocalStorage;
74
+ function removeStorage(key, obj) {
75
+ obj.removeItem(key);
76
+ }
@@ -11,4 +11,4 @@ export declare function formatTimeStamp(num?: number, format?: string): string;
11
11
  * @param str 字符串格式必须为: 2017/03/03 12:23:55 格式,避免兼容性,不能传 “ - ” 分割的时间字符串 2017-03-03
12
12
  * @returns
13
13
  */
14
- export declare function formatStrTime(str: string): number | undefined;
14
+ export declare function formatStrTime(str: string): any;
@@ -69,7 +69,7 @@ function isExist(str, key) {
69
69
  */
70
70
  function formatStrTime(str) {
71
71
  if (!str)
72
- return;
72
+ return "";
73
73
  var timestamp = new Date(str).getTime();
74
74
  timestamp = timestamp / 1000;
75
75
  return parseInt(timestamp);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.3.4",
3
+ "version": "1.3.6",
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",