zhl-methods 1.1.6 → 1.1.8

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,78 +73,62 @@ 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
- date = dayjs(date).endOf("month");
130
- }
131
- date = dayjs(date).startOf("month");
132
- }
133
- if (date.length === 6) {
134
- // 年月(6位) - 202507
135
- if (date.substring(0, 2) === "20") {
136
- date = date + "01";
137
- }
138
- // 年后两位月日(6位) - 250708
139
- if (date.substring(0, 2) !== "20") {
140
- date = "20" + date;
141
- }
142
- }
143
- // 年后两位月(4位) - 2507
144
- if (date.length === 4) {
145
- if (type === "expiry") {
146
- date = dayjs("20" + date).endOf("month");
89
+ setDateFormat(date, type, expand) {
90
+ try {
91
+ if (date) {
92
+ if (date.length === 8 && data.substr(data.length - 2) == "00") {
93
+ if (type === "expiry") {
94
+ date = dayjs(date).endOf("month");
95
+ }
96
+ date = dayjs(date).startOf("month");
97
+ }
98
+ if (date.length === 6) {
99
+ if (date.substring(0, 2) === expand.substring(0, 2)) {
100
+ // 年月(6位) - 202507
101
+ date = date + "01";
102
+ } else {
103
+ // 年后两位月日(6位) - 250708
104
+ date = "20" + date;
105
+ }
106
+ }
107
+ // 年后两位月(4) - 2507
108
+ if (date.length === 4) {
109
+ if (type === "expiry") {
110
+ date = dayjs("20" + date).endOf("month");
111
+ }
112
+ date = "20" + date + "01";
113
+ }
114
+ return dayjs(date).format("YYYY-MM-DD");
115
+ } else {
116
+ return "";
147
117
  }
148
- date = "20" + date + "01";
118
+ } catch (error) {
119
+ console.log(error, "setDateFormat error");
120
+ return date;
149
121
  }
150
- return dayjs(date).format("YYYY-MM-DD");
151
122
  }
152
123
  removeFrontZeros(str) {
153
124
  try {
154
125
  return str.replace(/^0+/, "");
155
126
  } catch (error) {
127
+ console.log(error, "removeFrontZeros error");
156
128
  return str;
157
129
  }
158
130
  }
159
131
  }
132
+ const scanudi = new ScanUDI({ rules: [] });
133
+
134
+ 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.6",
3
+ "version": "1.1.8",
4
4
  "license": "ISC",
5
5
  "dependencies": {
6
6
  "dayjs": "^1.11.15",