From 99f1670b99dfd7bc03141dbb9aa6e4ccdb5ca59e Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 17 Mar 2021 13:11:05 -0700 Subject: [PATCH] buffer: expose btoa and atob as globals Signed-off-by: James M Snell --- .eslintrc.js | 2 ++ doc/api/buffer.md | 4 ++++ doc/api/globals.md | 20 +++++++++++++++++ lib/internal/bootstrap/node.js | 31 +++++++++++++++++++++----- test/common/index.js | 7 ++++++ test/parallel/test-btoa-atob-global.js | 9 ++++++++ 6 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 test/parallel/test-btoa-atob-global.js diff --git a/.eslintrc.js b/.eslintrc.js index 7574e1b4b6c7f7..28a31d050a6de1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -329,5 +329,7 @@ module.exports = { TextDecoder: 'readable', queueMicrotask: 'readable', globalThis: 'readable', + btoa: 'readable', + atob: 'readable', }, }; diff --git a/doc/api/buffer.md b/doc/api/buffer.md index f31b8b298b02eb..60c073287baee9 100644 --- a/doc/api/buffer.md +++ b/doc/api/buffer.md @@ -3282,6 +3282,8 @@ accessed using `require('buffer')`. added: REPLACEME --> +> Stability: 3 - Legacy. Use `Buffer.from(data, 'base64')` instead. + * `data` {any} The Base64-encoded input string. Decodes a string of Base64-encoded data into bytes, and encodes those bytes @@ -3301,6 +3303,8 @@ and binary data should be performed using `Buffer.from(str, 'base64')` and added: REPLACEME --> +> Stability: 3 - Legacy. Use `buf.toString('base64')` instead. + * `data` {any} An ASCII (Latin1) string. Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes diff --git a/doc/api/globals.md b/doc/api/globals.md index 6f8c9d3b398c11..831ef06bec6094 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -146,6 +146,24 @@ This variable may appear to be global but is not. See [`__dirname`][]. This variable may appear to be global but is not. See [`__filename`][]. +## `atob(data)` + + +> Stability: 3 - Legacy. Use `Buffer.from(data, 'base64')` instead. + +Global alias for [`buffer.atob()`][]. + +## `btoa(data)` + + +> Stability: 3 - Legacy. Use `buf.toString('base64')` instead. + +Global alias for [`buffer.btoa()`][]. + ## `clearImmediate(immediateObject)`