• Version 3.0.2
  • Published
  • 6.48 kB
  • No dependencies
  • MIT license


npm i @types/html-encoding-sniffer
yarn add @types/html-encoding-sniffer
pnpm add @types/html-encoding-sniffer


TypeScript definitions for html-encoding-sniffer



function sniffHTMLEncoding

sniffHTMLEncoding: (
htmlBytes: Uint8Array,
options?: sniffHTMLEncoding.Options
) => string;
  • Determine the Encoding of a HTML Byte Stream.

    Implements the HTML Standard's [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm) in all its glory. The most interesting part of this is how it pre-scans the first 1024 bytes in order to search for certain <meta charset>-related patterns.

    Parameter htmlBytes

    The typed array containing the (X)HTML source text.

    The canonical [encoding name](https://encoding.spec.whatwg.org/#names-and-labels) for use with the [whatwg-encoding](https://github.com/jsdom/whatwg-encoding) or similar package.

    Example 1

    import htmlEncodingSniffer = require("html-encoding-sniffer"); import * as fs from "fs";

    const htmlBytes = fs.readFileSync("./html-page.html"); const sniffedEncoding = htmlEncodingSniffer(htmlBytes);


interface Options

interface Options {}

    property defaultEncoding

    defaultEncoding?: string | undefined;
    • The ultimate fallback encoding used if no valid encoding is supplied by the transport layer, and no encoding is sniffed from the bytes.


      Which is recommended by the algorithm's table of suggested defaults for "All other locales" (including the en locale).

    property transportLayerEncodingLabel

    transportLayerEncodingLabel?: string | undefined;
    • An encoding label that is obtained from the "transport layer" (probably an HTTP Content-Type header), which overrides everything but a BOM.

    Package Files (1)

    Dependencies (0)

    No dependencies.

    Dev Dependencies (0)

    No dev dependencies.

    Peer Dependencies (0)

    No peer dependencies.


    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/html-encoding-sniffer.

    • Markdown
    • HTML
      <a href="https://www.jsdocs.io/package/@types/html-encoding-sniffer"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>