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

hi-base64

v0.4.1

Published

A simple Base64 encode / decode function for JavaScript supports UTF-8 encoding.

Downloads

1,803

Readme

hi-base64

Build Status Build Status
NPM
A simple Base64 encode / decode function for JavaScript supports UTF-8 encoding.

Demo

Base64 Encode Online
Base64 Decode Online

Download

Compress
Uncompress

Installation

You can also install hi-base64 by using Bower.

bower install hi-base64

For node.js, you can use this command to install:

npm install hi-base64

Usage

Browser

You could use like this:

base64.encode('String to encode');
base64.decode('Base64 string to decode');
base64.decode.bytes('Base64 string to decode as bytes');

CommonJS

If you use node.js CommonJS, you should require the module first:

const { encode, decode } = require('hi-bas64');

ESM

If you use node.js ESM, you can import like this:

import { encode, decode } from 'hi-bas64';

TypeScript

If you use TypeScript, you can import like this:

import { encode, decode } from 'hi-bas64';

RequireJS

It supports AMD:

require(['your/path/base64.js'], function (base64) {
// ...
});

Methods

base64.encode(str, asciiOnly, format)

Encode string to base64, set asciiOnly to true for better performace.

str: String

String to encode.

asciiOnly: Boolean (default: false)

Specify the string encoding is ASCII.

format: String (default: rfc_4648)

Specify the output format. can be following:

  • rfc_4648
  • rfc_4648_url_safe
  • rfc_2045
  • rfc_2152
  • rfc_3501

Please refer to wiki.

base64.decode(base64Str, asciiOnly)

Decode base64 string, set asciiOnly to true for better performace. base64.decode.string is alias to this method.

base64Str: String

Base64 string to decode.

asciiOnly: Boolean (default: false)

Specify the string encoding is ASCII.

base64.decode.bytes(base64Str)

Decode base64 string and return bytes Array.

base64Str: String

Base64 string to decode.

base64.decode.uint8Array(base64Str)

Decode base64 string and return bytes Uint8Array.

base64Str: String

Base64 string to decode.

Example

Code

base64.encode('Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.');
// TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=

base64.decode('VGhpcyBpcyB0ZXN0Lg==');
base64.decode.string('VGhpcyBpcyB0ZXN0Lg==');
// This is test.


/* Supports UTF-8 encoding: */
base64.encode('中文');
// 5Lit5paH


/* Supports bytes: */
base64.encode([0, 1, 2]);
base64.encode(new Uint8Array([0, 1, 2]));
// AAEC

base64.encode(new ArrayBuffer(3));
// AAAA

base64.decode.bytes('VGhpcyBpcyB0ZXN0Lg==');
// [84, 104, 105, 115, 32, 105, 115, 32, 116, 101, 115, 116, 46]

base64.decode.uint8Array('VGhpcyBpcyB0ZXN0Lg==');
// Uint8Array(13) [84, 104, 105, 115, 32, 105, 115, 32, 116, 101, 115, 116, 46]

Notice

In node.js, hi-base64 uses Buffer to encode / decode. It will not throw an exception when decoding a non-UTF8 base64 string as UTF-8 string. In browsers, hi-base64 will throw an exception in this case.

License

The project is released under the MIT license.

Contact

The project's website is located at https://github.com/emn178/hi-base64
Author: Chen, Yi-Cyuan [email protected]