| 51 | ]; |
| 52 | |
| 53 | export class MinimalEncoder { |
| 54 | static isExtendedASCII(ch: char, fnc1: number): boolean { |
| 55 | return ch !== fnc1 && ch >= 128 && ch <= 255; |
| 56 | } |
| 57 | |
| 58 | static isInC40Shift1Set(ch: char): boolean { |
| 59 | return ch <= 31; |
| 60 | } |
| 61 | |
| 62 | static isInC40Shift2Set(ch: char, fnc1: number): boolean { |
| 63 | for (const c40Shift2Char of C40_SHIFT2_CHARS) { |
| 64 | if (c40Shift2Char.charCodeAt(0) === ch) { |
| 65 | return true; |
| 66 | } |
| 67 | } |
| 68 | return ch === fnc1; |
| 69 | } |
| 70 | |
| 71 | static isInTextShift1Set(ch: char): boolean { |
| 72 | return this.isInC40Shift1Set(ch); |
| 73 | } |
| 74 | |
| 75 | static isInTextShift2Set(ch: char, fnc1: number): boolean { |
| 76 | return this.isInC40Shift2Set(ch, fnc1); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Performs message encoding of a DataMatrix message |
| 81 | * |
| 82 | * @param msg the message |
| 83 | * @param priorityCharset The preferred {@link Charset}. When the value of the argument is null, the algorithm |
| 84 | * chooses charsets that leads to a minimal representation. Otherwise the algorithm will use the priority |
| 85 | * charset to encode any character in the input that can be encoded by it if the charset is among the |
| 86 | * supported charsets. |
| 87 | * @param fnc1 denotes the character in the input that represents the FNC1 character or -1 if this is not a GS1 |
| 88 | * bar code. If the value is not -1 then a FNC1 is also prepended. |
| 89 | * @param shape requested shape. |
| 90 | * @return the encoded message (the char values range from 0 to 255) |
| 91 | */ |
| 92 | static encodeHighLevel( |
| 93 | msg: string, |
| 94 | priorityCharset: Charset = null, |
| 95 | fnc1 = -1, |
| 96 | shape = SymbolShapeHint.FORCE_NONE |
| 97 | ): string { |
| 98 | let macroId = 0; |
| 99 | if (msg.startsWith(MACRO_05_HEADER) && msg.endsWith(MACRO_TRAILER)) { |
| 100 | macroId = 5; |
| 101 | msg = msg.substring(MACRO_05_HEADER.length, msg.length - 2); |
| 102 | } else if (msg.startsWith(MACRO_06_HEADER) && msg.endsWith(MACRO_TRAILER)) { |
| 103 | macroId = 6; |
| 104 | msg = msg.substring(MACRO_06_HEADER.length, msg.length - 2); |
| 105 | } |
| 106 | return decodeURIComponent( |
| 107 | escape( |
| 108 | String.fromCharCode( |
| 109 | ...this.encode(msg, priorityCharset, fnc1, shape, macroId) |
| 110 | ) |
nothing calls this directly
no outgoing calls
no test coverage detected