How to use the jschardet.UniversalDetector function in jschardet

To help you get started, we’ve selected a few jschardet 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 ezpaarse-project / ezpaarse / lib / pkbvalidator.js View on Github external
exports.validate = function (file, callback) {
  var titleIDs      = {}; // List of title IDs
  var titleIdColumn = false;
  var syntaxError   = false;
  var currentLine   = 1;
  var nbErrors      = 0;
  var nbWarnings    = 0;

  var fileStream    = fs.createReadStream(file);
  var emitter       = new EventEmitter();
  var detector      = new jschardet.UniversalDetector();
  var data;
  detector.reset();

  // Store errors if a callback is provided
  if (typeof callback === 'function') {
    var pkbErrors    = [];
    var pkbWarnings  = [];

    emitter
    .on('error', function (error)       { callback(error); })
    .on('syntaxError', function (error) { callback(error); })
    .on('pkbError', function (msg, line)     { pkbErrors.push({ message: msg, line: line }); })
    .on('pkbWarning', function (msg, line)   { pkbWarnings.push({ message: msg, line: line }); })
    .on('end', function () { callback(null, pkbErrors, pkbWarnings); });
  }

jschardet

Character encoding auto-detection in JavaScript (port of python's chardet)

LGPL-2.1
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis