{"ast":null,"code":"const Mode = require('./mode');\nconst Utils = require('./utils');\nfunction KanjiData(data) {\n  this.mode = Mode.KANJI;\n  this.data = data;\n}\nKanjiData.getBitsLength = function getBitsLength(length) {\n  return length * 13;\n};\nKanjiData.prototype.getLength = function getLength() {\n  return this.data.length;\n};\nKanjiData.prototype.getBitsLength = function getBitsLength() {\n  return KanjiData.getBitsLength(this.data.length);\n};\nKanjiData.prototype.write = function (bitBuffer) {\n  let i;\n\n  // In the Shift JIS system, Kanji characters are represented by a two byte combination.\n  // These byte values are shifted from the JIS X 0208 values.\n  // JIS X 0208 gives details of the shift coded representation.\n  for (i = 0; i < this.data.length; i++) {\n    let value = Utils.toSJIS(this.data[i]);\n\n    // For characters with Shift JIS values from 0x8140 to 0x9FFC:\n    if (value >= 0x8140 && value <= 0x9FFC) {\n      // Subtract 0x8140 from Shift JIS value\n      value -= 0x8140;\n\n      // For characters with Shift JIS values from 0xE040 to 0xEBBF\n    } else if (value >= 0xE040 && value <= 0xEBBF) {\n      // Subtract 0xC140 from Shift JIS value\n      value -= 0xC140;\n    } else {\n      throw new Error('Invalid SJIS character: ' + this.data[i] + '\\n' + 'Make sure your charset is UTF-8');\n    }\n\n    // Multiply most significant byte of result by 0xC0\n    // and add least significant byte to product\n    value = (value >>> 8 & 0xff) * 0xC0 + (value & 0xff);\n\n    // Convert result to a 13-bit binary string\n    bitBuffer.put(value, 13);\n  }\n};\nmodule.exports = KanjiData;","map":null,"metadata":{},"sourceType":"script","externalDependencies":[]}