@sythos/js_barcode_universal 1.5.8 → 1.5.9
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/LICENSE +5 -4
- package/NOTICE.md +2 -2
- package/README.md +17 -13
- package/bundle/sythos-barcode.esm.js +11658 -11244
- package/bundle/sythos-barcode.js +11658 -11244
- package/package.json +10 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +508 -516
- package/src/js/aztec/decoder.js +208 -199
- package/src/js/aztec/detector.js +153 -126
- package/src/js/aztec/encoder.js +172 -153
- package/src/js/aztec/high-level.js +106 -101
- package/src/js/aztec/index.js +1 -12
- package/src/js/aztec/tables.js +106 -120
- package/src/js/aztecrune/decoder.js +76 -85
- package/src/js/aztecrune/detector.js +107 -93
- package/src/js/aztecrune/encoder.js +50 -68
- package/src/js/aztecrune/index.js +1 -16
- package/src/js/aztecrune/tables.js +59 -54
- package/src/js/compactpdf417/decoder.js +69 -74
- package/src/js/compactpdf417/detector.js +74 -75
- package/src/js/compactpdf417/encoder.js +68 -81
- package/src/js/compactpdf417/index.js +1 -13
- package/src/js/compactpdf417/tables.js +71 -80
- package/src/js/core/bit-buffer.js +106 -122
- package/src/js/core/bit-matrix.js +196 -194
- package/src/js/core/errors.js +13 -15
- package/src/js/core/galois-field.js +119 -133
- package/src/js/core/index.js +2 -19
- package/src/js/core/reed-solomon.js +195 -204
- package/src/js/databar/codec.js +93 -108
- package/src/js/databar/decoder.js +149 -140
- package/src/js/databar/encoder.js +47 -55
- package/src/js/databar/gs1.js +122 -123
- package/src/js/databar/index.js +4 -36
- package/src/js/databar/patterns.js +81 -85
- package/src/js/databar/tables.js +51 -52
- package/src/js/datamatrix/decoder.js +216 -182
- package/src/js/datamatrix/detector.js +161 -132
- package/src/js/datamatrix/encoder.js +192 -133
- package/src/js/datamatrix/index.js +1 -9
- package/src/js/datamatrix/tables.js +68 -69
- package/src/js/frameqr/decoder.js +102 -125
- package/src/js/frameqr/detector.js +101 -94
- package/src/js/frameqr/encoder.js +67 -80
- package/src/js/frameqr/index.js +1 -10
- package/src/js/frameqr/tables.js +145 -163
- package/src/js/image/binarizer.js +146 -162
- package/src/js/image/grid-sampler.js +63 -79
- package/src/js/image/index.js +0 -2
- package/src/js/image/luminance.js +129 -140
- package/src/js/image/perspective.js +112 -149
- package/src/js/micropdf417/compaction.js +64 -65
- package/src/js/micropdf417/decoder.js +106 -109
- package/src/js/micropdf417/detector.js +73 -70
- package/src/js/micropdf417/encoder.js +129 -154
- package/src/js/micropdf417/error-correction.js +6 -11
- package/src/js/micropdf417/index.js +2 -16
- package/src/js/micropdf417/tables.js +112 -99
- package/src/js/microqr/decoder.js +177 -182
- package/src/js/microqr/detector.js +240 -256
- package/src/js/microqr/encoder.js +239 -194
- package/src/js/microqr/index.js +0 -2
- package/src/js/microqr/tables.js +208 -200
- package/src/js/oned/addons.js +167 -191
- package/src/js/oned/index.js +27 -58
- package/src/js/oned/patterns.js +194 -213
- package/src/js/oned/reader.js +1003 -984
- package/src/js/oned/writers.js +411 -466
- package/src/js/pdf417/compaction.js +315 -222
- package/src/js/pdf417/decoder.js +71 -36
- package/src/js/pdf417/detector.js +377 -361
- package/src/js/pdf417/encoder.js +57 -46
- package/src/js/pdf417/error-correction.js +5 -8
- package/src/js/pdf417/tables.js +248 -250
- package/src/js/qr/decoder.js +311 -347
- package/src/js/qr/detector.js +378 -395
- package/src/js/qr/encoder.js +514 -599
- package/src/js/qr/index.js +0 -2
- package/src/js/qr/tables.js +375 -422
- package/src/js/render/image-data.js +57 -62
- package/src/js/render/index.js +21 -23
- package/src/js/render/options.js +82 -90
- package/src/js/render/png.js +144 -169
- package/src/js/render/svg.js +41 -44
- package/src/js/render/webgl.js +103 -109
- package/src/js/render/webgpu.js +205 -217
- package/src/js/rmqr/decoder.js +161 -53
- package/src/js/rmqr/detector.js +73 -41
- package/src/js/rmqr/encoder.js +253 -104
- package/src/js/rmqr/index.js +1 -5
- package/src/js/rmqr/tables.js +108 -85
- package/src/ts/aztec/decoder.ts +317 -0
- package/src/ts/aztec/detector.ts +224 -0
- package/src/ts/aztec/encoder.ts +257 -0
- package/src/ts/aztec/high-level.ts +211 -0
- package/src/ts/aztec/index.ts +45 -0
- package/src/ts/aztec/tables.ts +210 -0
- package/src/ts/aztecrune/decoder.ts +155 -0
- package/src/ts/aztecrune/detector.ts +166 -0
- package/src/ts/aztecrune/encoder.ts +121 -0
- package/src/ts/aztecrune/index.ts +49 -0
- package/src/ts/aztecrune/tables.ts +137 -0
- package/src/ts/compactpdf417/decoder.ts +128 -0
- package/src/ts/compactpdf417/detector.ts +139 -0
- package/src/ts/compactpdf417/encoder.ts +140 -0
- package/src/ts/compactpdf417/index.ts +17 -0
- package/src/ts/compactpdf417/tables.ts +173 -0
- package/src/ts/core/bit-buffer.ts +174 -0
- package/src/ts/core/bit-matrix.ts +241 -0
- package/src/ts/core/errors.ts +61 -0
- package/src/ts/core/galois-field.ts +207 -0
- package/src/ts/core/index.ts +56 -0
- package/src/ts/core/reed-solomon.ts +327 -0
- package/src/ts/databar/codec.ts +181 -0
- package/src/ts/databar/decoder.ts +215 -0
- package/src/ts/databar/encoder.ts +96 -0
- package/src/ts/databar/gs1.ts +177 -0
- package/src/ts/databar/index.ts +68 -0
- package/src/ts/databar/patterns.ts +143 -0
- package/src/ts/databar/tables.ts +124 -0
- package/src/ts/datamatrix/decoder.ts +262 -0
- package/src/ts/datamatrix/detector.ts +225 -0
- package/src/ts/datamatrix/encoder.ts +191 -0
- package/src/ts/datamatrix/index.ts +42 -0
- package/src/ts/datamatrix/tables.ts +123 -0
- package/src/ts/frameqr/decoder.ts +239 -0
- package/src/ts/frameqr/detector.ts +192 -0
- package/src/ts/frameqr/encoder.ts +156 -0
- package/src/ts/frameqr/index.ts +42 -0
- package/src/ts/frameqr/tables.ts +270 -0
- package/src/ts/image/binarizer.ts +270 -0
- package/src/ts/image/grid-sampler.ts +164 -0
- package/src/ts/image/index.ts +40 -0
- package/src/ts/image/luminance.ts +196 -0
- package/src/ts/image/perspective.ts +195 -0
- package/src/ts/index.d.ts +1 -1
- package/src/ts/index.ts +790 -0
- package/src/ts/micropdf417/compaction.ts +116 -0
- package/src/ts/micropdf417/decoder.ts +183 -0
- package/src/ts/micropdf417/detector.ts +149 -0
- package/src/ts/micropdf417/encoder.ts +209 -0
- package/src/ts/micropdf417/error-correction.ts +55 -0
- package/src/ts/micropdf417/index.ts +49 -0
- package/src/ts/micropdf417/tables.ts +184 -0
- package/src/ts/microqr/decoder.ts +245 -0
- package/src/ts/microqr/detector.ts +355 -0
- package/src/ts/microqr/encoder.ts +269 -0
- package/src/ts/microqr/index.ts +36 -0
- package/src/ts/microqr/tables.ts +316 -0
- package/src/ts/oned/addons.ts +420 -0
- package/src/ts/oned/index.ts +106 -0
- package/src/ts/oned/patterns.ts +384 -0
- package/src/ts/oned/reader.ts +1364 -0
- package/src/ts/oned/writers.ts +746 -0
- package/src/ts/pdf417/compaction.ts +298 -0
- package/src/ts/pdf417/decoder.ts +75 -0
- package/src/ts/pdf417/detector.ts +468 -0
- package/src/ts/pdf417/encoder.ts +91 -0
- package/src/ts/pdf417/error-correction.ts +47 -0
- package/src/ts/pdf417/index.ts +6 -0
- package/src/ts/pdf417/tables.ts +317 -0
- package/src/ts/qr/decoder.ts +575 -0
- package/src/ts/qr/detector.ts +630 -0
- package/src/ts/qr/encoder.ts +958 -0
- package/src/ts/qr/index.ts +44 -0
- package/src/ts/qr/tables.ts +737 -0
- package/src/ts/render/image-data.ts +125 -0
- package/src/ts/render/index.ts +130 -0
- package/src/ts/render/options.ts +160 -0
- package/src/ts/render/png.ts +295 -0
- package/src/ts/render/svg.ts +120 -0
- package/src/ts/render/webgl.ts +206 -0
- package/src/ts/render/webgpu.ts +369 -0
- package/src/ts/rmqr/decoder.ts +101 -0
- package/src/ts/rmqr/detector.ts +90 -0
- package/src/ts/rmqr/encoder.ts +172 -0
- package/src/ts/rmqr/index.ts +37 -0
- package/src/ts/rmqr/tables.ts +154 -0
package/src/js/oned/patterns.js
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
*
|
|
28
28
|
* Original work. No code from any other barcode implementation.
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
30
|
/**
|
|
32
31
|
* Pattern tables for the linear symbologies.
|
|
33
32
|
*
|
|
@@ -49,133 +48,119 @@
|
|
|
49
48
|
*
|
|
50
49
|
* @module oned/patterns
|
|
51
50
|
*/
|
|
52
|
-
|
|
53
51
|
/* ------------------------------------------------------------------ *
|
|
54
52
|
* EAN / UPC
|
|
55
53
|
* ------------------------------------------------------------------ */
|
|
56
|
-
|
|
57
54
|
/** Odd-parity ("L") digit patterns, 7 modules each. */
|
|
58
55
|
export const EAN_L = [
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
'0001101', '0011001', '0010011', '0111101', '0100011',
|
|
57
|
+
'0110001', '0101111', '0111011', '0110111', '0001011',
|
|
61
58
|
];
|
|
62
|
-
|
|
63
59
|
/** Even-parity ("G") patterns: the R pattern reversed. */
|
|
64
60
|
export const EAN_G = EAN_L.map((p) => [...p].reverse().map((b) => (b === '1' ? '0' : '1')).join(''));
|
|
65
|
-
|
|
66
61
|
/** Right-hand ("R") patterns: the L pattern complemented. */
|
|
67
62
|
export const EAN_R = EAN_L.map((p) => [...p].map((b) => (b === '1' ? '0' : '1')).join(''));
|
|
68
|
-
|
|
69
63
|
/**
|
|
70
64
|
* Which parity set each of the six left-hand EAN-13 digits uses, indexed by
|
|
71
65
|
* the first digit. This is how the thirteenth digit is carried without a
|
|
72
66
|
* thirteenth symbol position.
|
|
73
67
|
*/
|
|
74
68
|
export const EAN13_PARITY = [
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
'LLLLLL', 'LLGLGG', 'LLGGLG', 'LLGGGL', 'LGLLGG',
|
|
70
|
+
'LGGLLG', 'LGGGLL', 'LGLGLG', 'LGLGGL', 'LGGLGL',
|
|
77
71
|
];
|
|
78
|
-
|
|
79
72
|
/** UPC-E parity patterns, indexed by check digit. Used when the number system is 0. */
|
|
80
73
|
export const UPCE_PARITY = [
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
'EEEOOO', 'EEOEOO', 'EEOOEO', 'EEOOOE', 'EOEEOO',
|
|
75
|
+
'EOOEEO', 'EOOOEE', 'EOEOEO', 'EOEOOE', 'EOOEOE',
|
|
83
76
|
];
|
|
84
|
-
|
|
85
77
|
export const EAN_START_END = '101';
|
|
86
78
|
export const EAN_MIDDLE = '01010';
|
|
87
79
|
export const UPCE_END = '010101';
|
|
88
|
-
|
|
89
80
|
/* ------------------------------------------------------------------ *
|
|
90
81
|
* Code 39
|
|
91
82
|
* ------------------------------------------------------------------ */
|
|
92
|
-
|
|
93
83
|
/**
|
|
94
84
|
* Code 39 is "three of nine": nine elements per character, of which exactly
|
|
95
85
|
* three are wide. `n` and `w` below are narrow and wide; elements alternate
|
|
96
86
|
* bar, space, bar, ... starting and ending with a bar.
|
|
97
87
|
*/
|
|
98
88
|
export const CODE39 = {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
89
|
+
'0': 'nnnwwnwnn', '1': 'wnnwnnnnw', '2': 'nnwwnnnnw', '3': 'wnwwnnnnn',
|
|
90
|
+
'4': 'nnnwwnnnw', '5': 'wnnwwnnnn', '6': 'nnwwwnnnn', '7': 'nnnwnnwnw',
|
|
91
|
+
'8': 'wnnwnnwnn', '9': 'nnwwnnwnn', 'A': 'wnnnnwnnw', 'B': 'nnwnnwnnw',
|
|
92
|
+
'C': 'wnwnnwnnn', 'D': 'nnnnwwnnw', 'E': 'wnnnwwnnn', 'F': 'nnwnwwnnn',
|
|
93
|
+
'G': 'nnnnnwwnw', 'H': 'wnnnnwwnn', 'I': 'nnwnnwwnn', 'J': 'nnnnwwwnn',
|
|
94
|
+
'K': 'wnnnnnnww', 'L': 'nnwnnnnww', 'M': 'wnwnnnnwn', 'N': 'nnnnwnnww',
|
|
95
|
+
'O': 'wnnnwnnwn', 'P': 'nnwnwnnwn', 'Q': 'nnnnnnwww', 'R': 'wnnnnnwwn',
|
|
96
|
+
'S': 'nnwnnnwwn', 'T': 'nnnnwnwwn', 'U': 'wwnnnnnnw', 'V': 'nwwnnnnnw',
|
|
97
|
+
'W': 'wwwnnnnnn', 'X': 'nwnnwnnnw', 'Y': 'wwnnwnnnn', 'Z': 'nwwnwnnnn',
|
|
98
|
+
'-': 'nwnnnnwnw', '.': 'wwnnnnwnn', ' ': 'nwwnnnwnn', '$': 'nwnwnwnnn',
|
|
99
|
+
'/': 'nwnwnnnwn', '+': 'nwnnnwnwn', '%': 'nnnwnwnwn', '*': 'nwnnwnwnn',
|
|
110
100
|
};
|
|
111
|
-
|
|
112
101
|
/** Character set for the optional modulo-43 check digit; '*' is excluded. */
|
|
113
102
|
export const CODE39_CHECK_SET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%';
|
|
114
|
-
|
|
115
103
|
/** Two-character escapes giving Code 39 the full ASCII range. */
|
|
116
104
|
export const CODE39_EXTENDED = (() => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
105
|
+
const map = new Array(128);
|
|
106
|
+
const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
107
|
+
for (let i = 0; i < 26; i++) {
|
|
108
|
+
map[i + 1] = '$' + upper[i]; // SOH..SUB
|
|
109
|
+
map[i + 65] = upper[i]; // A-Z
|
|
110
|
+
map[i + 97] = '+' + upper[i]; // a-z
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < 10; i++)
|
|
113
|
+
map[i + 48] = String(i);
|
|
114
|
+
map[0] = '%U';
|
|
115
|
+
for (let i = 27; i <= 31; i++)
|
|
116
|
+
map[i] = '%' + upper[i - 27 + 0]; // ESC..US -> %A..%E
|
|
117
|
+
const symbols = {
|
|
118
|
+
32: ' ', 33: '/A', 34: '/B', 35: '/C', 36: '/D', 37: '/E', 38: '/F',
|
|
119
|
+
39: '/G', 40: '/H', 41: '/I', 42: '/J', 43: '/K', 44: '/L', 45: '-',
|
|
120
|
+
46: '.', 47: '/O', 58: '/Z', 59: '%F', 60: '%G', 61: '%H', 62: '%I',
|
|
121
|
+
63: '%J', 64: '%V', 91: '%K', 92: '%L', 93: '%M', 94: '%N', 95: '%O',
|
|
122
|
+
96: '%W', 123: '%P', 124: '%Q', 125: '%R', 126: '%S', 127: '%T',
|
|
123
|
+
};
|
|
124
|
+
for (const [code, seq] of Object.entries(symbols))
|
|
125
|
+
map[Number(code)] = seq;
|
|
126
|
+
return map;
|
|
136
127
|
})();
|
|
137
|
-
|
|
138
128
|
/* ------------------------------------------------------------------ *
|
|
139
129
|
* Code 93
|
|
140
130
|
* ------------------------------------------------------------------ */
|
|
141
|
-
|
|
142
131
|
/** Nine modules per character across six elements. */
|
|
143
132
|
export const CODE93 = {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
133
|
+
'0': '131112', '1': '111213', '2': '111312', '3': '111411', '4': '121113',
|
|
134
|
+
'5': '121212', '6': '121311', '7': '111114', '8': '131211', '9': '141111',
|
|
135
|
+
'A': '211113', 'B': '211212', 'C': '211311', 'D': '221112', 'E': '221211',
|
|
136
|
+
'F': '231111', 'G': '112113', 'H': '112212', 'I': '112311', 'J': '122112',
|
|
137
|
+
'K': '132111', 'L': '111123', 'M': '111222', 'N': '111321', 'O': '121122',
|
|
138
|
+
'P': '131121', 'Q': '212112', 'R': '212211', 'S': '211122', 'T': '211221',
|
|
139
|
+
'U': '221121', 'V': '222111', 'W': '112122', 'X': '112221', 'Y': '122121',
|
|
140
|
+
'Z': '123111', '-': '121131', '.': '311112', ' ': '311211', '$': '321111',
|
|
141
|
+
'/': '112131', '+': '113121', '%': '211131',
|
|
142
|
+
// The four shift characters. Their conventional names -- ($) (%) (/) (+) --
|
|
143
|
+
// collide with the literal single-character entries above, so they take
|
|
144
|
+
// distinct multi-character keys. Writing the bare symbols here would create
|
|
145
|
+
// duplicate object keys, which JavaScript collapses silently: the table
|
|
146
|
+
// would end up three entries short, with no error raised anywhere.
|
|
147
|
+
'S$': '121221',
|
|
148
|
+
'S%': '312111',
|
|
149
|
+
'S/': '311121',
|
|
150
|
+
'S+': '122211',
|
|
162
151
|
};
|
|
163
|
-
|
|
164
152
|
/**
|
|
165
153
|
* Symbol values 0..46 in order, as keys into {@link CODE93}. An array rather
|
|
166
154
|
* than a string, because the four shift characters have multi-character keys.
|
|
167
155
|
*/
|
|
168
156
|
export const CODE93_VALUES = [
|
|
169
|
-
|
|
170
|
-
|
|
157
|
+
...'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%',
|
|
158
|
+
'S$', 'S%', 'S/', 'S+',
|
|
171
159
|
];
|
|
172
|
-
|
|
173
160
|
export const CODE93_START_STOP = '111141';
|
|
174
|
-
|
|
175
161
|
/* ------------------------------------------------------------------ *
|
|
176
162
|
* Code 128
|
|
177
163
|
* ------------------------------------------------------------------ */
|
|
178
|
-
|
|
179
164
|
/**
|
|
180
165
|
* All 107 symbol patterns. Eleven modules each across six elements; the stop
|
|
181
166
|
* pattern is the sole exception at thirteen modules across seven.
|
|
@@ -185,24 +170,23 @@ export const CODE93_START_STOP = '111141';
|
|
|
185
170
|
* pattern breaks the sum.
|
|
186
171
|
*/
|
|
187
172
|
export const CODE128 = [
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
173
|
+
'212222', '222122', '222221', '121223', '121322', '131222', '122213',
|
|
174
|
+
'122312', '132212', '221213', '221312', '231212', '112232', '122132',
|
|
175
|
+
'122231', '113222', '123122', '123221', '223211', '221132', '221231',
|
|
176
|
+
'213212', '223112', '312131', '311222', '321122', '321221', '312212',
|
|
177
|
+
'322112', '322211', '212123', '212321', '232121', '111323', '131123',
|
|
178
|
+
'131321', '112313', '132113', '132311', '211313', '231113', '231311',
|
|
179
|
+
'112133', '112331', '132131', '113123', '113321', '133121', '313121',
|
|
180
|
+
'211331', '231131', '213113', '213311', '213131', '311123', '311321',
|
|
181
|
+
'331121', '312113', '312311', '332111', '314111', '221411', '431111',
|
|
182
|
+
'111224', '111422', '121124', '121421', '141122', '141221', '112214',
|
|
183
|
+
'112412', '122114', '122411', '142112', '142211', '241211', '221114',
|
|
184
|
+
'413111', '241112', '134111', '111242', '121142', '121241', '114212',
|
|
185
|
+
'124112', '124211', '411212', '421112', '421211', '212141', '214121',
|
|
186
|
+
'412121', '111143', '111341', '131141', '114113', '114311', '411113',
|
|
187
|
+
'411311', '113141', '114131', '311141', '411131', '211412', '211214',
|
|
188
|
+
'211232', '2331112',
|
|
204
189
|
];
|
|
205
|
-
|
|
206
190
|
export const CODE128_START_A = 103;
|
|
207
191
|
export const CODE128_START_B = 104;
|
|
208
192
|
export const CODE128_START_C = 105;
|
|
@@ -216,58 +200,46 @@ export const CODE128_SHIFT = 98;
|
|
|
216
200
|
export const CODE128_CODE_A = 101;
|
|
217
201
|
export const CODE128_CODE_B = 100;
|
|
218
202
|
export const CODE128_CODE_C = 99;
|
|
219
|
-
|
|
220
203
|
/* ------------------------------------------------------------------ *
|
|
221
204
|
* Interleaved 2 of 5
|
|
222
205
|
* ------------------------------------------------------------------ */
|
|
223
|
-
|
|
224
206
|
/** Five elements per digit, exactly two of them wide. */
|
|
225
207
|
export const ITF = [
|
|
226
|
-
|
|
227
|
-
|
|
208
|
+
'nnwwn', 'wnnnw', 'nwnnw', 'wwnnn', 'nnwnw',
|
|
209
|
+
'wnwnn', 'nwwnn', 'nnnww', 'wnnwn', 'nwnwn',
|
|
228
210
|
];
|
|
229
|
-
|
|
230
211
|
/* ------------------------------------------------------------------ *
|
|
231
212
|
* Codabar
|
|
232
213
|
* ------------------------------------------------------------------ */
|
|
233
|
-
|
|
234
214
|
/** Seven elements per character. */
|
|
235
215
|
export const CODABAR = {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
216
|
+
'0': 'nnnnnww', '1': 'nnnnwwn', '2': 'nnnwnnw', '3': 'wwnnnnn',
|
|
217
|
+
'4': 'nnwnnwn', '5': 'wnnnnwn', '6': 'nwnnnnw', '7': 'nwnnwnn',
|
|
218
|
+
'8': 'nwwnnnn', '9': 'wnnwnnn', '-': 'nnnwwnn', '$': 'nnwwnnn',
|
|
219
|
+
':': 'wnnnwnw', '/': 'wnwnnnw', '.': 'wnwnwnn', '+': 'nnwnwnw',
|
|
220
|
+
'A': 'nnwwnwn', 'B': 'nwnwnnw', 'C': 'nnnwnww', 'D': 'nnnwwwn',
|
|
241
221
|
};
|
|
242
|
-
|
|
243
222
|
export const CODABAR_START_STOP = 'ABCD';
|
|
244
|
-
|
|
245
223
|
/* ------------------------------------------------------------------ *
|
|
246
224
|
* Code 11
|
|
247
225
|
* ------------------------------------------------------------------ */
|
|
248
|
-
|
|
249
226
|
/** Five elements per character, one or two of them wide. */
|
|
250
227
|
export const CODE11 = {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
228
|
+
'0': 'nnnnw', '1': 'wnnnw', '2': 'nwnnw', '3': 'wwnnn', '4': 'nnwnw',
|
|
229
|
+
'5': 'wnwnn', '6': 'nwwnn', '7': 'nnnww', '8': 'wnnwn', '9': 'wnnnn',
|
|
230
|
+
'-': 'nnwnn',
|
|
254
231
|
};
|
|
255
|
-
|
|
256
232
|
export const CODE11_START_STOP = 'nnwwn';
|
|
257
|
-
|
|
258
233
|
/* ------------------------------------------------------------------ *
|
|
259
234
|
* MSI / Plessey
|
|
260
235
|
* ------------------------------------------------------------------ */
|
|
261
|
-
|
|
262
236
|
/** Each bit of a digit becomes a bar pair: 1 is wide-then-narrow, 0 the reverse. */
|
|
263
237
|
export const MSI_BIT = { 0: '100', 1: '110' };
|
|
264
238
|
export const MSI_START = '110';
|
|
265
239
|
export const MSI_STOP = '1001';
|
|
266
|
-
|
|
267
240
|
/* ------------------------------------------------------------------ *
|
|
268
241
|
* Structural validation
|
|
269
242
|
* ------------------------------------------------------------------ */
|
|
270
|
-
|
|
271
243
|
/**
|
|
272
244
|
* Assert every invariant these tables are supposed to satisfy.
|
|
273
245
|
*
|
|
@@ -278,107 +250,116 @@ export const MSI_STOP = '1001';
|
|
|
278
250
|
* @returns {string[]} Problems found; empty means all invariants hold.
|
|
279
251
|
*/
|
|
280
252
|
export function validateTables() {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
253
|
+
const problems = [];
|
|
254
|
+
const sum = (s) => [...s].reduce((a, c) => a + Number(c), 0);
|
|
255
|
+
const countWide = (s) => [...s].filter((c) => c === 'w').length;
|
|
256
|
+
// --- EAN/UPC: 7 modules per digit; L odd parity; R the complement of L;
|
|
257
|
+
// G the reverse of R. All 30 patterns distinct.
|
|
258
|
+
for (let d = 0; d < 10; d++) {
|
|
259
|
+
for (const [name, table] of [['L', EAN_L], ['G', EAN_G], ['R', EAN_R]]) {
|
|
260
|
+
if (table[d].length !== 7)
|
|
261
|
+
problems.push(`EAN ${name}${d}: ${table[d].length} modules, expected 7`);
|
|
262
|
+
}
|
|
263
|
+
const darkL = [...EAN_L[d]].filter((c) => c === '1').length;
|
|
264
|
+
if (darkL % 2 === 0)
|
|
265
|
+
problems.push(`EAN L${d}: even parity, expected odd`);
|
|
266
|
+
const darkG = [...EAN_G[d]].filter((c) => c === '1').length;
|
|
267
|
+
if (darkG % 2 !== 0)
|
|
268
|
+
problems.push(`EAN G${d}: odd parity, expected even`);
|
|
269
|
+
if (EAN_L[d][0] !== '0' || EAN_L[d][6] !== '1') {
|
|
270
|
+
problems.push(`EAN L${d}: must start with a space and end with a bar`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const eanAll = new Set([...EAN_L, ...EAN_G, ...EAN_R]);
|
|
274
|
+
if (eanAll.size !== 30)
|
|
275
|
+
problems.push(`EAN: ${eanAll.size} distinct patterns, expected 30`);
|
|
276
|
+
// --- EAN-13 parity: first row all-L, every row six characters, all distinct.
|
|
277
|
+
if (EAN13_PARITY[0] !== 'LLLLLL')
|
|
278
|
+
problems.push('EAN-13 parity[0] must be LLLLLL');
|
|
279
|
+
if (new Set(EAN13_PARITY).size !== 10)
|
|
280
|
+
problems.push('EAN-13 parity rows are not distinct');
|
|
281
|
+
for (const [i, row] of EAN13_PARITY.entries()) {
|
|
282
|
+
if (row.length !== 6)
|
|
283
|
+
problems.push(`EAN-13 parity[${i}]: ${row.length} entries, expected 6`);
|
|
284
|
+
}
|
|
285
|
+
// --- Code 39: nine elements, exactly three wide, all patterns distinct.
|
|
286
|
+
for (const [ch, p] of Object.entries(CODE39)) {
|
|
287
|
+
if (p.length !== 9)
|
|
288
|
+
problems.push(`Code39 '${ch}': ${p.length} elements, expected 9`);
|
|
289
|
+
if (countWide(p) !== 3)
|
|
290
|
+
problems.push(`Code39 '${ch}': ${countWide(p)} wide, expected 3`);
|
|
291
|
+
}
|
|
292
|
+
if (new Set(Object.values(CODE39)).size !== Object.keys(CODE39).length) {
|
|
293
|
+
problems.push('Code39: duplicate patterns');
|
|
294
|
+
}
|
|
295
|
+
if (CODE39_CHECK_SET.length !== 43) {
|
|
296
|
+
problems.push(`Code39 check set: ${CODE39_CHECK_SET.length} characters, expected 43`);
|
|
297
|
+
}
|
|
298
|
+
// --- Code 93: nine modules across six elements, all patterns distinct.
|
|
299
|
+
for (const [ch, p] of Object.entries(CODE93)) {
|
|
300
|
+
if (p.length !== 6)
|
|
301
|
+
problems.push(`Code93 '${ch}': ${p.length} elements, expected 6`);
|
|
302
|
+
if (sum(p) !== 9)
|
|
303
|
+
problems.push(`Code93 '${ch}': ${sum(p)} modules, expected 9`);
|
|
304
|
+
}
|
|
305
|
+
if (new Set(Object.values(CODE93)).size !== Object.keys(CODE93).length) {
|
|
306
|
+
problems.push('Code93: duplicate patterns');
|
|
307
|
+
}
|
|
308
|
+
if (CODE93_VALUES.length !== 47) {
|
|
309
|
+
problems.push(`Code93 values: ${CODE93_VALUES.length}, expected 47`);
|
|
310
|
+
}
|
|
311
|
+
if (Object.keys(CODE93).length !== 47) {
|
|
312
|
+
problems.push(`Code93 table: ${Object.keys(CODE93).length} entries, expected 47 ` +
|
|
313
|
+
'(duplicate object keys collapse silently — check the shift characters)');
|
|
314
|
+
}
|
|
315
|
+
if (new Set(CODE93_VALUES).size !== CODE93_VALUES.length) {
|
|
316
|
+
problems.push('Code93: duplicate entries in the value order');
|
|
317
|
+
}
|
|
318
|
+
for (const ch of CODE93_VALUES) {
|
|
319
|
+
if (!CODE93[ch])
|
|
320
|
+
problems.push(`Code93: value character '${ch}' has no pattern`);
|
|
321
|
+
}
|
|
322
|
+
// --- Code 128: 107 patterns, 11 modules each, stop 13. All distinct.
|
|
323
|
+
if (CODE128.length !== 107) {
|
|
324
|
+
problems.push(`Code128: ${CODE128.length} patterns, expected 107`);
|
|
325
|
+
}
|
|
326
|
+
for (const [i, p] of CODE128.entries()) {
|
|
327
|
+
const expected = i === CODE128_STOP ? 13 : 11;
|
|
328
|
+
const elements = i === CODE128_STOP ? 7 : 6;
|
|
329
|
+
if (sum(p) !== expected)
|
|
330
|
+
problems.push(`Code128 [${i}] "${p}": ${sum(p)} modules, expected ${expected}`);
|
|
331
|
+
if (p.length !== elements)
|
|
332
|
+
problems.push(`Code128 [${i}] "${p}": ${p.length} elements, expected ${elements}`);
|
|
333
|
+
if ([...p].some((c) => c === '0' || Number(c) > 4)) {
|
|
334
|
+
problems.push(`Code128 [${i}] "${p}": element width out of range 1-4`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (new Set(CODE128).size !== CODE128.length)
|
|
338
|
+
problems.push('Code128: duplicate patterns');
|
|
339
|
+
// --- ITF: five elements, exactly two wide, ten distinct patterns.
|
|
340
|
+
for (const [d, p] of ITF.entries()) {
|
|
341
|
+
if (p.length !== 5)
|
|
342
|
+
problems.push(`ITF ${d}: ${p.length} elements, expected 5`);
|
|
343
|
+
if (countWide(p) !== 2)
|
|
344
|
+
problems.push(`ITF ${d}: ${countWide(p)} wide, expected 2`);
|
|
345
|
+
}
|
|
346
|
+
if (new Set(ITF).size !== 10)
|
|
347
|
+
problems.push('ITF: duplicate patterns');
|
|
348
|
+
// --- Codabar: seven elements, all distinct.
|
|
349
|
+
for (const [ch, p] of Object.entries(CODABAR)) {
|
|
350
|
+
if (p.length !== 7)
|
|
351
|
+
problems.push(`Codabar '${ch}': ${p.length} elements, expected 7`);
|
|
352
|
+
}
|
|
353
|
+
if (new Set(Object.values(CODABAR)).size !== Object.keys(CODABAR).length) {
|
|
354
|
+
problems.push('Codabar: duplicate patterns');
|
|
290
355
|
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (EAN_L[d][0] !== '0' || EAN_L[d][6] !== '1') {
|
|
296
|
-
problems.push(`EAN L${d}: must start with a space and end with a bar`);
|
|
356
|
+
// --- Code 11: five elements, all distinct.
|
|
357
|
+
for (const [ch, p] of Object.entries(CODE11)) {
|
|
358
|
+
if (p.length !== 5)
|
|
359
|
+
problems.push(`Code11 '${ch}': ${p.length} elements, expected 5`);
|
|
297
360
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (eanAll.size !== 30) problems.push(`EAN: ${eanAll.size} distinct patterns, expected 30`);
|
|
301
|
-
|
|
302
|
-
// --- EAN-13 parity: first row all-L, every row six characters, all distinct.
|
|
303
|
-
if (EAN13_PARITY[0] !== 'LLLLLL') problems.push('EAN-13 parity[0] must be LLLLLL');
|
|
304
|
-
if (new Set(EAN13_PARITY).size !== 10) problems.push('EAN-13 parity rows are not distinct');
|
|
305
|
-
for (const [i, row] of EAN13_PARITY.entries()) {
|
|
306
|
-
if (row.length !== 6) problems.push(`EAN-13 parity[${i}]: ${row.length} entries, expected 6`);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// --- Code 39: nine elements, exactly three wide, all patterns distinct.
|
|
310
|
-
for (const [ch, p] of Object.entries(CODE39)) {
|
|
311
|
-
if (p.length !== 9) problems.push(`Code39 '${ch}': ${p.length} elements, expected 9`);
|
|
312
|
-
if (countWide(p) !== 3) problems.push(`Code39 '${ch}': ${countWide(p)} wide, expected 3`);
|
|
313
|
-
}
|
|
314
|
-
if (new Set(Object.values(CODE39)).size !== Object.keys(CODE39).length) {
|
|
315
|
-
problems.push('Code39: duplicate patterns');
|
|
316
|
-
}
|
|
317
|
-
if (CODE39_CHECK_SET.length !== 43) {
|
|
318
|
-
problems.push(`Code39 check set: ${CODE39_CHECK_SET.length} characters, expected 43`);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// --- Code 93: nine modules across six elements, all patterns distinct.
|
|
322
|
-
for (const [ch, p] of Object.entries(CODE93)) {
|
|
323
|
-
if (p.length !== 6) problems.push(`Code93 '${ch}': ${p.length} elements, expected 6`);
|
|
324
|
-
if (sum(p) !== 9) problems.push(`Code93 '${ch}': ${sum(p)} modules, expected 9`);
|
|
325
|
-
}
|
|
326
|
-
if (new Set(Object.values(CODE93)).size !== Object.keys(CODE93).length) {
|
|
327
|
-
problems.push('Code93: duplicate patterns');
|
|
328
|
-
}
|
|
329
|
-
if (CODE93_VALUES.length !== 47) {
|
|
330
|
-
problems.push(`Code93 values: ${CODE93_VALUES.length}, expected 47`);
|
|
331
|
-
}
|
|
332
|
-
if (Object.keys(CODE93).length !== 47) {
|
|
333
|
-
problems.push(
|
|
334
|
-
`Code93 table: ${Object.keys(CODE93).length} entries, expected 47 ` +
|
|
335
|
-
'(duplicate object keys collapse silently — check the shift characters)'
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
if (new Set(CODE93_VALUES).size !== CODE93_VALUES.length) {
|
|
339
|
-
problems.push('Code93: duplicate entries in the value order');
|
|
340
|
-
}
|
|
341
|
-
for (const ch of CODE93_VALUES) {
|
|
342
|
-
if (!CODE93[ch]) problems.push(`Code93: value character '${ch}' has no pattern`);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// --- Code 128: 107 patterns, 11 modules each, stop 13. All distinct.
|
|
346
|
-
if (CODE128.length !== 107) {
|
|
347
|
-
problems.push(`Code128: ${CODE128.length} patterns, expected 107`);
|
|
348
|
-
}
|
|
349
|
-
for (const [i, p] of CODE128.entries()) {
|
|
350
|
-
const expected = i === CODE128_STOP ? 13 : 11;
|
|
351
|
-
const elements = i === CODE128_STOP ? 7 : 6;
|
|
352
|
-
if (sum(p) !== expected) problems.push(`Code128 [${i}] "${p}": ${sum(p)} modules, expected ${expected}`);
|
|
353
|
-
if (p.length !== elements) problems.push(`Code128 [${i}] "${p}": ${p.length} elements, expected ${elements}`);
|
|
354
|
-
if ([...p].some((c) => c === '0' || Number(c) > 4)) {
|
|
355
|
-
problems.push(`Code128 [${i}] "${p}": element width out of range 1-4`);
|
|
361
|
+
if (new Set(Object.values(CODE11)).size !== Object.keys(CODE11).length) {
|
|
362
|
+
problems.push('Code11: duplicate patterns');
|
|
356
363
|
}
|
|
357
|
-
|
|
358
|
-
if (new Set(CODE128).size !== CODE128.length) problems.push('Code128: duplicate patterns');
|
|
359
|
-
|
|
360
|
-
// --- ITF: five elements, exactly two wide, ten distinct patterns.
|
|
361
|
-
for (const [d, p] of ITF.entries()) {
|
|
362
|
-
if (p.length !== 5) problems.push(`ITF ${d}: ${p.length} elements, expected 5`);
|
|
363
|
-
if (countWide(p) !== 2) problems.push(`ITF ${d}: ${countWide(p)} wide, expected 2`);
|
|
364
|
-
}
|
|
365
|
-
if (new Set(ITF).size !== 10) problems.push('ITF: duplicate patterns');
|
|
366
|
-
|
|
367
|
-
// --- Codabar: seven elements, all distinct.
|
|
368
|
-
for (const [ch, p] of Object.entries(CODABAR)) {
|
|
369
|
-
if (p.length !== 7) problems.push(`Codabar '${ch}': ${p.length} elements, expected 7`);
|
|
370
|
-
}
|
|
371
|
-
if (new Set(Object.values(CODABAR)).size !== Object.keys(CODABAR).length) {
|
|
372
|
-
problems.push('Codabar: duplicate patterns');
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// --- Code 11: five elements, all distinct.
|
|
376
|
-
for (const [ch, p] of Object.entries(CODE11)) {
|
|
377
|
-
if (p.length !== 5) problems.push(`Code11 '${ch}': ${p.length} elements, expected 5`);
|
|
378
|
-
}
|
|
379
|
-
if (new Set(Object.values(CODE11)).size !== Object.keys(CODE11).length) {
|
|
380
|
-
problems.push('Code11: duplicate patterns');
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return problems;
|
|
364
|
+
return problems;
|
|
384
365
|
}
|