* Convert encoding of astring with iconv-lite * * @param {String|Buffer} str String to be converted * @param {String} to Encoding to be converted to * @param {String} [from='UTF-8'] Encoding to be converted from * @return {Buffer} Encoded string
(str, to, from)
| 55 | * @return {Buffer} Encoded string |
| 56 | */ |
| 57 | function convertIconvLite(str, to, from) { |
| 58 | if (to === 'UTF-8') { |
| 59 | return iconvLite.decode(str, from); |
| 60 | } else if (from === 'UTF-8') { |
| 61 | return iconvLite.encode(str, to); |
| 62 | } else { |
| 63 | return iconvLite.encode(iconvLite.decode(str, from), to); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Converts charset name if needed |