chore: Remove Dockerfile and docker-compose.yml, update README and migration guide for backend log checks
Some checks failed
Documentation / build-docs (push) Has been cancelled
Tests / test (macos-latest, 3.11) (push) Has been cancelled
Tests / test (macos-latest, 3.12) (push) Has been cancelled
Tests / test (macos-latest, 3.13) (push) Has been cancelled
Tests / test (macos-latest, 3.14) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.12) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.13) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.14) (push) Has been cancelled

This commit is contained in:
kfox
2026-01-02 22:46:03 -05:00
parent 6834655e03
commit 3c6770acf5
134 changed files with 3025 additions and 18054 deletions

View File

@@ -12,28 +12,30 @@ 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](https://encoding.spec.whatwg.org/#names-and-labels) (not a label). You might then combine this with the [whatwg-encoding](https://github.com/jsdom/whatwg-encoding) package to decode the result:
The returned value will be a canonical [encoding name](https://encoding.spec.whatwg.org/#names-and-labels) (not a label). You might then combine this with the [`@exodus/bytes`](https://github.com/ExodusOSS/bytes/) package to decode the result:
```js
const whatwgEncoding = require("whatwg-encoding");
const htmlString = whatwgEncoding.decode(htmlBytes, sniffedEncoding);
const { TextDecoder } = require("@exodus/bytes");
const htmlString = (new TextDecoder(sniffedEncoding)).decode(htmlBytes);
```
## Options
You can pass two potential options to `htmlEncodingSniffer`:
You can pass the following options to `htmlEncodingSniffer`:
```js
const sniffedEncoding = htmlEncodingSniffer(htmlBytes, {
xml,
transportLayerEncodingLabel,
defaultEncoding
defaultEncoding,
});
```
These represent two possible inputs into the [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#encoding-sniffing-algorithm):
The `xml` option is a boolean, defaulting to `false`. If set to `true`, then we bypass the [HTML encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.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.)
- `transportLayerEncodingLabel` is an encoding label that is obtained from the "transport layer" (probably a HTTP `Content-Type` header), which overrides everything but a BOM.
- `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. It defaults to `"windows-1252"`, as recommended by the algorithm's table of suggested defaults for "All other locales" (including the `en` locale).
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

View File

@@ -5,26 +5,30 @@
"encoding",
"html"
],
"version": "4.0.0",
"version": "6.0.0",
"author": "Domenic Denicola <d@domenic.me> (https://domenic.me/)",
"license": "MIT",
"repository": "jsdom/html-encoding-sniffer",
"repository": {
"type": "git",
"url": "git+https://github.com/jsdom/html-encoding-sniffer.git"
},
"main": "lib/html-encoding-sniffer.js",
"files": [
"lib/"
],
"scripts": {
"test": "node --test",
"lint": "eslint ."
"lint": "eslint"
},
"dependencies": {
"whatwg-encoding": "^3.1.1"
"@exodus/bytes": "^1.6.0"
},
"devDependencies": {
"@domenic/eslint-config": "^3.0.0",
"eslint": "^8.53.0"
"@domenic/eslint-config": "^4.0.1",
"eslint": "^9.39.2",
"globals": "^16.5.0"
},
"engines": {
"node": ">=18"
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
}
}