@types/charset-detector
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Installation

npm install --save @types/charset-detector

Summary

This package contains type definitions for charset-detector (https://github.com/btd/node-charset-detector).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/charset-detector.

index.d.ts

declare namespace detect {
    /**
     * charset detect match result
     */
    interface CharsetMatch {
        /**
         * confidence between 0 and 100
         */
        confidence: number;
        /**
         * name of charset
         * @example 'UTF-8'
         */
        charsetName: string;
        /**
         * language of charset
         * @example 'zh'
         */
        lang?: string | undefined;
    }

    /**
     * input statics
     */
    interface InputStats {
        /**
         * whether input contains bytes larger that 0x7F (127)
         */
        readonly c1Bytes: boolean;
        /**
         * count of bytes, eg. `byteStats[32] === 17` means there are 17 bytes with value of `32` in the input
         */
        readonly byteStats: readonly number[];
    }
    type CharsetMatcher = (input: ArrayLike<number>, stats: InputStats) => CharsetMatch | null;
    const DEFAULT_CS_RECOGNIZERS: readonly CharsetMatcher[];
    const ALL_CS_RECOGNIZERS: readonly CharsetMatcher[];
}

/**
 * ICU based port of charset detection to javascript
 * @param input accept node Buffer, but will work with anything that follow such rules:
 *              - allow indexing by []
 *              - has .length
 *              - each numbered property is byte 0-255
 * @param matchers charset detectors, default value is `detect.DEFAULT_CS_RECOGNIZERS`
 * @returns array of matches sorted by most confident first
 */
declare function detect(
    input: ArrayLike<number>,
    matchers?: readonly detect.CharsetMatcher[],
): detect.CharsetMatch[];

export = detect;

Additional Details

  • Last updated: Mon, 20 Nov 2023 23:36:23 GMT
  • Dependencies: none

Credits

These definitions were written by OpportunityLiu.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/charset-detector

Weekly Downloads

203

Version

0.0.4

License

MIT

Unpacked Size

5.79 kB

Total Files

5

Last publish

Collaborators

  • types