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 +2 -0
- package/VERSION.md +5 -0
- package/index.css +0 -1
- package/js/ScanUDI.js +50 -75
- 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,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
|
-
|
|
128
|
-
if (
|
|
129
|
-
date
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
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"));
|