From b50cd7646a581ff8fc8e408c06ca2342c63b8b5c Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 17 Jan 2018 21:43:21 +0200 Subject: [PATCH] Added atob and btoa for node --- snippets/atob.md | 13 +++++++++++++ snippets/btoa.md | 13 +++++++++++++ tag_database | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 snippets/atob.md create mode 100644 snippets/btoa.md diff --git a/snippets/atob.md b/snippets/atob.md new file mode 100644 index 000000000..e7fa6d167 --- /dev/null +++ b/snippets/atob.md @@ -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' +``` diff --git a/snippets/btoa.md b/snippets/btoa.md new file mode 100644 index 000000000..970cee770 --- /dev/null +++ b/snippets/btoa.md @@ -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' +``` diff --git a/tag_database b/tag_database index f24d2af5c..6a577d873 100644 --- a/tag_database +++ b/tag_database @@ -1,8 +1,10 @@ anagrams:string,recursion arrayToHtmlList:browser,array +atob:node,string,utility average:math,array averageBy:math,array,function bottomVisible:browser +btoa:node,string,utility byteSize:string call:adapter,function capitalize:string,array