Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion encodings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
20 changes: 20 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/utf7-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down