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 +2 -0
- package/VERSION.md +5 -0
- package/index.css +0 -1
- package/js/ScanUDI.js +44 -76
- package/package.json +1 -1
package/README.md
CHANGED
package/VERSION.md
CHANGED
package/index.css
CHANGED
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
|
-
|
|
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
|
-
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
|
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"));
|