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

bestbase64utf8

v1.0.3

Published

The most standard, most cross-browser, most compact, and fastest possible btoa and atob solution for unicode strings with high code points. Made by AnonyCo with ❤️ from 🐕s.

Downloads

24

Readme

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

Quick Start

Add the following HTML Code to your head:

<script src="https://www.dropbox.com/s/uo9kbpolhnat1cg/atobAndBtoaTogether.min.js?raw=1" type="text/javascript"></script>

If you know that nothing on the page loads until the DOMContentLoaded event, then you can switch to the much faster version below:

<script src="https://www.dropbox.com/s/uo9kbpolhnat1cg/atobAndBtoaTogether.min.js?raw=1" type="text/javascript" defer=""></script>

There are two separate API functions introduced by the library:

  • /**String*/ btoaUTF8(/**String*/ originalString, /**boolean*/ autoBOMit = false)

    • Encodes the binary string originalString into valid base 64.
    • autoBOMit determines whether to append a BOM on to the end of the string. Only use this when the base64 is to be used as a data URI link. If you have no idea what this means and are confused, then simply ignore this option and it should not give you any problems.
  • /**String*/ atobUTF8(/**String*/ encodedBase64String, /**boolean*/ keepBOM = false)

    • Decodes the base64 string encodedBase64String into its original UTF8 binary counterpart.
    • keepBOM will keep the BOM of the string. Use this option if you are certain that the original UTF8 string was raw binary data. Keep this option false if you used the autoBOMit option when encoding the string.

BestBase64EncoderDecoder

I would assume that one might want it base64 encoded in a more standard way than other solutions that attempt to address this problem. This "standard" way is naturally interpretable by the browser such that you can use the base64 in a data URI. Please visit this data URI here to see a demonstration: data:text/plain;base64,4pi44pi54pi64pi74pi84pi+4pi/ (copy the data uri, open a new tab, paste the data URI into the address bar, then press enter to go to the page). As you can see, despite the fact that it is a base64-encoded URL, the browser is still able to recognize the high code points and decode them properly. Thus, this demonstration proves that this is the best way to go because it is the most W3C standard. Then, to decode the base64 data, either HTTP get the data as a data URI or use the function below. The advantage of being more standard is that this encoder and this decoder are more widely applicable because they can be used as a valid URL that displays correctly.

In addition to being very standardized, the above code snippets are also very fast. Instead of an indirect chain of succession where the data has to be converted several times between various forms, the above code snippet is as direct as performantly possible. It uses only one simple fast String.prototype.replace call to process the data when encoding, and only one to decode the data when decoding. Another plus is that (especially for big strings), String.prototype.replace allows the browser to automatically handle the underlying memory management of resizing the string, leading a significant performance boost especially in evergreen browsers like Chrome and Firefox that heavily optimize String.prototype.replace. Finally, the icing on the cake is that for you latin script exclūsīvō users, strings which don't contain any code points above 0x7f are extra fast to process because the string remains unmodified by the replacement algorithm.

(see also https://stackoverflow.com/a/53433503/5601591) (see also The MDN Page Base64_encoding_and_decoding)

SpiderNode (Hooray!) / NodeJS (Booo!)

Simply drop the file atobAndBtoaTogether.node.js into the same folder as your Javascript node file. Then, add the following to the Javascript to the node file:

var AtobAndBtoaTogether = require("./atobAndBtoaTogether.node.js");

Then, here is the node API:

  • /**String*/ AtobAndBtoaTogether.btoaUTF8(/**String*/ originalString, /**boolean*/ autoBOMit = false)

    • Encodes the binary string originalString into valid base 64.
    • autoBOMit determines whether to append a BOM on to the end of the string. Only use this when the base64 is to be used as a data URI link. If you have no idea what this means and are confused, then simply ignore this option and it should not give you any problems.
  • /**String*/ AtobAndBtoaTogether.atobUTF8(/**String*/ encodedBase64String, /**boolean*/ keepBOM = false)

    • Decodes the base64 string encodedBase64String into its original UTF8 binary counterpart.
    • keepBOM will keep the BOM of the string. Use this option if you are certain that the original UTF8 string was raw binary data. Keep this option false if you used the autoBOMit option when encoding the string.

Enjoy!