How to use iconv - 10 common examples

To help you get started, we’ve selected a few iconv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tilakpatidar / bot-marvin / lib / rss.js View on Github external
function maybeTranslate (res, charset) {
      var iconv;
      // Use iconv if its not utf8 already.
      if (!iconv && charset && !/utf-*8/i.test(charset)) {
        try {
          iconv = new Iconv(charset, 'utf-8');
          console.log('Converting from charset %s to utf-8', charset);
          iconv.on('error', function(){
            res.emit('error', err);
          });
          // If we're using iconv, stream will be the output of iconv
          // otherwise it will remain the output of request
          res = res.pipe(iconv);
        } catch(err) {
          
        }
      }
      return res;
    }
github kof / kiipost / api / extractor / CharsetConverter.js View on Github external
CharsetConverter.prototype._onData = function(data) {
    var error
    if (this.data) data = Buffer.concat([this.data, data])
    if (!this.charset) this.charset = this._detectCharset(data)

    // Init iconv if encoding is not utf-8.
    if (!this.iconv && this.charset != 'utf-8') {
        try {
            this.iconv = new Iconv(this.charset, 'utf-8')
        } catch(err) {
            error = err
            this.stream.emit('error', new ExtError(err.message, {
                err: err,
                encoding: this.charset
            }))
        }
    }

    if (this.iconv) {
        try {
            data = this.iconv.convert(data)
            // We are able to convert, now we can cleanup our data.
            this.data = null
        } catch(err) {
            error = err
github hustcer / star / lib / watch.js View on Github external
* @copyright   uzfin.com
 * @create      06/24/2015
 */

let vm      = require('vm'),
    fs      = require('fs'),
    _       = require('lodash'),
    yaml    = require('js-yaml'),
    blessed = require('blessed'),
    Promise = require('bluebird'),
    cmd     = require('commander'),
    contrib = require('blessed-contrib');

let conf    = require('./conf').conf;
let Iconv   = require('iconv').Iconv;
let iconv   = new Iconv('GBK', 'UTF-8//TRANSLIT//IGNORE');
let request = Promise.promisifyAll(require('request'), {multiArgs:true});

let table   = null;
let screen  = blessed.screen({ fullUnicode:true });

const MSG = {
    INPUT_ERROR      : '输入错误,当前只支持通过证券代码看盘,请检查后重新输入!',
    TOO_MANY_SYMS    : '输入的股票太多,一次最多支持盯盘25只股票!',
    SYMBOL_NOT_EXIST : '该股票代码不存在:',
};

// A client error like 400 Bad Request happened
let ClientError = e => (e.code >= 400 && e.code < 500 || e.code === 'ENOTFOUND');

// Set current data source
let src    = (cmd.data || '').toUpperCase();
github narirou / jconv / test / speed.js View on Github external
function speedTest( from, to ) {
	var FROM    = from.toUpperCase(),
		TO      = to.toUpperCase(),
		fixFROM = fixEncoding[ FROM ] || FROM,
		fixTO   = fixEncoding[ TO ] || TO;

	var _jconv  = jconv;
	var _iconv  = new Iconv( fixFROM, fixTO + '//TRANSLIT//IGNORE' );

	var buffer  = fs.readFileSync( inputPath + FROM + '.TXT' );
	var title   = '[ ' + FROM + ' -> ' + TO + ' ]';

	log( title );

	var suite = new Benchmark.Suite;
	suite
		.add( 'jconv', function() {
			_jconv.convert( buffer, FROM, TO );
		})
		.add( 'iconv', function() {
			_iconv.convert( buffer );
		})
		.on( 'cycle', function( event ) {
			log( String( event.target ) );
github assistunion / xml-stream / lib / xml-stream.js View on Github external
function makeEncoder(encoding) {
  if (encoding && !/^utf-?8$/i.test(encoding)) {
    return new Iconv(encoding, 'utf8');
  }
  return null;
}
github lijinma / wechat_spider / lib / csv.js View on Github external
var db = require('./db.js'),
  fs = require('fs'),
  Iconv = require('iconv').Iconv;

var iconv = new Iconv('UTF-8', 'GBK//TRANSLIT//IGNORE');

var csvFile = process.cwd() + '/wechat.csv';

var getFormatDate = function (date) {
  return date.getFullYear() + '-' +
    ("0" + (date.getMonth() + 1)).slice(-2) + '-' +
    ("0" + (date.getDate())).slice(-2) + ' ' +
    ("0" + date.getHours()).slice(-2) + ':' +
    ("0" + date.getMinutes()).slice(-2) + ':' +
    ("0" + date.getSeconds()).slice(-2);
}

var saveAll = function () {
  var headers = [
    'accountName',
    'author',
github TooTallNate / ref-wchar / index.js View on Github external
/**
 * On Windows they're UTF-16 (2-bytes),
 * but on Unix platform they're UTF-32 (4-bytes).
 *
 * TODO: add a way to optionally enable `-fshort-wchar` for Unix (gcc option).
 */

var size;
if ('win32' == process.platform) {
  size = 2;
} else {
  size = 4;
}

var getter = new Iconv('UTF-' + (8 * size) + ref.endianness, 'UTF-8');
var setter = new Iconv('UTF-8', 'UTF-' + (8 * size) + ref.endianness);


/**
 * The `wchar_t` type.
 */

exports = module.exports = Object.create(ref.types['int' + (8 * size)]);
exports.name = 'wchar_t';
exports.size = size;
exports.indirection = 1;
exports.get = function get (buf, offset) {
  if (offset > 0 || buf.length !== exports.size) {
    offset = offset | 0;
    buf = buf.slice(offset, offset + size);
  }
  return exports.toString(buf);
github shlee322 / delivery-tracker / apiserver / carriers / kr.logen / index.js View on Github external
const iconv  = new (require('iconv').Iconv)('EUC-KR', 'UTF-8//TRANSLIT//IGNORE')
const axios = require('axios')
const { JSDOM } = require('jsdom')
const qs = require('querystring')

function parseStatus(s) {
  if(s.includes('터미널입고')) return {id: 'at_pickup', text:'상품인수'}
  if(s.includes('배송출고')) return {id: 'out_for_delivery', text:'배송출발'}
  if(s.includes('배송완료')) return {id: 'delivered', text:'배송완료'}

  return {id: 'in_transit', text: '이동중'}
}

function getTrack(trackId) {
  const trimString = (s) => {
    return s.replace(/([\n\t]{1,}|\s{2,})/g, ' ').trim()
  }
github accesolibre / proxy / lib / encodingstream.js View on Github external
function encodeChunk(chunk) {
        if (charset in charset_aliases) {
            return new Buffer(chunk, charset_aliases[charset]);
        } else {
            if (!encodeIconv) encodeIconv = new Iconv('UTF-8', charset + '//TRANSLIT//IGNORE');
            return encodeIconv.convert(chunk);
        }
    }
github nodemailer / mailparser / mime.js View on Github external
function toCharset(charset, buffer){
    var iconv = new Iconv('UTF-8',charset);
    return iconv.convert(buffer);
}

iconv

Text recoding in JavaScript for fun and profit!

ISC
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis

Popular iconv functions