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

fastestsmallesttextencoderdecoder-browser

v1.0.8

Published

The fastest smallest Javascript polyfill for the encode of TextEncoder and decode of TextDecoder for UTF-8 only. Made by AnonyCo with ❤️ from 🐕s.

Downloads

18

Readme

npm version GitHub stars GitHub file size in bytes GitHub file size in bytes npm bundle size (version) Issues Unlicense license npm downloads

This Javascript library provides the most performant tiny polyfill for window.TextEncoder and window.TextDecoder for use in the browser, in NodeJS, in RequireJS, in web Workers, in SharedWorkers, and in ServiceWorkers.

Quick Start

Add the following HTML Code to your head:

<script src="https://dl.dropboxusercontent.com/s/r55397ld512etib/EncoderDecoderTogether.min.js?dl=0" type="text/javascript"></script>

If you know that no script on the page requires this library until the DOMContentLoaded event, then you can switch to the much less blocking version below:

<script defer="" src="https://dl.dropboxusercontent.com/s/r55397ld512etib/EncoderDecoderTogether.min.js?dl=0" type="text/javascript"></script>

Alternatively, either use https://dl.dropboxusercontent.com/s/47481btie8pb95h/FastestTextEncoderPolyfill.min.js?dl=0 to polyfill window.TextEncoder for converting a String into a Uint8Array or use https://dl.dropboxusercontent.com/s/qmoknmp86sytc74/FastestTextDecoderPolyfill.min.js?dl=0 to only polyfill window.TextDecoder for converting a Uint8Array/ArrayBuffer/[typedarray]/global.Buffer into a String.

RequireJS and NodeJS

For dropping into either RequireJS or NodeJS, please use the fastestsmallesttextencoderdecoder npm repository, this minified file, or the corresponding source code file. To install via npm, use the following code,

npm install fastestsmallesttextencoderdecoder

Browser Support

This polyfill will bring support for TextEncoder/TextDecoder to the following browsers.

| Feature | Chrome | Firefox | Opera | Edge | Internet Explorer | Safari | Android | Samsung Internet | Node.js | | ------------------ | --- | --- | -------------------------------- | ------ | --- | ------------------------- | --- | --- | --- | | Full Polyfill | 7.0 | 4.0 | 11.6 | 12.0** | 10 | 5.1 (Desktop) / 4.2 (iOS) | 4.0 | 1.0 | 3.0 | | Partial Polyfill* | 1.0** | 0.6 | 7.0 (Desktop) / 9.5** (Mobile) | 12.0** | 4.0 | 2.0 | 1.0** | 1.0** | 0.10 |

Also note that while this polyfill may work in these old browsers, it is very likely that the rest of your website will not (unless if you make a concious effort about it which I would not reccomend because noone uses or should use these old browsers).

* Partial polyfill means that Array (or Buffer in NodeJS) will be used instead of Uint8Array/[typedarray].

** This is the first public release of the browser

API Documentation

Please review the MDN at window.TextEncoder and window.TextDecoder for information on how to use TextEncoder and TextDecoder.

As for NodeJS, calling require("EncoderAndDecoderNodeJS.min.js") yields the following object:

module.exports = {
	TextEncoder: function TextEncoder(){/*...*/},
	TextDecoder: function TextEncoder(){/*...*/},
	encode: TextEncoder.prototype.encode,
	decode: TextDecoder.prototype.decode
}

Thus, in NodeJS, you do not ever have to use new just to get the encoder/decoder (although you still can do so if you want to). All of the code snippets below function identically (aside from unused local variables introduced into the scope). There are an innumerable number of ways to rewrite this same snippet of code, thus I only chose the three which I thought would be most useful.

    // Variation 1
    const {TextEncoder, TextDecoder} = require("fastestsmallesttextencoderdecoder");
    const encode = (new TextEncoder).encode;
    const decode = (new TextDecoder).decode;
    // Variation 2
    const {encode, decode} = require("fastestsmallesttextencoderdecoder");
    // Variation 3 (a rewording of Variation 2)
    const encodeAndDecodeModule = require("fastestsmallesttextencoderdecoder");
    const encode = encodeAndDecodeModule.encode;
    const decode = encodeAndDecodeModule.decode;

Or, you can use the new and shiny ES6 module importation statements.

    // Variation 1
    import {TextEncoder, TextDecoder} from "fastestsmallesttextencoderdecoder";
    const encode = (new TextEncoder).encode;
    const decode = (new TextDecoder).decode;
    // Variation 2
    import {encode, decode} from "fastestsmallesttextencoderdecoder";
    // Variation 3 (a rewording of Variation 2)
    import * as encodeAndDecodeModule from "fastestsmallesttextencoderdecoder";
    const encode = encodeAndDecodeModule.encode;
    const decode = encodeAndDecodeModule.decode;

Note that fastestsmallesttextencoderdecoder must be installed via the following snippet in the terminal in order for the require("fastestsmallesttextencoderdecoder") to work.

npm install fastestsmallesttextencoderdecoder

Demonstration

Visit the GithubPage to see a demonstation. As seen in the Web Worker hexWorker.js, the Github Pages demonstration uses a special encoderAndDecoderForced.src.js version of this library to forcefully install the TextEncoder and TextDecoder even when there is native support. That way, this demonstraton should serve to truthfully demonstrate this polyfill.

npm Project

You can find this project on npm here at this link.

Development

On linux, you can develop the project on your own by cloning it with the following command line.

git clone https://github.com/anonyco/FastestSmallestTextEncoderDecoder.git; cd FastestSmallestTextEncoderDecoder; npm run install-dev

Emphasize the npm run install-dev which downloads closure-compiler.jar into the repository for minifying the files.

Now that the repository is cloned, edit the files as you see fit. Now that the files have been edited, run the following in the terminal in the root folder of the repository in order to minify the NodeJS JavaScript files.

npm run build