xctc-utils 1.5.9 → 1.6.1

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
@@ -4,7 +4,7 @@
4
4
  #### 更新到最新版本 npm install xctc-utils@latest
5
5
  #### 项目中引入 import useUtils from "xctc-utils"
6
6
 
7
-
7
+ ### 缓存操作集合
8
8
  #### LocalStorage使用,存取值时数据已经过处理
9
9
  ```
10
10
  存储: useUtils.useLocalStorage(key,value)
@@ -19,10 +19,6 @@
19
19
 
20
20
  ```
21
21
 
22
- #### 将数据复制到剪贴板函数
23
- ```
24
- useUtils.handleCopyValue(val)
25
- ```
26
22
  #### 删除缓存
27
23
  ```
28
24
  key:string 需要删除的缓存键
@@ -32,6 +28,13 @@ isAll:boolean 为true时删除调用方法的所有缓存,否则只删除当
32
28
  删除永久缓存: useUtils.removeLocalStorage(key,isAll)
33
29
 
34
30
  ```
31
+
32
+ ### 剪贴板操作集合
33
+ #### 将数据复制到剪贴板函数
34
+ ```
35
+ useUtils.handleCopyValue(val)
36
+ ```
37
+ ### AES 加密、解密处理函数集合
35
38
  #### AES 加密、解密,同一个数据的加密和解密传入的key 和 iv保持一致。
36
39
  ```
37
40
  work: 需要加密的对象,如传入的是对象,该方法默认进行JSON序列化处理。
@@ -41,7 +44,8 @@ data: encrypt方法加密后返回的数据
41
44
  加密:useUtils.encrypt( work:any , key:string , iv:string )
42
45
  解密:useUtils.decrypt( data:string , key:string , iv:string )
43
46
  ```
44
- #### 类型判断
47
+ ### 数据类型判断集合
48
+ #### 数据类型判断
45
49
  ```
46
50
  useUtils.type.isFunction(val) // 是否是函数
47
51
  useUtils.type.isObject(val) // 是否是对象 null 类型为对象,该方法已对null进行过滤
@@ -52,34 +56,22 @@ useUtils.type.isBoolean(val) // 是否是boolean类型
52
56
  useUtils.type.isWindow(val) // 是否在浏览器环境下运行
53
57
 
54
58
  ```
59
+ #### json数据类型判断
60
+ ```
61
+ useUtils.isJson(data) // 判断传入数据是否是 JSON对象字符串,如果是,返回序列化后的JSON对象,否则返回false
62
+ ```
63
+ ### 环境判断
55
64
  #### 获取当前设备环境
56
65
  设备环境:
57
66
  ```
58
67
 
59
- 当前使用设备类型: useUtils.deviceEnvironment() // android ios
68
+ 当前使用设备类型: useUtils.deviceEnvironment() // android ios ,未识别到返回 other
60
69
  是否在微信浏览器环境中: useUtils.weixinBrowser() // true false
61
70
  是否是手持设备: useUtils.isMobile() // true 移动设备 false PC设备
62
71
 
63
72
  ```
64
-
65
-
66
- #### crypto-js 加密解密方法
67
- ```
68
- word: 需要加密的数据,数据可是字符串,对象等
69
- key: 加密 密钥
70
- iv: 密钥偏移量
71
- data:encrypt方法加密后返回的数据
72
- 对同一个数据进行加密、解密时,encrypt和decrypt的iv和key保持一致
73
- 对word进行CryptoJS.enc.Utf8.parse转义
74
- CryptoJS.AES.encrypt加密,加密模式:CBC ; padding: CryptoJS.pad.Pkcs7
75
- 对数据进行加密
76
- useUtils.encrypt(word:any,key:string,iv:string)
77
- // 对数据进行解密
78
- useUtils.decrypt(data:string,key:string,iv:string)
79
-
80
- ```
81
- #### 微信H5使用方法集合
82
- ##### 微信授权登录
73
+ ### 微信授权等方法集合
74
+ #### 微信授权登录
83
75
  ```
84
76
  interface configOption {
85
77
  appId?:string, // 当前微信服务号 appId
@@ -123,9 +115,7 @@ useUtils.weixinShareInit(config:Share)
123
115
  ### 时间相关方法
124
116
  #### 获取当前时间的时间戳
125
117
  ```
126
-
127
118
  useUtils.getTime() // 返回秒
128
-
129
119
  ```
130
120
  #### 时间戳转任意格式时间字符串
131
121
  ```
@@ -147,4 +137,42 @@ useUtils.formatTimeStamp(num,format) // 返回 format 格式时间戳
147
137
  */
148
138
  useUtils.formatStrTime(str) // 返回时间戳 秒
149
139
 
150
- ```
140
+ ```
141
+
142
+ ### DOM处理集合
143
+ #### 获取ID元素
144
+ ```
145
+ useUtils.$id("domid") // 如果存在当前dom元素,则返回dom对象,否则返回false
146
+ ```
147
+ ### ueditor 富文本操作函数集合
148
+ #### 计算当前富文本内容高度
149
+ ```
150
+ var option = {
151
+ id:"ueditor" , // 富文本DOM容器 id
152
+ content:"" , // ueditor 富文本内容
153
+ }
154
+ // 返回的富文本内容包含input dom元素,input元素的content-data-height属性计算富文本高度
155
+ // <input type="hidden" content-data-height="${height}" id="ueditorHeight" />
156
+ useUtils.checkIframeContentHeight(option)
157
+ ```
158
+ #### 获取指定富文本内容高度
159
+ ```
160
+ // 返回富文本元素所占页面高度,默认返回 0
161
+ useUtils.getIframeContentHeight("ueditor")
162
+ ```
163
+ ### 其它处理函数集合
164
+ #### 通过身份证号码的出生年月日,获取出生日期
165
+ ```
166
+ // 传入身份证号码,返回出生具体时间,默认返回空
167
+ 正确返回: {
168
+ year:year,
169
+ month:month,
170
+ day:day,
171
+ hour:hour,
172
+ minute:minute,
173
+ second:second,
174
+ num:nowNumber // 具体时间戳
175
+ }
176
+ useUtils.findIdcardAge(idcard)
177
+ ```
178
+
@@ -11,7 +11,7 @@ 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): any;
14
+ export declare function formatStrTime(str: string, format?: string): any;
15
15
  /**
16
16
  * 2018-12-28 15:00:00
17
17
  * 2018/12/28 15:00:00
@@ -35,7 +35,7 @@ export declare function getDateData(value: string | number, format?: string): {
35
35
  * @param idcard 身份证号码
36
36
  * @returns
37
37
  */
38
- export declare function findIdcardAge(idcard: string): void | {
38
+ export declare function findIdcardAge(idcard: string): "" | {
39
39
  year: string | number;
40
40
  month: string | number;
41
41
  day: string | number;
@@ -70,17 +70,11 @@ function isExist(str, key) {
70
70
  * @param str 字符串格式必须为: 2017/03/03 12:23:55 格式,避免兼容性,不能传 “ - ” 分割的时间字符串 2017-03-03
71
71
  * @returns
72
72
  */
73
- function formatStrTime(str) {
73
+ function formatStrTime(str, format) {
74
+ var _a;
74
75
  if (!str)
75
76
  return "";
76
- var strDate = new Date(str);
77
- var timestamp = "";
78
- if (strDate) {
79
- timestamp = strDate.getTime();
80
- timestamp = timestamp / 1000;
81
- return parseInt(timestamp);
82
- }
83
- return "";
77
+ return (_a = getDateData(str, format)) === null || _a === void 0 ? void 0 : _a.num;
84
78
  }
85
79
  exports.formatStrTime = formatStrTime;
86
80
  // 获取当前时间的 年月日时分秒对象
@@ -121,6 +115,7 @@ function getDateData(value, format) {
121
115
  year = value.substring(0, 4);
122
116
  var str = "".concat(year);
123
117
  var monthIndex = format.indexOf("MM");
118
+ console.log("monthIndex==", monthIndex);
124
119
  if (monthIndex != -1) {
125
120
  month = value.substring(monthIndex, monthIndex + 2) || "01";
126
121
  str = "".concat(str, "/").concat(month);
@@ -187,7 +182,8 @@ exports.getDateData = getDateData;
187
182
  */
188
183
  function findIdcardAge(idcard) {
189
184
  if (!idcard || idcard.length < 15) {
190
- return console.error("传入正确的身份证号码");
185
+ console.error("传入正确的身份证号码");
186
+ return "";
191
187
  }
192
188
  // 提取身份证号中的出生日期部分
193
189
  var birthday = idcard.substring(6, 14);
@@ -199,6 +195,6 @@ function findIdcardAge(idcard) {
199
195
  var str = "".concat(year, "-").concat(month, "-").concat(day);
200
196
  return getDateData(str, "YYYY-MM-DD HH:mm:ss");
201
197
  }
202
- return;
198
+ return "";
203
199
  }
204
200
  exports.findIdcardAge = findIdcardAge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.5.9",
3
+ "version": "1.6.1",
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",