Files
30-seconds-of-code/snippets/btoa.md
2018-10-03 23:08:31 +02:00

14 lines
395 B
Markdown

### btoa
Creates a base-64 encoded ASCII string from a String object in which each character in the string is treated as a byte of binary data.
Create a `Buffer` for the given string with binary encoding and use `Buffer.toString('base64')` to return the encoded string.
```js
const btoa = str => new Buffer.from(str, 'binary').toString('base64');
```
```js
btoa('foobar'); // 'Zm9vYmFy'
```