xctc-utils 1.5.8 → 1.6.0

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.
@@ -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
@@ -30,7 +30,12 @@ export declare function getDateData(value: string | number, format?: string): {
30
30
  second: string | number;
31
31
  num: any;
32
32
  };
33
- export declare function findIdcardAge(idcard: string): {
33
+ /**
34
+ *
35
+ * @param idcard 身份证号码
36
+ * @returns
37
+ */
38
+ export declare function findIdcardAge(idcard: string): void | {
34
39
  year: string | number;
35
40
  month: string | number;
36
41
  day: string | number;
@@ -38,4 +43,4 @@ export declare function findIdcardAge(idcard: string): {
38
43
  minute: string | number;
39
44
  second: string | number;
40
45
  num: any;
41
- } | undefined;
46
+ };
@@ -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,8 +115,9 @@ 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
- month = value.substring(monthIndex, monthIndex + 3);
120
+ month = value.substring(monthIndex, monthIndex + 2) || "01";
126
121
  str = "".concat(str, "/").concat(month);
127
122
  }
128
123
  else {
@@ -131,7 +126,7 @@ function getDateData(value, format) {
131
126
  }
132
127
  var dayIndex = format.indexOf("DD");
133
128
  if (dayIndex != -1) {
134
- day = value.substring(dayIndex, dayIndex + 3);
129
+ day = value.substring(dayIndex, dayIndex + 2) || "01";
135
130
  str = "".concat(str, "/").concat(day);
136
131
  }
137
132
  else {
@@ -140,7 +135,7 @@ function getDateData(value, format) {
140
135
  }
141
136
  var hourIndex = format.indexOf("HH");
142
137
  if (hourIndex != -1) {
143
- hour = value.substring(hourIndex, hourIndex + 3);
138
+ hour = value.substring(hourIndex, hourIndex + 2) || "00";
144
139
  str = "".concat(str, " ").concat(hour);
145
140
  }
146
141
  else {
@@ -148,8 +143,8 @@ function getDateData(value, format) {
148
143
  str = "".concat(str, " 00");
149
144
  }
150
145
  var minuteIndex = format.indexOf("mm");
151
- if (hourIndex != -1) {
152
- minute = value.substring(minuteIndex, minuteIndex + 3);
146
+ if (minuteIndex != -1) {
147
+ minute = value.substring(minuteIndex, minuteIndex + 2) || "00";
153
148
  str = "".concat(str, ":").concat(minute);
154
149
  }
155
150
  else {
@@ -157,8 +152,8 @@ function getDateData(value, format) {
157
152
  str = "".concat(str, ":00");
158
153
  }
159
154
  var secondIndex = format.indexOf("ss");
160
- if (hourIndex != -1) {
161
- second = value.substring(secondIndex, secondIndex + 3);
155
+ if (secondIndex != -1) {
156
+ second = value.substring(secondIndex, secondIndex + 2) || "00";
162
157
  str = "".concat(str, ":").concat(second);
163
158
  }
164
159
  else {
@@ -180,9 +175,14 @@ function getDateData(value, format) {
180
175
  };
181
176
  }
182
177
  exports.getDateData = getDateData;
178
+ /**
179
+ *
180
+ * @param idcard 身份证号码
181
+ * @returns
182
+ */
183
183
  function findIdcardAge(idcard) {
184
- if (!idcard) {
185
- return;
184
+ if (!idcard || idcard.length < 15) {
185
+ return console.error("传入正确的身份证号码");
186
186
  }
187
187
  // 提取身份证号中的出生日期部分
188
188
  var birthday = idcard.substring(6, 14);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.5.8",
3
+ "version": "1.6.0",
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",