zhl-methods 1.1.5 → 1.1.7

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
@@ -1,5 +1,7 @@
1
1
  # zhl-methods
2
2
 
3
+ <!-- npm publish 发布命令 -->
4
+
3
5
  JS 微信小程序 工具类
4
6
 
5
7
  #### 安装
package/VERSION.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  版本更新日志
4
4
 
5
+ ### 1.1.7
6
+
7
+ - 增加 dayjs 库 获取时间使用
8
+ - ScanUDI 解析时间格式 分辨 202509 和 250901
9
+
5
10
  ### 1.1.2
6
11
 
7
12
  - 增加 /js/ScanUDI.js 文件 扫描 净里镜规则 括号规则 自定义规则
package/index.css CHANGED
@@ -1,4 +1,3 @@
1
- /* npm publish 发布命令 */
2
1
  /* 单行溢出省略号 */
3
2
  .nowrap {
4
3
  /*溢出部分隐藏*/
package/js/ScanUDI.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import dayjs from "dayjs";
2
-
3
2
  export default class ScanUDI {
4
3
  constructor({ rules }) {
5
4
  this.rules = rules;
@@ -34,23 +33,15 @@ export default class ScanUDI {
34
33
  } else if (str.includes("(")) {
35
34
  const regex = /\((\d{2})\)([^($$)]+)/g;
36
35
  let match;
36
+ let obj = {};
37
37
  while ((match = regex.exec(str)) !== null) {
38
- if (match[1] == "01") {
39
- upc = match[2];
40
- }
41
- if (match[1] == "11") {
42
- manufacture_time = match[2];
43
- }
44
- if (match[1] == "17") {
45
- expiry_time = match[2];
46
- }
47
- if (match[1] == "10") {
48
- batch_no = match[2];
49
- }
50
- if (match[1] == "21") {
51
- serial_no = match[2];
52
- }
38
+ obj[match[1]] = match[2];
53
39
  }
40
+ upc = obj["01"];
41
+ manufacture_time = obj["11"];
42
+ expiry_time = obj["17"];
43
+ batch_no = obj["10"];
44
+ serial_no = obj["21"];
54
45
  } else {
55
46
  if (
56
47
  this.rules.every(
@@ -82,81 +73,58 @@ export default class ScanUDI {
82
73
  });
83
74
  }
84
75
  let obj = {
76
+ upc: this.removeFrontZeros(upc),
85
77
  sku_number,
78
+ manufacture_time: this.setDateFormat(
79
+ manufacture_time,
80
+ "manufacture",
81
+ expiry_time
82
+ ),
83
+ expiry_time: this.setDateFormat(expiry_time, "expiry", manufacture_time),
84
+ batch_no: batch_no.toUpperCase(),
86
85
  serial_no,
87
86
  };
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
87
  return obj;
125
88
  }
126
- setDateFormat(date, type) {
127
- if (date.length === 8 && data.substr(data.length - 2) == "00") {
128
- if (type === "expiry") {
129
- return dayjs(date).endOf("month").format("YYYYMMDD");
130
- }
131
- return dayjs(date).startOf("month").format("YYYYMMDD");
132
- }
133
- if (date.length === 6) {
134
- // 年月(6位) - 202507
135
- if (date.substring(0, 2) === "20") {
136
- return date + "01";
89
+ setDateFormat(date, type, expand) {
90
+ try {
91
+ if (date.length === 8 && data.substr(data.length - 2) == "00") {
92
+ if (type === "expiry") {
93
+ date = dayjs(date).endOf("month");
94
+ }
95
+ date = dayjs(date).startOf("month");
137
96
  }
138
- // 年后两位月日(6) - 250708
139
- if (date.substring(0, 2) !== "20") {
140
- return "20" + date;
97
+ if (date.length === 6) {
98
+ if (date.substring(0, 2) === expand.substring(0, 2)) {
99
+ // 年月(6位) - 202507
100
+ date = date + "01";
101
+ } else {
102
+ // 年后两位月日(6位) - 250708
103
+ date = "20" + date;
104
+ }
141
105
  }
142
- }
143
- // 年后两位月(4) - 2507
144
- if (date.length === 4) {
145
- if (type === "expiry") {
146
- return dayjs("20" + date)
147
- .endOf("month")
148
- .format("YYYYMMDD");
106
+ // 年后两位月(4位) - 2507
107
+ if (date.length === 4) {
108
+ if (type === "expiry") {
109
+ date = dayjs("20" + date).endOf("month");
110
+ }
111
+ date = "20" + date + "01";
149
112
  }
150
- return "20" + date + "01";
113
+ return dayjs(date).format("YYYY-MM-DD");
114
+ } catch (error) {
115
+ console.log(error, "setDateFormat error");
116
+ return date;
151
117
  }
152
-
153
- return date;
154
118
  }
155
119
  removeFrontZeros(str) {
156
120
  try {
157
121
  return str.replace(/^0+/, "");
158
122
  } catch (error) {
123
+ console.log(error, "removeFrontZeros error");
159
124
  return str;
160
125
  }
161
126
  }
162
127
  }
128
+ const scanudi = new ScanUDI({ rules: [] });
129
+
130
+ console.log(scanudi.parse("(01)00047144050546(17)261002(11)241003(10)GJ24117"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zhl-methods",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "license": "ISC",
5
5
  "dependencies": {
6
6
  "dayjs": "^1.11.15",