如何将对象编码和解码为 Base64?

How can I encode and decode a objedct to Base64?

我有一个对象 uriBase:

    const nameNFT = `...`;
    const descriptionNFT = `...`;
    const svg = `...`;

    const uriBase = {
      Name: `${nameNFT}`,
      Description: `${descriptionNFT}`,
      Painting: `${svg}`,
    };

如何将对象编码和解码为 Base64? 我使用 ReactJs,我正在尝试这样的事情:

$ npm install --save js-base64

import { Base64 } from "js-base64";
    const uriBase64 = Base64.encode(uriBase);

    return uriBase64;

    const decodeBase64Uri= Base64.decode(uriBase);

    return decodeBase64Uri;

并在控制台中

console.log(decodeBase64Uri);
print:
[Object object]

使用Buffer.

const object = {
    foo: 'bar',
};

// convert it to base64
const base64 = Buffer.from(JSON.stringify(object)).toString('base64');

console.table({ base64 });

// convert it back
const back = JSON.parse(Buffer.from(base64, 'base64').toString('utf-8'));

console.log(back);