Spaces:
Sleeping
Sleeping
File size: 3,517 Bytes
3530df7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <p align="center">
<img src="https://cdn.jsdelivr.net/gh/hexagon/base64@main/base64.png" alt="@hexagon/base64" width="200" height="200"><br>
<br>Probably the only JavaScript base64 library you'll ever need!<br>
</p>
# @hexagon/base64
Encode, decode and validate base64/base64url to string/arraybuffer and vice-versa. Works in Node, Deno and browser.
[](https://github.com/Hexagon/base64/actions/workflows/node.js.yml) [](https://github.com/Hexagon/base64/actions/workflows/deno.yml)
[](https://badge.fury.io/js/@hexagon%2Fbase64) [](https://www.npmjs.org/package/@hexagon/base64) [](https://www.jsdelivr.com/package/npm/@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)
* Supports regular base64 and base64url
* Convert to/from string or arraybuffer
* Validate / identify base64 and base64url
* Works in Node.js >=4.0 (both require and import).
* Works in Deno >=1.16.
* Works in browsers as standalone, UMD or ES-module.
* Includes [TypeScript](https://www.typescriptlang.org/) typings.
```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?!
```
Full documentation available at [base64.56k.guru](https://base64.56k.guru)
## Quick Installation
Node.js: `npm install @hexagon/base64 --save`
Deno: `import base64 from "https://deno.land/x/b64@1.1.28/src/base64.js";`
For browser/cdn usage, refer to the documentation.
### Quick API
- __fromArrayBuffer(buffer, urlMode)__ - Encodes `ArrayBuffer` into base64 or base64url if urlMode(optional) is true
- __toArrayBuffer(str, urlMode)__ - Decodes base64url string (or base64url string if urlMode is true) to `ArrayBuffer`
- __fromString(str, urlMode)__ - Encodes `String` into base64 string(base64url string if urlMode is true)
- __toString(str, urlMode)__ - Decodes base64 or base64url string to `String`
- __validate(str, urlMode)__ - Returns true if `String` str is valid base64/base64 dependending on urlMode
## Contributing
See [Contribution Guide](https://base64.56k.guru/contributing.html)
## Donations
If you found this library helpful and wish to support its development, consider making a donation through [Hexagon's GitHub Sponsors page](https://github.com/sponsors/hexagon). Your generosity ensures the library's continued development and maintenance.
### Contributors
The underlying code is loosely based on [github.com/niklasvh/base64-arraybuffer](https://github.com/niklasvh/base64-arraybuffer)
## License
MIT
|