UNPKG

1.44 kBTypeScriptView Raw
1// Type definitions for html-encoding-sniffer 2.0
2// Project: https://github.com/jsdom/html-encoding-sniffer#readme
3// Definitions by: ExE Boss <https://github.com/ExE-Boss>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6/// <reference types="node"/>
7
8/**
9 * @param buffer The NodeJS buffer containing the (X)HTML source text.
10 *
11 * @return The canonical [encoding name](https://encoding.spec.whatwg.org/#names-and-labels)
12 * for use with the `whatwg-encoding` or similar package.
13 */
14declare function sniffHTMLEncoding(buffer: Buffer, options?: sniffHTMLEncoding.Options): string;
15
16declare namespace sniffHTMLEncoding {
17 interface Options {
18 /**
19 * An encoding label that is obtained from the "transport layer"
20 * (probably an HTTP `Content-Type` header), which overrides
21 * everything but a BOM.
22 */
23 transportLayerEncodingLabel?: string | undefined;
24
25 /**
26 * The ultimate fallback encoding used if no valid encoding is supplied
27 * by the transport layer, and no encoding is sniffed from the bytes.
28 *
29 * @default
30 * ```js
31 * 'windows-1252'
32 * ```
33 *
34 * Which is recommended by the algorithm's table of suggested
35 * defaults for "All other locales" (including the `en` locale).
36 */
37 defaultEncoding?: string | undefined;
38 }
39}
40
41export = sniffHTMLEncoding;