Detects when user changes same config setting 3+ times within 24 hours. Shows non-intrusive prompt offering help with guided calibration flow. Guided calibration features: - Test for false positives (walk around room) - Test for missed motion (sit still) - Suggest optimal value based on diurnal baseline SNR and link health - Apply suggested value button Files: - dashboard/js/proactive.js: Complete implementation with localStorage tracking Acceptance: - Help prompt fires after 3+ changes in 24h - Calibration flow tests both directions - Suggests value based on system data - Apply button works |
||
|---|---|---|
| .. | ||
| lib | ||
| LICENSE.txt | ||
| package.json | ||
| 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 whatwg-encoding package to decode the result:
const whatwgEncoding = require("whatwg-encoding");
const htmlString = whatwgEncoding.decode(htmlBytes, sniffedEncoding);
Options
You can pass two potential options to htmlEncodingSniffer:
const sniffedEncoding = htmlEncodingSniffer(htmlBytes, {
transportLayerEncodingLabel,
defaultEncoding
});
These represent two possible inputs into the encoding sniffing algorithm:
transportLayerEncodingLabelis an encoding label that is obtained from the "transport layer" (probably a HTTPContent-Typeheader), which overrides everything but a BOM.defaultEncodingis 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 theenlocale).
Credits
This package was originally based on the excellent work of @nicolashenry, in jsdom. It has since been pulled out into this separate package.