zhl-methods 1.1.3 → 1.1.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/js/ScanUDI.js CHANGED
@@ -17,6 +17,7 @@ export default class ScanUDI {
17
17
  21: "serial_no",
18
18
  };
19
19
  parse(str) {
20
+ str = str.replace(/[^a-zA-Z0-9/()]/g, "");
20
21
  if ((str && str.length < 8) || !str) {
21
22
  return `请输入正确的条形码${str}`;
22
23
  }
@@ -51,8 +52,6 @@ export default class ScanUDI {
51
52
  }
52
53
  }
53
54
  } else {
54
- // let re = /[^\u4e00-\u9fa5a-zA-Z0-9]/g;
55
- // str = str.replace(re, "");
56
55
  if (
57
56
  this.rules.every(
58
57
  (v) => str.length != v.length || str.substring(0, 2) != v.start_value
@@ -82,37 +81,73 @@ export default class ScanUDI {
82
81
  }
83
82
  });
84
83
  }
85
- return {
86
- upc: this.removeFrontZeros(upc),
84
+ let obj = {
87
85
  sku_number,
88
- manufacture_time: this.setDateFormat(manufacture_time, "manufacture"),
89
- expiry_time: this.setDateFormat(expiry_time, "expiry"),
90
- batch_no,
91
86
  serial_no,
92
87
  };
88
+ try {
89
+ obj.upc = this.removeFrontZeros(upc);
90
+ } catch (error) {
91
+ console.log(error, "upc error");
92
+ obj.upc = upc;
93
+ }
94
+ try {
95
+ obj.manufacture_time = this.setDateFormat(
96
+ manufacture_time,
97
+ "manufacture"
98
+ );
99
+ } catch (error) {
100
+ console.log(error, "manufacture_time error");
101
+ obj.manufacture_time = manufacture_time;
102
+ }
103
+ try {
104
+ obj.manufacture_time = this.setDateFormat(
105
+ manufacture_time,
106
+ "manufacture"
107
+ );
108
+ } catch (error) {
109
+ console.log(error, "manufacture_time error");
110
+ obj.manufacture_time = manufacture_time;
111
+ }
112
+ try {
113
+ obj.expiry_time = this.setDateFormat(expiry_time, "expiry");
114
+ } catch (error) {
115
+ console.log(error, "expiry_time error");
116
+ obj.expiry_time = expiry_time;
117
+ }
118
+ try {
119
+ obj.batch_no = batch_no.toUpperCase();
120
+ } catch (error) {
121
+ console.log(error, "batch_no error");
122
+ obj.batch_no = batch_no;
123
+ }
124
+ return obj;
93
125
  }
94
126
  setDateFormat(date, type) {
127
+ if (date.length === 8 && data.substr(data.length - 2) == "00") {
128
+ if (type === "expiry") {
129
+ date = dayjs(date).endOf("month");
130
+ }
131
+ date = dayjs(date).startOf("month");
132
+ }
95
133
  if (date.length === 6) {
96
134
  // 年月(6位) - 202507
97
135
  if (date.substring(0, 2) === "20") {
98
- return date + "01";
136
+ date = date + "01";
99
137
  }
100
138
  // 年后两位月日(6位) - 250708
101
139
  if (date.substring(0, 2) !== "20") {
102
- return "20" + date;
140
+ date = "20" + date;
103
141
  }
104
142
  }
105
143
  // 年后两位月(4位) - 2507
106
144
  if (date.length === 4) {
107
145
  if (type === "expiry") {
108
- return dayjs("20" + date)
109
- .endOf("month")
110
- .format("YYYYMMDD");
146
+ date = dayjs("20" + date).endOf("month");
111
147
  }
112
- return "20" + date + "01";
148
+ date = "20" + date + "01";
113
149
  }
114
-
115
- return date;
150
+ return dayjs(date).format("YYYY-MM-DD");
116
151
  }
117
152
  removeFrontZeros(str) {
118
153
  try {
package/js/index.js CHANGED
@@ -110,10 +110,10 @@ export const getRandomNumber = (min, max) => {
110
110
  * 传type 返回 true false
111
111
  */
112
112
  export const isType = (data, type) => {
113
- if (type) {
114
- return Object.prototype.toString.call(data) === type;
115
- }
116
- return Object.prototype.toString.call(data);
113
+ const regex = /\[object (\w+)\]/;
114
+ let str = Object.prototype.toString.call(data);
115
+ const match = regex.exec(str);
116
+ return type ? match[1] === type : match[1];
117
117
  };
118
118
  /**
119
119
  * 时间戳转换成时间
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zhl-methods",
3
- "version": "1.1.3",
3
+ "version": "1.1.6",
4
4
  "license": "ISC",
5
5
  "dependencies": {
6
6
  "dayjs": "^1.11.15",