Socket
Socket
Sign inDemoInstall

chardet

Package Overview
Dependencies
0
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.2 to 1.3.0

lib/fs/browser.d.ts

3

lib/encoding/iso2022.d.ts
import { Context, Recogniser } from '.';
import { Match } from '../match';
declare class ISO_2022 implements Recogniser {
escapeSequences: number[][];
name(): string;
match(det: Context): any;
match(det: Context): Match | null;
}

@@ -7,0 +8,0 @@ export declare class ISO_2022_JP extends ISO_2022 {

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var match = require('../match').default;
exports.ISO_2022_CN = exports.ISO_2022_KR = exports.ISO_2022_JP = void 0;
const match_1 = __importDefault(require("../match"));
class ISO_2022 {

@@ -12,14 +16,14 @@ constructor() {

match(det) {
var i, j;
var escN;
var hits = 0;
var misses = 0;
var shifts = 0;
var quality;
var text = det.fInputBytes;
var textLen = det.fInputLen;
let i, j;
let escN;
let hits = 0;
let misses = 0;
let shifts = 0;
let quality;
const text = det.fInputBytes;
const textLen = det.fInputLen;
scanInput: for (i = 0; i < textLen; i++) {
if (text[i] == 0x1b) {
checkEscapes: for (escN = 0; escN < this.escapeSequences.length; escN++) {
var seq = this.escapeSequences[escN];
const seq = this.escapeSequences[escN];
if (textLen - i < seq.length)

@@ -44,3 +48,3 @@ continue checkEscapes;

quality -= (5 - (hits + shifts)) * 10;
return quality <= 0 ? null : match(det, this, quality);
return quality <= 0 ? null : match_1.default(det, this, quality);
}

@@ -47,0 +51,0 @@ }

import { Context, Recogniser } from '.';
import { Match } from '../match';
declare class IteratedChar {

@@ -15,3 +16,3 @@ charValue: number;

name(): string;
match(det: Context): any;
match(det: Context): Match | null;
nextChar(iter: IteratedChar, det: Context): boolean;

@@ -18,0 +19,0 @@ }

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var match = require('../match').default;
exports.gb_18030 = exports.euc_kr = exports.euc_jp = exports.big5 = exports.sjis = void 0;
const match_1 = __importDefault(require("../match"));
function binarySearch(arr, searchValue) {

@@ -8,3 +12,3 @@ const find = (arr, searchValue, left, right) => {

return -1;
var mid = Math.floor((left + right) >>> 1);
const mid = Math.floor((left + right) >>> 1);
if (searchValue > arr[mid])

@@ -38,3 +42,3 @@ return find(arr, searchValue, mid + 1, right);

}
var byteValue = det.fRawInput[this.nextIndex++] & 0x00ff;
const byteValue = det.fRawInput[this.nextIndex++] & 0x00ff;
return byteValue;

@@ -51,4 +55,4 @@ }

match(det) {
var singleByteCharCount = 0, doubleByteCharCount = 0, commonCharCount = 0, badCharCount = 0, totalCharCount = 0, confidence = 0;
var iter = new IteratedChar();
let singleByteCharCount = 0, doubleByteCharCount = 0, commonCharCount = 0, badCharCount = 0, totalCharCount = 0, confidence = 0;
const iter = new IteratedChar();
detectBlock: {

@@ -61,3 +65,3 @@ for (iter.reset(); this.nextChar(iter, det);) {

else {
var cv = iter.charValue & 0xffffffff;
const cv = iter.charValue & 0xffffffff;
if (cv <= 0xff) {

@@ -99,4 +103,4 @@ singleByteCharCount++;

else {
var maxVal = Math.log(parseFloat(doubleByteCharCount) / 4);
var scaleFactor = 90.0 / maxVal;
const maxVal = Math.log(doubleByteCharCount / 4);
const scaleFactor = 90.0 / maxVal;
confidence = Math.floor(Math.log(commonCharCount + 1) * scaleFactor + 10);

@@ -106,3 +110,3 @@ confidence = Math.min(confidence, 100);

}
return confidence == 0 ? null : match(det, this, confidence);
return confidence == 0 ? null : match_1.default(det, this, confidence);
}

@@ -185,4 +189,3 @@ nextChar(iter, det) {

iter.error = false;
var firstByte;
firstByte = iter.charValue = iter.nextByte(det);
const firstByte = (iter.charValue = iter.nextByte(det));
if (firstByte < 0)

@@ -192,3 +195,3 @@ return false;

return true;
var secondByte = iter.nextByte(det);
const secondByte = iter.nextByte(det);
if (secondByte < 0)

@@ -316,3 +319,3 @@ return false;

iter.error = false;
var firstByte = (iter.charValue = iter.nextByte(det));
const firstByte = (iter.charValue = iter.nextByte(det));
if (firstByte < 0)

@@ -322,3 +325,3 @@ return false;

return true;
var secondByte = iter.nextByte(det);
const secondByte = iter.nextByte(det);
if (secondByte < 0)

@@ -336,5 +339,5 @@ return false;

iter.error = false;
var firstByte = 0;
var secondByte = 0;
var thirdByte = 0;
let firstByte = 0;
let secondByte = 0;
let thirdByte = 0;
buildChar: {

@@ -718,6 +721,6 @@ firstByte = iter.charValue = iter.nextByte(det);

iter.error = false;
var firstByte = 0;
var secondByte = 0;
var thirdByte = 0;
var fourthByte = 0;
let firstByte = 0;
let secondByte = 0;
let thirdByte = 0;
let fourthByte = 0;
buildChar: {

@@ -724,0 +727,0 @@ firstByte = iter.charValue = iter.nextByte(det);

import { Context, Recogniser } from '../encoding/index';
import { Match } from '../match';
declare class NGramsPlusLang {

@@ -12,3 +13,3 @@ fLang: string;

name(input: Context): string;
match(det: Context): any;
match(det: Context): Match | null;
}

@@ -15,0 +16,0 @@ export declare class ISO_8859_1 extends sbcs {

import { Context, Recogniser } from '.';
import { Match } from '../match';
export declare class UTF_16BE implements Recogniser {
name(): string;
match(det: Context): any;
match(det: Context): Match | null;
}
export declare class UTF_16LE implements Recogniser {
name(): string;
match(det: Context): any;
match(det: Context): Match | null;
}

@@ -16,3 +17,3 @@ interface WithGetChar {

getChar(input: Uint8Array, index: number): number;
match(det: Context): any;
match(det: Context): Match | null;
}

@@ -19,0 +20,0 @@ export declare class UTF_32BE extends UTF_32 {

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const match = require('../match').default;
exports.UTF_32LE = exports.UTF_32BE = exports.UTF_16LE = exports.UTF_16BE = void 0;
const match_1 = __importDefault(require("../match"));
class UTF_16BE {

@@ -9,7 +13,7 @@ name() {

match(det) {
var input = det.fRawInput;
const input = det.fRawInput;
if (input.length >= 2 &&
(input[0] & 0xff) == 0xfe &&
(input[1] & 0xff) == 0xff) {
return match(det, this, 100);
return match_1.default(det, this, 100);
}

@@ -25,3 +29,3 @@ return null;

match(det) {
var input = det.fRawInput;
const input = det.fRawInput;
if (input.length >= 2 &&

@@ -33,3 +37,3 @@ (input[0] & 0xff) == 0xff &&

}
return match(det, this, 100);
return match_1.default(det, this, 100);
}

@@ -48,3 +52,5 @@ return null;

match(det) {
var input = det.fRawInput, limit = (det.fRawLength / 4) * 4, numValid = 0, numInvalid = 0, hasBOM = false, confidence = 0;
let numValid = 0, numInvalid = 0, hasBOM = false, confidence = 0;
const limit = (det.fRawLength / 4) * 4;
const input = det.fRawInput;
if (limit == 0) {

@@ -56,4 +62,4 @@ return null;

}
for (var i = 0; i < limit; i += 4) {
var ch = this.getChar(input, i);
for (let i = 0; i < limit; i += 4) {
const ch = this.getChar(input, i);
if (ch < 0 || ch >= 0x10ffff || (ch >= 0xd800 && ch <= 0xdfff)) {

@@ -81,3 +87,3 @@ numInvalid += 1;

}
return confidence == 0 ? null : match(det, this, confidence);
return confidence == 0 ? null : match_1.default(det, this, confidence);
}

@@ -84,0 +90,0 @@ }

import { Context, Recogniser } from '.';
import { Match } from '../match';
export default class Utf8 implements Recogniser {
name(): string;
match(det: Context): any;
match(det: Context): Match | null;
}
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var match = require('../match').default;
const match_1 = __importDefault(require("../match"));
class Utf8 {

@@ -9,3 +12,4 @@ name() {

match(det) {
var hasBOM = false, numValid = 0, numInvalid = 0, input = det.fRawInput, trailBytes = 0, confidence;
let hasBOM = false, numValid = 0, numInvalid = 0, trailBytes = 0, confidence;
const input = det.fRawInput;
if (det.fRawLength >= 3 &&

@@ -17,4 +21,4 @@ (input[0] & 0xff) == 0xef &&

}
for (var i = 0; i < det.fRawLength; i++) {
var b = input[i];
for (let i = 0; i < det.fRawLength; i++) {
const b = input[i];
if ((b & 0x80) == 0)

@@ -66,3 +70,3 @@ continue;

return null;
return match(det, this, confidence);
return match_1.default(det, this, confidence);
}

@@ -69,0 +73,0 @@ }

@@ -5,7 +5,8 @@ import { Match } from './match';

}
declare type Options = Partial<FullOptions>;
declare type DetectResult = Match[] | string | null;
export declare const detect: (buffer: Uint8Array) => string | null;
export declare const analyse: (buffer: Uint8Array) => Match[];
export declare const detectFile: (filepath: string, opts?: Partial<FullOptions>) => Promise<DetectResult>;
export declare const detectFileSync: (filepath: string, opts?: Partial<FullOptions>) => DetectResult;
export declare const detectFile: (filepath: string, opts?: Options) => Promise<DetectResult>;
export declare const detectFileSync: (filepath: string, opts?: Options) => DetectResult;
declare const _default: {

@@ -12,0 +13,0 @@ analyse: (buffer: Uint8Array) => Match[];

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.detectFileSync = exports.detectFile = exports.analyse = exports.detect = void 0;
const node_1 = __importDefault(require("./fs/node"));
const utf8_1 = __importDefault(require("./encoding/utf8"));

@@ -18,10 +32,2 @@ const unicode = __importStar(require("./encoding/unicode"));

const iso2022 = __importStar(require("./encoding/iso2022"));
let fsModule;
const loadFs = () => {
if (typeof module === 'object' && typeof module.exports === 'object') {
fsModule = fsModule ? fsModule : require('fs');
return fsModule;
}
throw new Error('File system is not available');
};
const recognisers = [

@@ -91,3 +97,3 @@ new utf8_1.default(),

let fd;
const fs = loadFs();
const fs = node_1.default();
const handler = (err, buffer) => {

@@ -115,3 +121,3 @@ if (fd) {

exports.detectFileSync = (filepath, opts = {}) => {
const fs = loadFs();
const fs = node_1.default();
if (opts && opts.sampleSize) {

@@ -118,0 +124,0 @@ const fd = fs.openSync(filepath, 'r');

@@ -0,7 +1,8 @@

import { Context, Recogniser } from "./encoding";
export interface Match {
confidence: number;
name: string;
lang: string;
lang?: string;
}
declare const _default: (det: any, rec: any, confidence: any, name: any, lang: any) => Match;
declare const _default: (det: Context, rec: Recogniser, confidence: number, name?: string | undefined, lang?: string | undefined) => Match;
export default _default;
{
"name": "chardet",
"version": "1.2.2",
"version": "1.3.0",
"homepage": "https://github.com/runk/node-chardet",
"description": "Character detector",
"description": "Character encoding detector",
"license": "MIT",

@@ -17,3 +17,3 @@ "repository": {

"build": "rm -rf lib/* && tsc",
"lint": "tslint -p tsconfig.json -c tslint.json",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"lint:types": "tsc --noEmit",

@@ -26,6 +26,6 @@ "format": "prettier --write ./src/**/*.ts",

},
"main": "lib/index.js",
"files": [
"lib"
],
"main": "lib/index.js",
"typings": "lib/index.d.ts",

@@ -40,10 +40,12 @@ "engine": {

"devDependencies": {
"@types/jest": "^25.1.4",
"@types/node": "^13.9.5",
"jest": "^25.2.4",
"prettier": "^2.0.2",
"semantic-release": "^15.14.0",
"ts-jest": "^25.2.1",
"tslint": "^6.1.0",
"typescript": "^3.8.3"
"@types/jest": "^26.0.14",
"@types/node": "^14.11.2",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
"eslint": "^7.9.0",
"jest": "^26.4.2",
"prettier": "^2.1.2",
"semantic-release": "^17.1.2",
"ts-jest": "^26.4.0",
"typescript": "^4.0.3"
},

@@ -56,3 +58,34 @@ "keywords": [

"chardet",
"icu"
"icu",
"character detection",
"character encoding",
"language",
"iconv",
"iconv-light",
"UTF-8",
"UTF-16",
"UTF-32",
"ISO-2022-JP",
"ISO-2022-KR",
"ISO-2022-CN",
"Shift_JIS",
"Big5",
"EUC-JP",
"EUC-KR",
"GB18030",
"ISO-8859-1",
"ISO-8859-2",
"ISO-8859-5",
"ISO-8859-6",
"ISO-8859-7",
"ISO-8859-8",
"ISO-8859-9",
"windows-1250",
"windows-1251",
"windows-1252",
"windows-1253",
"windows-1254",
"windows-1255",
"windows-1256",
"KOI8-R"
],

@@ -66,3 +99,6 @@ "author": "Dmitry Shirokov <deadrunk@gmail.com>",

"@zevanty"
]
],
"browser": {
"./lib/fs/node.js": "./lib/fs/browser.js"
}
}
# chardet [![Build Status](https://travis-ci.org/runk/node-chardet.png)](https://travis-ci.org/runk/node-chardet)
Chardet is a character detection module for NodeJS written in pure Javascript.
Module is based on ICU project http://site.icu-project.org/, which uses character
occurency analysis to determine the most probable encoding.
*Chardet* is a character detection module written in pure Javascript (Typescript). Module uses occurrence analysis to determine the most probable encoding.
- Packed size is only **22 KB**
- Works in all environments: Node / Browser / Native
- Works on all platforms: Linux / Mac / Windows
- No dependencies
- No native code / bindings
- 100% written in Typescript
- Extensive code coverage
## Installation

@@ -90,1 +96,5 @@

Yes. Type definitions are included.
### References
- ICU project http://site.icu-project.org/

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc