Module basic module

Module iconv

iconv encoding and decoding module

Reference method:

1 2
var encoding = require('encoding'); var iconv = encoding.iconv;

or

1
var iconv = require('iconv');

iconv will use the codes installed in the system for processing. The iconv module also supports the following built-in code sets:

1 2 3 4 5 6 7 8 9
"utf8", "utf-8", "ucs2", "ucs-2", "utf16", "utf-16", "ucs2le", "ucs-2le", "utf16le", "utf-16le", "ucs2be", "ucs-2be", "utf16be", "utf-16be", "ucs4", "ucs-4", "utf32", "utf-32", "ucs4le", "ucs-4le", "utf32le", "utf-32le", "ucs4be", "ucs-4be", "utf32be", "utf-32be"

Static function

encode

Convert text to binary data with iconv

1 2
static Buffer iconv.encode(String charset, String data);

Call parameters:

  • charset: String, specify the character set
  • data: String, the text to be converted

Return result:

  • Buffer, Return the decoded binary data

decode

Use iconv to Buffer Convert content to text

1 2
static String iconv.decode(String charset, Buffer data);

Call parameters:

  • charset: String, specify the character set
  • data: Buffer, The binary data to be converted

Return result:

  • String, Return the encoded string

isEncoding

Check whether the character set is supported

1
static Boolean iconv.isEncoding(String charset);

Call parameters:

  • charset: String, specify the character set

Return result:

  • Boolean, Return whether the character set is supported