2017-05-07 18:07:56 -04:00
|
|
|
import cptable from "../lib/codepage.js";
|
2017-03-23 17:52:20 +00:00
|
|
|
import Utils from "../Utils.js";
|
|
|
|
import CryptoJS from "crypto-js";
|
2017-03-06 12:45:51 +00:00
|
|
|
|
2016-11-28 10:42:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Character encoding operations.
|
|
|
|
*
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*
|
|
|
|
* @namespace
|
|
|
|
*/
|
2017-03-23 17:52:20 +00:00
|
|
|
const CharEnc = {
|
2016-11-28 10:42:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @default
|
|
|
|
*/
|
2017-05-17 11:17:11 -04:00
|
|
|
IO_FORMAT: {
|
|
|
|
"UTF-8": 65001,
|
|
|
|
"UTF-7": 65000,
|
|
|
|
"UTF16LE": 1200,
|
|
|
|
"UTF16BE": 1201,
|
|
|
|
"UTF16": 1201,
|
2017-05-07 18:07:56 -04:00
|
|
|
"IBM EBCDIC International": 500,
|
|
|
|
"IBM EBCDIC US-Canada": 37,
|
2017-05-17 11:17:11 -04:00
|
|
|
"Windows-874 Thai": 874,
|
|
|
|
"Japanese Shift-JIS": 932,
|
|
|
|
"Simplified Chinese GBK": 936,
|
|
|
|
"Korean": 949,
|
|
|
|
"Traditional Chinese Big5": 950,
|
|
|
|
"Windows-1250 Central European": 1250,
|
|
|
|
"Windows-1251 Cyrillic": 1251,
|
|
|
|
"Windows-1252 Latin": 1252,
|
|
|
|
"Windows-1253 Greek": 1253,
|
|
|
|
"Windows-1254 Turkish": 1254,
|
|
|
|
"Windows-1255 Hebrew": 1255,
|
|
|
|
"Windows-1256 Arabic": 1256,
|
|
|
|
"Windows-1257 Baltic": 1257,
|
|
|
|
"Windows-1258 Vietnam": 1258,
|
|
|
|
"US-ASCII": 20127,
|
|
|
|
"Russian Cyrillic KOI8-R": 20866,
|
|
|
|
"Simplified Chinese GB2312": 20936,
|
|
|
|
"KOI8-U Ukrainian Cyrillic": 21866,
|
|
|
|
"ISO-8859-1 Latin 1 (Western European)": 28591,
|
|
|
|
"ISO-8859-2 Latin 2 (Central European)": 28592,
|
|
|
|
"ISO-8859-3 Latin 3": 28593,
|
|
|
|
"ISO-8859-4 Baltic": 28594,
|
|
|
|
"ISO-8859-5 Cyrillic": 28595,
|
|
|
|
"ISO-8859-6 Arabic": 28596,
|
|
|
|
"ISO-8859-7 Greek": 28597,
|
|
|
|
"ISO-8859-8 Hebrew": 28598,
|
|
|
|
"ISO-8859-9 Turkish": 28599,
|
|
|
|
"ISO-8859-10 Latin 6": 28600,
|
|
|
|
"ISO-8859-11 Latin (Thai)": 28601,
|
|
|
|
"ISO-8859-13 Latin 7 (Estonian)": 28603,
|
|
|
|
"ISO-8859-14 Latin 8 (Celtic)": 28604,
|
|
|
|
"ISO-8859-15 Latin 9": 28605,
|
|
|
|
"ISO-8859-16 Latin 10": 28606,
|
|
|
|
"ISO-2022 JIS Japanese": 50222,
|
|
|
|
"EUC Japanese": 51932,
|
|
|
|
"EUC Korean": 51949,
|
|
|
|
"Simplified Chinese GB18030": 54936,
|
2017-05-07 18:07:56 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2017-05-17 11:17:11 -04:00
|
|
|
* Encode text operation.
|
2017-05-17 17:31:28 -04:00
|
|
|
* @author tlwr [toby@toby.codes]
|
2017-05-07 18:07:56 -04:00
|
|
|
*
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {byteArray}
|
|
|
|
*/
|
2017-05-17 11:17:11 -04:00
|
|
|
runEncode: function(input, args) {
|
|
|
|
let format = CharEnc.IO_FORMAT[args[0]];
|
|
|
|
let encoded = cptable.utils.encode(format, input);
|
|
|
|
encoded = Array.from(encoded);
|
|
|
|
return encoded;
|
2017-05-07 18:07:56 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2017-05-17 11:17:11 -04:00
|
|
|
* Decode text operation.
|
2017-05-17 17:31:28 -04:00
|
|
|
* @author tlwr [toby@toby.codes]
|
2017-05-07 18:07:56 -04:00
|
|
|
*
|
|
|
|
* @param {byteArray} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2017-05-17 11:17:11 -04:00
|
|
|
runDecode: function(input, args) {
|
|
|
|
let format = CharEnc.IO_FORMAT[args[0]];
|
|
|
|
let decoded = cptable.utils.decode(format, input);
|
|
|
|
return decoded;
|
2017-05-07 18:07:56 -04:00
|
|
|
},
|
2016-11-28 10:42:58 +00:00
|
|
|
};
|
2017-03-23 17:52:20 +00:00
|
|
|
|
|
|
|
export default CharEnc;
|