npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

whatwg-encoding

v3.1.1

Published

Decode strings according to the WHATWG Encoding Standard

Downloads

107,472,116

Readme

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.

const whatwgEncoding = require("whatwg-encoding");

console.assert(whatwgEncoding.labelToName("latin1") === "windows-1252");
console.assert(whatwgEncoding.labelToName("  CYRILLic ") === "ISO-8859-5");

console.assert(whatwgEncoding.isSupported("IBM866") === true);

// Not supported by the Encoding Standard
console.assert(whatwgEncoding.isSupported("UTF-32") === false);

// In the Encoding Standard, but this package can't decode it
console.assert(whatwgEncoding.isSupported("x-mac-cyrillic") === false);

console.assert(whatwgEncoding.getBOMEncoding(new Uint8Array([0xFE, 0xFF])) === "UTF-16BE");
console.assert(whatwgEncoding.getBOMEncoding(new Uint8Array([0x48, 0x69])) === null);

console.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 string
  • labelToName(label): performs the get an encoding algorithm and returns the resulting encoding's name, or null for failure
  • isSupported(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 supplied Uint8Array, returning one of the encoding names "UTF-8", "UTF-16LE", or "UTF-16BE" if the appropriate BOM is present, or null 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.