| Lines of Code | 33 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | // Encoding documentation: |
||
| 4 | import EANencoder from './ean_encoder.js'; |
||
| 5 | |||
| 6 | class EAN2{ |
||
| 7 | constructor(string){ |
||
| 8 | this.string = string; |
||
| 9 | |||
| 10 | this.structure = ["LL", "LG", "GL", "GG"]; |
||
| 11 | } |
||
| 12 | |||
| 13 | valid(){ |
||
| 14 | return this.string.search(/^[0-9]{2}$/) !== -1; |
||
| 15 | } |
||
| 16 | |||
| 17 | encode(){ |
||
| 18 | var encoder = new EANencoder(); |
||
| 19 | |||
| 20 | // Choose the structure based on the number mod 4 |
||
| 21 | var structure = this.structure[parseInt(this.string) % 4]; |
||
| 22 | |||
| 23 | // Start bits |
||
| 24 | var result = "1011"; |
||
| 25 | |||
| 26 | // Encode the two digits with 01 in between |
||
| 27 | result += encoder.encode(this.string, structure, "01"); |
||
| 28 | |||
| 29 | return { |
||
| 30 | data: result, |
||
| 31 | text: this.string |
||
| 32 | }; |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | export default EAN2; |
||
| 37 |