How to use iconv-lite - 10 common examples

To help you get started, we’ve selected a few iconv-lite 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 mongaku / mongaku / tests / init.js View on Github external
const fs = require("fs");
const path = require("path");

const tap = require("tap");
const sinon = require("sinon");
const mockfs = require("mock-fs");
const async = require("async");
const iconv = require("iconv-lite");

// Force ICONV to pre-load its encodings
iconv.getCodec("utf8");

// Force babel sub-modules to preload
require("babel-preset-react");
require("babel-helper-builder-react-jsx");
require("babel-plugin-flow-react-proptypes");
require("../lib/babel");

// Load in global ENV
process.env.BASE_DATA_DIR = path.resolve(process.cwd(), "data");

const record = require("../lib/record");
const models = require("../lib/models");
const options = require("../lib/options");
const similarity = require("../lib/similar");
const server = require("../server/server");
github jeresig / pharos-images / tests / init.js View on Github external
process.env.BASE_DATA_DIR = process.cwd();
process.env.PASTEC_URL = "localhost:4212";
process.env.ELASTICSEARCH_URL = "http://localhost:9200";

const fs = require("fs");
const path = require("path");

const tap = require("tap");
const sinon = require("sinon");
const mockfs = require("mock-fs");
const async = require("async");
const iconv = require("iconv-lite");

// Force ICONV to pre-load its encodings
iconv.getCodec("utf8");

// Force babel sub-modules to preload
require("babel-preset-react");
require("babel-helper-builder-react-jsx");
require("babel-register");

const models = require("../lib/models");
const similarity = require("../lib/similar");
const server = require("../server/server");

// Models used for testing
const Image = models("Image");
const Artwork = models("Artwork");
const Source = models("Source");
const ImageImport = models("ImageImport");
const ArtworkImport = models("ArtworkImport");
github petermikitsh / myethereumapp / src / server / __tests__ / __setup__.js View on Github external
import iconv from 'iconv-lite';
import encodings from 'iconv-lite/encodings';
import enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

// For info on this hack:
// https://stackoverflow.com/questions/46227783/encoding-not-recognized-in-jest-js
iconv.encodings = encodings;

enzyme.configure({ adapter: new Adapter() });
github AntSwordProject / antSword / source / modules / filemanager / index.js View on Github external
if (ret === '1') {
            toastr.success(LANG['editor']['success'](path), LANG_T['success']);
            // 刷新目录(显示更改时间、大小等)
            self.files.refreshPath();
          } else {
            toastr.error(LANG['editor']['error'](path, ret === '0' ? '' : '<br>' + ret), LANG_T['error']);
          }
        }).catch((err) =&gt; {

        });
      } else if (id.startsWith('mode_')) {
        let mode = id.split('_')[1];
        editor.session.setMode(`ace/mode/${mode}`);
      } else if (id.startsWith('encode_')) {
        let encode = id.split('_')[1];
        editor.session.setValue(iconv.decode(Buffer.from(codes), encode).toString());
      } else if (id === 'refresh') {
        // 获取文件代码
        win.progressOn()
        this.core.request(
          this.core.filemanager.read_file({
            path: path
          })
        ).then((res) =&gt; {
          win.progressOff();
          name = path.substr(path.lastIndexOf('/') + 1);
          if (openfileintab == false) {
            win.setText(LANG['editor']['title'](antSword.noxss(path)));
          } else {
            win.setText(`<i class="fa fa-file-o"></i> ${antSword.noxss(name)}`);
          }
          ext = name.substr(name.lastIndexOf('.') + 1);
github GetStream / Winds / api / services / parse.js View on Github external
function maybeTranslate(res, charset) {
    const iconv = require('iconv-lite')

    // use iconv if its not utf8 already.
    if (charset && !/utf-*8/i.test(charset)) {
        try {
            res.pipe(
                iconv.decodeStream(charset)
            ).pipe(
                iconv.encodeStream('utf-8')
            )
        } catch (err) {
            res.emit('error', err);
        }
    }

    return res;

}
github stream-utils / raw-body / index.js View on Github external
function getDecoder (encoding) {
  if (!encoding) return null

  try {
    return iconv.getDecoder(encoding)
  } catch (e) {
    // error getting decoder
    if (!ICONV_ENCODING_MESSAGE_REGEXP.test(e.message)) throw e

    // the encoding was not found
    throw createError(415, 'specified encoding unsupported', {
      encoding: encoding,
      type: 'encoding.unsupported'
    })
  }
}
github sprut666666 / com.sprut.homekit / node_modules / raw-body / index.js View on Github external
function getDecoder (encoding) {
  if (!encoding) return null

  try {
    return iconv.getDecoder(encoding)
  } catch (e) {
    // error getting decoder
    if (!ICONV_ENCODING_MESSAGE_REGEXP.test(e.message)) throw e

    // the encoding was not found
    throw createError(415, 'specified encoding unsupported', {
      encoding: encoding,
      type: 'encoding.unsupported'
    })
  }
}
github joshlobaptista / Barista-Fullstack / node_modules / raw-body / index.js View on Github external
function getDecoder (encoding) {
  if (!encoding) return null

  try {
    return iconv.getDecoder(encoding)
  } catch (e) {
    // error getting decoder
    if (!iconvEncodingMessageRegExp.test(e.message)) throw e

    // the encoding was not found
    throw createError(415, 'specified encoding unsupported', 'encoding.unsupported', {
      encoding: encoding
    })
  }
}
github jedmao / eclint / js / rules / charset.spec.js View on Github external
var iconv = require('iconv-lite');
var common = require('../test-common');
var rule = require('./charset');
var linez = require('linez');
var expect = common.expect;
var reporter = common.reporter;
var context = common.context;
iconv.extendNodeEncodings();
// ReSharper disable WrongExpressionStatement
describe('charset rule', function () {
    beforeEach(function () {
        reporter.reset();
    });
    describe('check command', function () {
        it('reports out of range characters for latin1 setting', function () {
            rule.check(context, { charset: 'latin1' }, linez('foo\u0080bar'));
            expect(reporter).to.have.been.calledOnce;
            expect(reporter).to.have.been.calledWithExactly('Character out of latin1 range: \u0080');
        });
        it('remains silent on in-range characters for latin1 setting', function () {
            rule.check(context, { charset: 'latin1' }, linez('foo\u007Fbar'));
            expect(reporter).to.not.have.been.called;
        });
        it('reports invalid charsets', function () {
github jedmao / eclint / js / rules / charset.spec.js View on Github external
var iconv = require('iconv-lite');
var common = require('../test-common');
var rule = require('./charset');
var linez = require('linez');
var expect = common.expect;
var reporter = common.reporter;
var context = common.context;
var createLine = common.createLine;
var Doc = linez.Document;
iconv.extendNodeEncodings();
// ReSharper disable WrongExpressionStatement
describe('charset rule', function () {
    beforeEach(function () {
        reporter.reset();
    });
    describe('check command', function () {
        it('reports out of range characters for latin1 setting', function () {
            rule.check(context, { charset: 'latin1' }, linez('foo\u0080bar'));
            expect(reporter).to.have.been.calledOnce;
            expect(reporter).to.have.been.calledWithExactly('line 1, column: 4: character out of latin1 range: \u0080');
        });
        it('remains silent on in-range characters for latin1 setting', function () {
            rule.check(context, { charset: 'latin1' }, linez('foo\u007Fbar'));
            expect(reporter).to.not.have.been.called;
        });
        it('reports invalid charsets', function () {