Added atob and btoa for node

This commit is contained in:
Angelos Chalaris
2018-01-17 21:43:21 +02:00
parent 6b9ca7249c
commit b50cd7646a
3 changed files with 28 additions and 0 deletions

13
snippets/atob.md Normal file
View File

@ -0,0 +1,13 @@
### atob
Decodes a string of data which has been encoded using base-64 encoding.
Create a `Buffer` for the given string with base-64 encoding and use `Buffer.toString('binary')` to return the decoded string.
```js
const atob = str => new Buffer(str, 'base64').toString('binary');
```
```js
atob('Zm9vYmFy'); // 'foobar'
```

13
snippets/btoa.md Normal file
View File

@ -0,0 +1,13 @@
### 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(str, 'binary').toString('base64');
```
```js
btoa('foobar'); // 'Zm9vYmFy'
```

View File

@ -1,8 +1,10 @@
anagrams:string,recursion anagrams:string,recursion
arrayToHtmlList:browser,array arrayToHtmlList:browser,array
atob:node,string,utility
average:math,array average:math,array
averageBy:math,array,function averageBy:math,array,function
bottomVisible:browser bottomVisible:browser
btoa:node,string,utility
byteSize:string byteSize:string
call:adapter,function call:adapter,function
capitalize:string,array capitalize:string,array