README
base64-converter
A library that allows bidirectional conversion of strings and base64. Available in both browser and Node.js.
Note: Actually, this would be a bit more useful in traditional web development. If you're developing in a Node.js environment, it's no different than implementing it yourself.
Note 2: What I recently discovered is that you can do base64 conversion using btoa()
and atob()
in the browser. If you're not using Node.js on your server, this may be sufficient. :joy:
Installation
CDN
<script src="https://cdn.jsdelivr.net/npm/@ony3000/base64-converter@1.1.1/dist/converter.js"></script>
NPM
npm install @ony3000/base64-converter
Yarn
yarn add @ony3000/base64-converter
Usage
with CDN
<script>
console.log(converter.base64Encode('Hello world!')); // 'SGVsbG8gd29ybGQh'
console.log(converter.base64Decode('SGVsbG8gd29ybGQh')); // 'Hello world!'
</script>
without CDN
// You can import it in one of the following ways:
/* 1 */ const { base64Encode, base64Decode } = require('@ony3000/base64-converter');
/* 2 */ import { base64Encode, base64Decode } from '@ony3000/base64-converter';
console.log(base64Encode('Hello world!')); // 'SGVsbG8gd29ybGQh'
console.log(base64Decode('SGVsbG8gd29ybGQh')); // 'Hello world!'
Browser compatibility
- Internet Explorer 9+
- Most modern browsers except Internet Explorer