All Projects → kaelzhang → b2a

kaelzhang / b2a

Licence: MIT License
btoa and atob support for node.js or old browsers, with the Unicode Problems fixed

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to b2a

Weird Json
A collection of strange encoded JSONs. For connoisseurs.
Stars: ✭ 53 (+152.38%)
Mutual labels:  unicode, base64
uax29
A tokenizer based on Unicode text segmentation (UAX 29), for Go
Stars: ✭ 26 (+23.81%)
Mutual labels:  unicode
unicode-emoji-json
Emoji data from unicode.org as easily consumable JSON files.
Stars: ✭ 149 (+609.52%)
Mutual labels:  unicode
contour
Modern C++ Terminal Emulator
Stars: ✭ 761 (+3523.81%)
Mutual labels:  unicode
jose-simple
Jose-Simple allows the encryption and decryption of data using the JOSE (JSON Object Signing and Encryption) standard.
Stars: ✭ 50 (+138.1%)
Mutual labels:  base64
rm-emoji-picker
A modern, ES2015 emoji picker and editor.
Stars: ✭ 76 (+261.9%)
Mutual labels:  unicode
micell
A collection of functions for front-end development
Stars: ✭ 16 (-23.81%)
Mutual labels:  base64
libWinTF8
The library handling things related to UTF-8 and Unicode when you want to port your program to Windows
Stars: ✭ 18 (-14.29%)
Mutual labels:  unicode
StringConvert
A simple C++11 based helper for converting string between a various charset
Stars: ✭ 16 (-23.81%)
Mutual labels:  unicode
unidecode
Elixir package to transliterate Unicode to ASCII
Stars: ✭ 18 (-14.29%)
Mutual labels:  unicode
fast-base64
Fastest base64 on the web, with Wasm + SIMD
Stars: ✭ 23 (+9.52%)
Mutual labels:  base64
Wordle2Townscaper
Wordle2Townscaper is meant to convert Wordle tweets into Townscaper houses using yellow and green building blocks.
Stars: ✭ 64 (+204.76%)
Mutual labels:  unicode
umoji
😄 A lib convert emoji unicode to Surrogate pairs
Stars: ✭ 68 (+223.81%)
Mutual labels:  unicode
UniObfuscator
Java obfuscator that hides code in comment tags and Unicode garbage by making use of Java's Unicode escapes.
Stars: ✭ 40 (+90.48%)
Mutual labels:  unicode
unicode-c
A C library for handling Unicode, UTF-8, surrogate pairs, etc.
Stars: ✭ 32 (+52.38%)
Mutual labels:  unicode
prettype
An easy to use text stylizer for your desktop!
Stars: ✭ 14 (-33.33%)
Mutual labels:  unicode
secondhand-deal
A campus secondhand trading system based on the vue.js + stylus + koa2 + sequelize ORM + mysql, and typescript is still learning to migrate.🍌
Stars: ✭ 21 (+0%)
Mutual labels:  base64
postcss-inline-base64
PostCSS plugin used to replace value inside of url function to base64
Stars: ✭ 23 (+9.52%)
Mutual labels:  base64
text-rendering-tests
Unicode’s test suite for text rendering engines
Stars: ✭ 135 (+542.86%)
Mutual labels:  unicode
widestring-rs
A wide string Rust library for converting to and from wide Unicode strings.
Stars: ✭ 48 (+128.57%)
Mutual labels:  unicode

Build Status Coverage

b2a

btoa and atob (base64/base64url encoding and decoding) support for node.js or old browsers, with the Unicode Problems fixed.

The common problem of other libraries is that they fail to encode 16-bit strings. Since DOMStrings are 16-bit-encoded strings, in most browsers calling window.btoa on a Unicode string will cause a 'Character Out Of Range' exception if a character exceeds the range of a 8-bit byte (0x00~0xFF).

This module will try to reuse window.atob and window.btoa when possible.

Install

$ npm install b2a

Usage

import {
  // Encode a string in base-64
  btoa,
  // Decode a string in base-64
  atob,

  // Encode a string into base64url
  btoau,
  // Decode a base64url-encoded string
  atobu
} from 'b2a'

btoa('a')           // 'YQ=='
window.btoa('a')    // 'YQ==', works fine with ASCII characters


// Oooooooops!
// In most browsers, calling btoa() on a Unicode string
// will cause a Character Out Of Range exception.
window.btoa('中文')  // throws InvalidCharacterError ❌

btoa('中文')         // '5Lit5paH' ✅


// Oooooooops!
window.atob('5Lit5paH')   // '中æ', oh no! ❌

atob('5Lit5paH')          // '中文', great! ✅


btoau('μπορούμε')                 // zrzPgM6_z4HOv8-NzrzOtQ==

atobu('zrzPgM6_z4HOv8-NzrzOtQ==') // μπορούμε

base64url support since 1.1.0

Since 1.1.0, btoau and atobu are introduced to encode and decode in base64url format.

import {btoau} from 'b2a'

location.href = `https://domain.com/login?return_to=${btoau(location.href)}`

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].