c79d0b18a195ffb61650b426af0a6ab14d114fe6d12014dd84a7aec56bee8fac.json raw
1 {"ast":null,"code":"const Mode = require('./mode');\n\n/**\n * Array of characters available in alphanumeric mode\n *\n * As per QR Code specification, to each character\n * is assigned a value from 0 to 44 which in this case coincides\n * with the array index\n *\n * @type {Array}\n */\nconst ALPHA_NUM_CHARS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'];\nfunction AlphanumericData(data) {\n this.mode = Mode.ALPHANUMERIC;\n this.data = data;\n}\nAlphanumericData.getBitsLength = function getBitsLength(length) {\n return 11 * Math.floor(length / 2) + 6 * (length % 2);\n};\nAlphanumericData.prototype.getLength = function getLength() {\n return this.data.length;\n};\nAlphanumericData.prototype.getBitsLength = function getBitsLength() {\n return AlphanumericData.getBitsLength(this.data.length);\n};\nAlphanumericData.prototype.write = function write(bitBuffer) {\n let i;\n\n // Input data characters are divided into groups of two characters\n // and encoded as 11-bit binary codes.\n for (i = 0; i + 2 <= this.data.length; i += 2) {\n // The character value of the first character is multiplied by 45\n let value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45;\n\n // The character value of the second digit is added to the product\n value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]);\n\n // The sum is then stored as 11-bit binary number\n bitBuffer.put(value, 11);\n }\n\n // If the number of input data characters is not a multiple of two,\n // the character value of the final character is encoded as a 6-bit binary number.\n if (this.data.length % 2) {\n bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);\n }\n};\nmodule.exports = AlphanumericData;","map":null,"metadata":{},"sourceType":"script","externalDependencies":[]}