1
hao
2025-03-27 e610e1c17f62b423a717fadaaa7b139d02857793
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Encoding documentation
// http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf
 
import Barcode from "../Barcode.js";
 
class pharmacode extends Barcode{
    constructor(data, options){
        super(data, options);
        this.number = parseInt(data, 10);
    }
 
    encode(){
        var z = this.number;
        var result = "";
 
        // http://i.imgur.com/RMm4UDJ.png
        // (source: http://www.gomaro.ch/ftproot/Laetus_PHARMA-CODE.pdf, page: 34)
        while(!isNaN(z) && z != 0){
            if(z % 2 === 0){ // Even
                result = "11100" + result;
                z = (z - 2) / 2;
            }
            else{ // Odd
                result = "100" + result;
                z = (z - 1) / 2;
            }
        }
 
        // Remove the two last zeroes
        result = result.slice(0, -2);
 
        return {
            data: result,
            text: this.text
        };
    }
 
    valid(){
        return this.number >= 3 && this.number <= 131070;
    }
}
 
export {pharmacode};