1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- var Mode = require('./mode')
- var 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',
- ' ', '$', '%', '*', '+', '-', '.', '/', ':'
- ]
- function AlphanumericData (data) {
- this.mode = Mode.ALPHANUMERIC
- this.data = data
- }
- AlphanumericData.getBitsLength = function getBitsLength (length) {
- return 11 * Math.floor(length / 2) + 6 * (length % 2)
- }
- AlphanumericData.prototype.getLength = function getLength () {
- return this.data.length
- }
- AlphanumericData.prototype.getBitsLength = function getBitsLength () {
- return AlphanumericData.getBitsLength(this.data.length)
- }
- AlphanumericData.prototype.write = function write (bitBuffer) {
- var i
-
-
- for (i = 0; i + 2 <= this.data.length; i += 2) {
-
- var value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45
-
- value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1])
-
- bitBuffer.put(value, 11)
- }
-
-
- if (this.data.length % 2) {
- bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6)
- }
- }
- module.exports = AlphanumericData
|