
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
A simple Base64 encode / decode function for JavaScript supports UTF-8 encoding.
A simple Base64 encode / decode function for JavaScript supports UTF-8 encoding.
Base64 Encode Online
Base64 Decode Online
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
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');
If you use node.js CommonJS, you should require the module first:
const { encode, decode } = require('hi-bas64');
If you use node.js ESM, you can import like this:
import { encode, decode } from 'hi-bas64';
If you use TypeScript, you can import like this:
import { encode, decode } from 'hi-bas64';
It supports AMD:
require(['your/path/base64.js'], function (base64) {
// ...
});
Encode string to base64, set asciiOnly to true for better performace.
String
String to encode.
Boolean
(default: false
)Specify the string encoding is ASCII.
String
(default: rfc_4648
)Specify the output format. can be following:
Please refer to wiki.
Decode base64 string, set asciiOnly to true for better performace. base64.decode.string
is alias to this method.
String
Base64 string to decode.
Boolean
(default: false
)Specify the string encoding is ASCII.
Decode base64 string and return bytes Array
.
String
Base64 string to decode.
Decode base64 string and return bytes Uint8Array
.
String
Base64 string to decode.
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]
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.
The project is released under the MIT license.
The project's website is located at https://github.com/emn178/hi-base64
Author: Chen, Yi-Cyuan emn178@gmail.com
v0.4.1 / 2024-10-02
FAQs
A simple Base64 encode / decode function for JavaScript supports UTF-8 encoding.
The npm package hi-base64 receives a total of 493 weekly downloads. As such, hi-base64 popularity was classified as not popular.
We found that hi-base64 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.