diff --git a/encodings/index.js b/encodings/index.js index d95c2441..4a46426a 100644 --- a/encodings/index.js +++ b/encodings/index.js @@ -6,7 +6,8 @@ var modules = [ require("./internal"), require("./utf32"), require("./utf16"), - require("./utf7"), + // require("./utf7"), + // require("../externalEcods/utf7"), require("./sbcs-codec"), require("./sbcs-data"), require("./sbcs-data-generated"), diff --git a/lib/index.js b/lib/index.js index 657701c3..deb7749d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -52,6 +52,26 @@ iconv.encodingExists = function encodingExists(enc) { } } +/** + * input an encodes + * @param {string} enc + * @param {string} src + * @param {boolean} replace override existing encodings/aliases + */ +iconv.addEncoding = function (enc,src, replace) { + console.log('added'); + var hasExt = iconv.encodingExists(enc) + if (!hasExt || (hasExt && replace)) { + // iconv.encodings = {} + var exEcods = require(src) + for (const key in exEcods) { + if (Object.hasOwnProperty.call(exEcods, key)) { + iconv.encodings[key] = exEcods[key]; + } + } + } +} + // Legacy aliases to convert functions iconv.toEncoding = iconv.encode; iconv.fromEncoding = iconv.decode; diff --git a/test/utf7-test.js b/test/utf7-test.js index 37d7cfaf..99e4cbdb 100644 --- a/test/utf7-test.js +++ b/test/utf7-test.js @@ -5,6 +5,10 @@ var assert = require('assert'), // These tests are mostly from https://github.com/kkaefer/utf7 // In case of ambiguity, we do the same as iconv. For example, we encode "optional direct" characters, but leave spaces and \n\r\t as-is. +// now,utf7 is a external encodingExists,we need add +if (!iconv.encodingExists('utf7')) { + iconv.addEncoding('utf7',"../externalEcods/utf7") +} describe("UTF-7 codec", function() { it("encodes correctly", function() { // Examples from RFC 2152.