@hexagon/base64
Advanced tools
Comparing version
{ | ||
"name": "@hexagon/base64", | ||
"version": "1.0.12", | ||
"description": "Base64 and base64url to string or arraybuffer, and back.", | ||
"version": "1.0.13", | ||
"description": "Base64 and base64url to string or arraybuffer, and back. Node, Deno or browser.", | ||
"author": "Hexagon <github.com/hexagon>", | ||
@@ -6,0 +6,0 @@ "homepage": "https://hexagon.github.io/base64", |
@@ -0,11 +1,16 @@ | ||
<p align="center"> | ||
<img src="/base64.png" alt="Croner" width="200" height="200"><br> | ||
<br>Probably the only JavaScript base64 library you'll ever need.<br> | ||
</p> | ||
# @hexagon/base64 | ||
Base64 and base64url to string or arraybuffer, and back. | ||
Base64 and base64url to string or arraybuffer, and back. Works in Node, Deno or browser. | ||
[](https://github.com/Hexagon/base64/actions/workflows/node.js.yml) | ||
[](https://badge.fury.io/js/@hexagon%2Fbase64) [](https://www.codacy.com/gh/Hexagon/base64/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Hexagon/base64&utm_campaign=Badge_Grade) | ||
[](https://badge.fury.io/js/@hexagon%2Fbase64) [](https://www.npmjs.org/package/@hexagon/base64) [](https://www.codacy.com/gh/Hexagon/base64/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Hexagon/base64&utm_campaign=Badge_Grade) | ||
[](https://github.com/Hexagon/base64/blob/master/LICENSE) [](https://www.jsdelivr.com/package/gh/hexagon/base64) | ||
* Support regular base64, and base64url | ||
* Convert to/from string or ArrayBuffers | ||
* Supports regular base64, as well as base64url | ||
* Convert to/from string or arraybuffer | ||
* Works in Node.js >=4.0 (both require and import). | ||
@@ -89,4 +94,30 @@ * Works in Deno >=1.16. | ||
## API | ||
### Examples | ||
Assuming you have imported base64 as described under 'Installation'. | ||
```javascript | ||
// Encode string as regular base64 | ||
const example1enc = base64.fromString("Hellö Wörld, how are you doing today?!"); | ||
console.log(example1enc); | ||
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ== | ||
// Decode string as regular base64 | ||
const example1dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk/IQ=="); | ||
console.log(example1dec); | ||
// > Hellö Wörld, how are you doing today?! | ||
// Encode string as base64url (setting the second parameter to true gives base64url) | ||
const example2enc = base64.fromString("Hellö Wörld, how are you doing today?!", true); | ||
console.log(example2enc); | ||
// > SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk_IQ | ||
// Decode string as base64url (setting the second parameter to true takes base64url) | ||
const example2dec = base64.toString("SGVsbMO2IFfDtnJsZCwgaG93IGFyZSB5b3UgZG9pbmcgdG9kYXk_IQ", true); | ||
console.log(example2dec); | ||
// > Hellö Wörld, how are you doing today?! | ||
``` | ||
### Full API | ||
The library encodes and decodes base64/base64url to and from ArrayBuffers | ||
@@ -93,0 +124,0 @@ |
39660
50.33%14
7.69%143
27.68%