index.js 815 B

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