Gathering detailed insights and metrics for html-encoding-sniffer
Gathering detailed insights and metrics for html-encoding-sniffer
Gathering detailed insights and metrics for html-encoding-sniffer
Gathering detailed insights and metrics for html-encoding-sniffer
npm install html-encoding-sniffer
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
19 Stars
25 Commits
11 Forks
5 Watching
2 Branches
7 Contributors
Updated on 23 May 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-8.3%
4,959,657
Compared to previous day
Last week
2.6%
29,615,921
Compared to previous week
Last month
22.7%
115,812,843
Compared to previous month
Last year
11.3%
1,089,188,827
Compared to previous year
1
2
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.
1const htmlEncodingSniffer = require("html-encoding-sniffer"); 2const fs = require("fs"); 3 4const htmlBytes = fs.readFileSync("./html-page.html"); 5const 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:
1const whatwgEncoding = require("whatwg-encoding"); 2const htmlString = whatwgEncoding.decode(htmlBytes, sniffedEncoding);
You can pass two potential options to htmlEncodingSniffer
:
1const sniffedEncoding = htmlEncodingSniffer(htmlBytes, {
2 transportLayerEncodingLabel,
3 defaultEncoding
4});
These represent two possible inputs into the encoding sniffing algorithm:
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).This package was originally based on the excellent work of @nicolashenry, in jsdom. It has since been pulled out into this separate package.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 2/17 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More