• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Encoding
2
3**encoding** is a simple wrapper around [node-iconv](https://github.com/bnoordhuis/node-iconv) and [iconv-lite](https://github.com/ashtuchkin/iconv-lite/) to convert strings from one encoding to another. If node-iconv is not available for some reason,
4iconv-lite will be used instead of it as a fallback.
5
6[![Build Status](https://secure.travis-ci.org/andris9/encoding.svg)](http://travis-ci.org/andris9/Nodemailer)
7[![npm version](https://badge.fury.io/js/encoding.svg)](http://badge.fury.io/js/encoding)
8
9## Install
10
11Install through npm
12
13    npm install encoding
14
15## Usage
16
17Require the module
18
19    var encoding = require("encoding");
20
21Convert with encoding.convert()
22
23    var resultBuffer = encoding.convert(text, toCharset, fromCharset);
24
25Where
26
27  * **text** is either a Buffer or a String to be converted
28  * **toCharset** is the characterset to convert the string
29  * **fromCharset** (*optional*, defaults to UTF-8) is the source charset
30
31Output of the conversion is always a Buffer object.
32
33Example
34
35    var result = encoding.convert("ÕÄÖÜ", "Latin_1");
36    console.log(result); //<Buffer d5 c4 d6 dc>
37
38## iconv support
39
40By default only iconv-lite is bundled. If you need node-iconv support, you need to add it
41as an additional dependency for your project:
42
43    ...,
44    "dependencies":{
45        "encoding": "*",
46        "iconv": "*"
47    },
48    ...
49
50## License
51
52**MIT**
53