How to use the jschardet/package.json.version 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 CapacitorSet / box-js / analyze.js View on Github external
if (fs.existsSync(git_path) && fs.lstatSync(git_path).isDirectory()) {
	lib.verbose("Commit: " + fs.readFileSync(path.join(__dirname, ".git/refs/heads/master"), "utf8").replace(/\n/, ""));
} else {
	lib.verbose("No git folder found.");
}
lib.verbose(`Analyzing ${filename}`, false);
const sampleBuffer = fs.readFileSync(filename);
let encoding;
if (argv.encoding) {
	lib.debug("Using argv encoding");
	encoding = argv.encoding;
} else {
	lib.debug("Using detected encoding");
	encoding = require("jschardet").detect(sampleBuffer).encoding;
	if (encoding === null) {
		lib.warning("jschardet (v" + require("jschardet/package.json").version + ") couldn't detect encoding, using UTF-8");
		encoding = "utf8";
	} else {
		lib.debug("jschardet (v" + require("jschardet/package.json").version + ") detected encoding " + encoding);
	}
}

let code = iconv.decode(sampleBuffer, encoding);

if (code.match(".
	lib.debug("Sample seems to be WSF");
	code = code.replace(/<\??\/?\w+( [\w=\"\']*)*\??>/g, ""); // XML tags
	code = code.replace(//g, "");
}

function lacksBinary(name) {

jschardet

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

LGPL-2.1
Latest version published 2 months ago

Package Health Score

80 / 100
Full package analysis