Decode strings according to the WHATWG Encoding Standard
Installations
npm install whatwg-encoding
Developer
jsdom
Developer Guide
Module System
CommonJS
Min. Node Version
>=18
Typescript Support
No
Node Version
21.1.0
NPM Version
10.2.0
Statistics
23 Stars
30 Commits
10 Forks
5 Watching
2 Branches
9 Contributors
Updated on 21 Jul 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
4,145,199,164
Last day
-8.2%
5,199,183
Compared to previous day
Last week
2.7%
31,046,561
Compared to previous week
Last month
22.1%
121,705,802
Compared to previous month
Last year
16.4%
1,086,779,011
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
2
Decode According to the WHATWG Encoding Standard
This package provides a thin layer on top of iconv-lite which makes it expose some of the same primitives as the Encoding Standard.
1const whatwgEncoding = require("whatwg-encoding"); 2 3console.assert(whatwgEncoding.labelToName("latin1") === "windows-1252"); 4console.assert(whatwgEncoding.labelToName(" CYRILLic ") === "ISO-8859-5"); 5 6console.assert(whatwgEncoding.isSupported("IBM866") === true); 7 8// Not supported by the Encoding Standard 9console.assert(whatwgEncoding.isSupported("UTF-32") === false); 10 11// In the Encoding Standard, but this package can't decode it 12console.assert(whatwgEncoding.isSupported("x-mac-cyrillic") === false); 13 14console.assert(whatwgEncoding.getBOMEncoding(new Uint8Array([0xFE, 0xFF])) === "UTF-16BE"); 15console.assert(whatwgEncoding.getBOMEncoding(new Uint8Array([0x48, 0x69])) === null); 16 17console.assert(whatwgEncoding.decode(new Uint8Array([0x48, 0x69]), "UTF-8") === "Hi");
API
decode(uint8Array, fallbackEncodingName)
: performs the decode algorithm (in which any BOM will override the passed fallback encoding), and returns the resulting stringlabelToName(label)
: performs the get an encoding algorithm and returns the resulting encoding's name, ornull
for failureisSupported(name)
: returns whether the encoding is one of the encodings of the Encoding Standard, and is an encoding that this package can decode (via iconv-lite)getBOMEncoding(uint8Array)
: sniffs the first 2–3 bytes of the suppliedUint8Array
, returning one of the encoding names"UTF-8"
,"UTF-16LE"
, or"UTF-16BE"
if the appropriate BOM is present, ornull
if no BOM is present
Unsupported encodings
Since we rely on iconv-lite, we are limited to support only the encodings that they support. Currently we are missing support for:
- ISO-2022-JP
- ISO-8859-8-I
- replacement
- x-mac-cyrillic
- x-user-defined
Passing these encoding names will return false
when calling isSupported
, and passing any of the possible labels for these encodings to labelToName
will return null
.
Credits
This package was originally based on the excellent work of @nicolashenry, in jsdom. It has since been pulled out into this separate package.
Alternatives
If you are looking for a JavaScript implementation of the Encoding Standard's TextEncoder
and TextDecoder
APIs, you'll want @inexorabletash's text-encoding package. Node.js also has them built-in.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.txt:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/jsdom/.github/SECURITY.md:1
- Info: Found linked content: github.com/jsdom/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/jsdom/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/jsdom/.github/SECURITY.md:1
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/jsdom/whatwg-encoding/build.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/jsdom/whatwg-encoding/build.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 4/26 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
- Warn: no topLevel permission defined: .github/workflows/build.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Score
4.2
/10
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 MoreOther packages similar to whatwg-encoding
@types/whatwg-encoding
TypeScript definitions for whatwg-encoding
utf8-encoding
utf8 encoder/decoder of whatwg Encoding Living Standard https://encoding.spec.whatwg.org/
whatwg-encoding-mapper
Encoding mapper according to the WHATWG Encoding Standard
@i-xi-dev/ms932-encoder
A JavaScript Windows-31J encoder, implements Shift_JIS encoder defined in WHATWG Encoding Standard.