Add types for chardet (#25308)

This commit is contained in:
Gebatzens
2018-04-27 00:20:59 +02:00
committed by Wesley Wigham
parent 321c042eba
commit 54acb6f5d7
4 changed files with 57 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
import * as chardet from "chardet";
chardet.detect(new Buffer('hello there!'));
chardet.detectFile('/path/to/file', (err, encoding) => {});
chardet.detectFileSync('/path/to/file');
chardet.detectFile('/path/to/file', { sampleSize: 32 }, (err, encoding) => {});

26
types/chardet/index.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
// Type definitions for chardet 0.5
// Project: https://github.com/runk/node-chardet
// Definitions by: Hauke Oldsen <https://github.com/Gebatzens>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
export interface Confidence {
name: string;
confidence: number;
lang?: string;
}
export interface Options {
returnAllMatches?: boolean;
sampleSize?: number;
}
export type Result = Confidence[] | string | null;
export function detect(buf: Buffer, opts?: Options): Result;
export function detectFile(path: string, cb: (err: any, result: Result) => void): void;
export function detectFile(path: string, opts: Options, cb: (err: any, result: Result) => void): void;
export function detectFileSync(path: string, opts?: Options): Result;

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"chardet-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }