zhouyang.xie 89146efd70 2.19.0 Vue 总览页签迁移 + 呈现对拍门: Overview.vue(逐块搬 KPI/需关注/状态条) + lib/render.ts 口径同源 + i18n/zh.ts(105 键取自现网语言包) + tools/render_parity.mjs(jsdom 跑旧页面 beforeParse 装 fetch 桩 vs Vue SSR, 11 组锚点全一致) + npm run parity/build:ssr; 设计说明 §3.6 迁移进度; 文档/版本表同步 před 1 týdnem
..
lib 89146efd70 2.19.0 Vue 总览页签迁移 + 呈现对拍门: Overview.vue(逐块搬 KPI/需关注/状态条) + lib/render.ts 口径同源 + i18n/zh.ts(105 键取自现网语言包) + tools/render_parity.mjs(jsdom 跑旧页面 beforeParse 装 fetch 桩 vs Vue SSR, 11 组锚点全一致) + npm run parity/build:ssr; 设计说明 §3.6 迁移进度; 文档/版本表同步 před 1 týdnem
LICENSE.txt 89146efd70 2.19.0 Vue 总览页签迁移 + 呈现对拍门: Overview.vue(逐块搬 KPI/需关注/状态条) + lib/render.ts 口径同源 + i18n/zh.ts(105 键取自现网语言包) + tools/render_parity.mjs(jsdom 跑旧页面 beforeParse 装 fetch 桩 vs Vue SSR, 11 组锚点全一致) + npm run parity/build:ssr; 设计说明 §3.6 迁移进度; 文档/版本表同步 před 1 týdnem
README.md 89146efd70 2.19.0 Vue 总览页签迁移 + 呈现对拍门: Overview.vue(逐块搬 KPI/需关注/状态条) + lib/render.ts 口径同源 + i18n/zh.ts(105 键取自现网语言包) + tools/render_parity.mjs(jsdom 跑旧页面 beforeParse 装 fetch 桩 vs Vue SSR, 11 组锚点全一致) + npm run parity/build:ssr; 设计说明 §3.6 迁移进度; 文档/版本表同步 před 1 týdnem
package.json 89146efd70 2.19.0 Vue 总览页签迁移 + 呈现对拍门: Overview.vue(逐块搬 KPI/需关注/状态条) + lib/render.ts 口径同源 + i18n/zh.ts(105 键取自现网语言包) + tools/render_parity.mjs(jsdom 跑旧页面 beforeParse 装 fetch 桩 vs Vue SSR, 11 组锚点全一致) + npm run parity/build:ssr; 设计说明 §3.6 迁移进度; 文档/版本表同步 před 1 týdnem

README.md

Determine the Encoding of a HTML Byte Stream

This package implements the HTML Standard's 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.

const htmlEncodingSniffer = require("html-encoding-sniffer");
const fs = require("fs");

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

The passed bytes are given as a Uint8Array; the Node.js Buffer subclass of Uint8Array will also work, as shown above.

The returned value will be a canonical encoding name (not a label). You might then combine this with the @exodus/bytes package to decode the result:

const { TextDecoder } = require("@exodus/bytes");
const htmlString = (new TextDecoder(sniffedEncoding)).decode(htmlBytes);

Options

You can pass the following options to htmlEncodingSniffer:

const sniffedEncoding = htmlEncodingSniffer(htmlBytes, {
  xml,
  transportLayerEncodingLabel,
  defaultEncoding,
});

The xml option is a boolean, defaulting to false. If set to true, then we bypass the HTML encoding sniffing algorithm and compute the encoding based on the presence of a BOM, or the other options provided. (In the future, we may perform sniffing of the <?xml?> declaration, but for now that is not implemented.)

The transportLayerEncodingLabel is an encoding label that is obtained from the "transport layer" (probably a HTTP Content-Type header), which overrides everything but a BOM.

The defaultEncoding is the ultimate fallback encoding used if no valid encoding is supplied by the transport layer, and no encoding is sniffed from the bytes. For HTML, it defaults to "windows-1252", as recommended by the algorithm's table of suggested defaults for "All other locales" (including the en locale). For XML, it defaults to "UTF-8".

Credits

This package was originally based on the excellent work of @nicolashenry, in jsdom. It has since been pulled out into this separate package.