Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Base64 encoding, decoding on both modern browser and Node.js

License

NotificationsYou must be signed in to change notification settings

waitingsong/base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Base64 encoding/decoding in pure JS on both modern Browsers and Node.js based onbase64-js.
Also supportsURL-safe base64

VersionLicenseBuild StatusBuild statusCoverage StatusConventional Commits

Features

  • Supports typeofstring,number andbigint
  • SupportsArrayBuffer orUint8Array
  • Encoding/Decoding viaTextEncoder/TextDecoder under browser andBuffer under Node.js
  • Building various modulesESM,UMD andCJS

Browser requirement

Node.js requirement

  • v10.4.0+ forbigint base64 encoding
  • ICU installation for base64 decoding with char encodings other thenutf-8 andutf-16le

Installing

npm install @waiting/base64

Usage of Node.js

See theDocs for details

Encoding

import{b64encode,b64fromBuffer,b64urlEncode}from'@waiting/base64'b64encode('A')==='QQ=='b64encode('schöne')==='c2Now7ZuZQ=='b64encode(1n)===b64encode(1)// bigint -> 'MQ=='b64encode('𠮷')===b64encode('\uD842\uDFB7')===b64encode('\u{20BB7}')// '8KCutw=='constu8arr=Uint8Array.from([0xe4,0xb8,0xad,0xe6,0x96,0x87])b64fromBuffer(u8arr)===b64encode('中文')// '5Lit5paH'// URL-safeb64urlEncode('A')==='QQ'b64urlEncode('中文测试')==='5Lit5paH5rWL6K-V'

Decoding

import{b64decode,b64urlDecode}from'@waiting/base64'b64decode('MQ==')==='1'b64urlDecode('MQ')==='1'

Transfer

import{b64toURLSafe,b64fromURLSafe}from'@waiting/base64'// base64 -> URL-safe base64b64toURLSafe('QQ==')==='QQ'b64toURLSafe('5Lit5paH5rWL6K+V')==='5Lit5paH5rWL6K-V'// URL-safe base64 -> base64b64fromURLSafe('QQ')==='QQ=='b64fromURLSafe('0J_RgNC40LLQtdGCLCDQvNC40YAh')==='0J/RgNC40LLQtdGCLCDQvNC40YAh'

Usage of browser

See theDocs for details

ESM

<scripttype="module">import{b64encode,b64urlEncode}from'./base64.esm.min.js'console.log(b64encode('A'))// 'QQ=='console.log(b64urlEncode('A'))// 'QQ'console.log(b64encode('\uD842\uDFB7'))// '8KCutw=='</script>

UMD

<!-- polyfill for Edge  Note: text-encoder-lite parse 4-bytes UTF-8 char incorrectly,  so use text-encoding instead.  see: https://github.com/solderjs/TextEncoderLite/issues/16--><!--<script src="https://raw.githubusercontent.com/inexorabletash/text-encoding/master/lib/encoding-indexes.js"></script><script src="https://raw.githubusercontent.com/inexorabletash/text-encoding/master/lib/encoding.js"></script>--><scriptsrc="./base64.umd.min.js"></script><script>// global variable base64console.log(base64.b64encode('A'))console.log(base64.b64urlEncode('A'))console.log(base64.b64encode('\uD842\uDFB7'))</script>

Testing

npm runtest# for browsers FireFox and Chromenpm run test:browser# for browsers all available on this clientcd .config&& npm inpm run browser:detect

Demo

License

MIT

Languages

About

Base64 encoding, decoding on both modern browser and Node.js

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp