Skip to content

Commit c7fcc9d

Browse files
author
Alex Tessmer
committed
Move multi-symbol characters to a separate lookup table
1 parent 7e95812 commit c7fcc9d

2 files changed

Lines changed: 91 additions & 55 deletions

File tree

src/barcodes/CODE93/CODE93.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Encoding documentation:
22
// https://en.wikipedia.org/wiki/Code_93#Detailed_outline
33

4-
import { SYMBOLS, BINARIES } from './constants';
4+
import { SYMBOLS, BINARIES, MULTI_SYMBOLS } from './constants';
55
import Barcode from "../Barcode.js";
66

77
class CODE93 extends Barcode {
@@ -16,15 +16,7 @@ class CODE93 extends Barcode {
1616
encode(){
1717
const symbols = this.data
1818
.split('')
19-
.flatMap(c => {
20-
const encoding = CODE93.getEncoding(c);
21-
if (typeof(encoding) === 'string') {
22-
// Single-symbol character
23-
return c;
24-
}
25-
// Multi-symbol character
26-
return encoding;
27-
});
19+
.flatMap(c => MULTI_SYMBOLS[c] || c);
2820
const encoded = symbols
2921
.map(s => CODE93.getEncoding(s))
3022
.join('');

src/barcodes/CODE93/constants.js

Lines changed: 89 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,6 @@ export const SYMBOLS = [
1515
'($)', '(%)', '(/)', '(+)',
1616
// Start/Stop
1717
'\xff',
18-
// Multi-sequence characters (Full ASCII Code 93)
19-
'\x00', '\x01', '\x02', '\x03',
20-
'\x04', '\x04', '\x06', '\x07',
21-
'\x08', '\x09', '\x0a', '\x0b',
22-
'\x0c', '\x0d', '\x0e', '\x0f',
23-
'\x10', '\x11', '\x12', '\x13',
24-
'\x14', '\x14', '\x16', '\x17',
25-
'\x18', '\x19', '\x1a', '\x1b',
26-
'\x1c', '\x1d', '\x1e', '\x1f',
27-
'!', '"', '#', '&',
28-
'\'', '(', ')', '*',
29-
',', ':', ';', '<',
30-
'=', '>', '?', '@',
31-
'[', '\\', ']', '^',
32-
'_', '`', 'a', 'b',
33-
'c', 'd', 'e', 'f',
34-
'g', 'h', 'i', 'j',
35-
'k', 'l', 'm', 'n',
36-
'o', 'p', 'q', 'r',
37-
's', 't', 'u', 'v',
38-
'w', 'x', 'y', 'z',
39-
'{', '|', '}', '~',
40-
'\x7f',
4118
];
4219

4320
// Order matches SYMBOLS array
@@ -54,26 +31,93 @@ export const BINARIES = [
5431
'100101110', '111010100', '111010010', '111001010',
5532
'101101110', '101110110', '110101110', '100100110',
5633
'111011010', '111010110', '100110010', '101011110',
57-
['(%)', 'U'], ['($)', 'A'], ['($)', 'B'], ['($)', 'C'],
58-
['($)', 'D'], ['($)', 'E'], ['($)', 'F'], ['($)', 'G'],
59-
['($)', 'H'], ['($)', 'I'], ['($)', 'J'], ['($)', 'K'],
60-
['($)', 'L'], ['($)', 'M'], ['($)', 'N'], ['($)', 'O'],
61-
['($)', 'P'], ['($)', 'Q'], ['($)', 'R'], ['($)', 'S'],
62-
['($)', 'T'], ['($)', 'U'], ['($)', 'V'], ['($)', 'W'],
63-
['($)', 'X'], ['($)', 'Y'], ['($)', 'Z'], ['(%)', 'A'],
64-
['(%)', 'B'], ['(%)', 'C'], ['(%)', 'D'], ['(%)', 'E'],
65-
['(/)', 'A'], ['(/)', 'B'], ['(/)', 'C'], ['(/)', 'F'],
66-
['(/)', 'G'], ['(/)', 'H'], ['(/)', 'I'], ['(/)', 'J'],
67-
['(/)', 'L'], ['(/)', 'Z'], ['(%)', 'F'], ['(%)', 'G'],
68-
['(%)', 'H'], ['(%)', 'I'], ['(%)', 'J'], ['(%)', 'V'],
69-
['(%)', 'K'], ['(%)', 'L'], ['(%)', 'M'], ['(%)', 'N'],
70-
['(%)', 'O'], ['(%)', 'W'], ['(+)', 'A'], ['(+)', 'B'],
71-
['(+)', 'C'], ['(+)', 'D'], ['(+)', 'E'], ['(+)', 'F'],
72-
['(+)', 'G'], ['(+)', 'H'], ['(+)', 'I'], ['(+)', 'J'],
73-
['(+)', 'K'], ['(+)', 'L'], ['(+)', 'M'], ['(+)', 'N'],
74-
['(+)', 'O'], ['(+)', 'P'], ['(+)', 'Q'], ['(+)', 'R'],
75-
['(+)', 'S'], ['(+)', 'T'], ['(+)', 'U'], ['(+)', 'V'],
76-
['(+)', 'W'], ['(+)', 'X'], ['(+)', 'Y'], ['(+)', 'Z'],
77-
['(%)', 'P'], ['(%)', 'Q'], ['(%)', 'R'], ['(%)', 'S'],
78-
['(%)', 'T'],
7934
];
35+
36+
// Multi-symbol characters (Full ASCII Code 93)
37+
export const MULTI_SYMBOLS = {
38+
'\x00': ['(%)', 'U'],
39+
'\x01': ['($)', 'A'],
40+
'\x02': ['($)', 'B'],
41+
'\x03': ['($)', 'C'],
42+
'\x04': ['($)', 'D'],
43+
'\x05': ['($)', 'E'],
44+
'\x06': ['($)', 'F'],
45+
'\x07': ['($)', 'G'],
46+
'\x08': ['($)', 'H'],
47+
'\x09': ['($)', 'I'],
48+
'\x0a': ['($)', 'J'],
49+
'\x0b': ['($)', 'K'],
50+
'\x0c': ['($)', 'L'],
51+
'\x0d': ['($)', 'M'],
52+
'\x0e': ['($)', 'N'],
53+
'\x0f': ['($)', 'O'],
54+
'\x10': ['($)', 'P'],
55+
'\x11': ['($)', 'Q'],
56+
'\x12': ['($)', 'R'],
57+
'\x13': ['($)', 'S'],
58+
'\x14': ['($)', 'T'],
59+
'\x15': ['($)', 'U'],
60+
'\x16': ['($)', 'V'],
61+
'\x17': ['($)', 'W'],
62+
'\x18': ['($)', 'X'],
63+
'\x19': ['($)', 'Y'],
64+
'\x1a': ['($)', 'Z'],
65+
'\x1b': ['(%)', 'A'],
66+
'\x1c': ['(%)', 'B'],
67+
'\x1d': ['(%)', 'C'],
68+
'\x1e': ['(%)', 'D'],
69+
'\x1f': ['(%)', 'E'],
70+
'!': ['(/)', 'A'],
71+
'"': ['(/)', 'B'],
72+
'#': ['(/)', 'C'],
73+
'&': ['(/)', 'F'],
74+
'\'': ['(/)', 'G'],
75+
'(': ['(/)', 'H'],
76+
')': ['(/)', 'I'],
77+
'*': ['(/)', 'J'],
78+
',': ['(/)', 'L'],
79+
':': ['(/)', 'Z'],
80+
';': ['(%)', 'F'],
81+
'<': ['(%)', 'G'],
82+
'=': ['(%)', 'H'],
83+
'>': ['(%)', 'I'],
84+
'?': ['(%)', 'J'],
85+
'@': ['(%)', 'V'],
86+
'[': ['(%)', 'K'],
87+
'\\': ['(%)', 'L'],
88+
']': ['(%)', 'M'],
89+
'^': ['(%)', 'N'],
90+
'_': ['(%)', 'O'],
91+
'`': ['(%)', 'W'],
92+
'a': ['(+)', 'A'],
93+
'b': ['(+)', 'B'],
94+
'c': ['(+)', 'C'],
95+
'd': ['(+)', 'D'],
96+
'e': ['(+)', 'E'],
97+
'f': ['(+)', 'F'],
98+
'g': ['(+)', 'G'],
99+
'h': ['(+)', 'H'],
100+
'i': ['(+)', 'I'],
101+
'j': ['(+)', 'J'],
102+
'k': ['(+)', 'K'],
103+
'l': ['(+)', 'L'],
104+
'm': ['(+)', 'M'],
105+
'n': ['(+)', 'N'],
106+
'o': ['(+)', 'O'],
107+
'p': ['(+)', 'P'],
108+
'q': ['(+)', 'Q'],
109+
'r': ['(+)', 'R'],
110+
's': ['(+)', 'S'],
111+
't': ['(+)', 'T'],
112+
'u': ['(+)', 'U'],
113+
'v': ['(+)', 'V'],
114+
'w': ['(+)', 'W'],
115+
'x': ['(+)', 'X'],
116+
'y': ['(+)', 'Y'],
117+
'z': ['(+)', 'Z'],
118+
'{': ['(%)', 'P'],
119+
'|': ['(%)', 'Q'],
120+
'}': ['(%)', 'R'],
121+
'~': ['(%)', 'S'],
122+
'\x7f': ['(%)', 'T'],
123+
};

0 commit comments

Comments
 (0)