@neshca/json-replacer-reviver

1.1.3 • Public • Published

@neshca/json-replacer-reviver

Utility library for handling Buffer object serialization and deserialization with JSON, offering base64 representations.

npm package Dependencies License

Installation

npm i @neshca/json-replacer-reviver

Usage

const buffer = Buffer.from('hello');
console.log(buffer); // <Buffer 68 65 6c 6c 6f>

const json = JSON.stringify(buffer);
console.log(json); // '{"type":"Buffer","data":[104,101,108,108,111]}'

const parsed = JSON.parse(json, reviveFromJsonRepresentation);
console.log(parsed); // <Buffer 68 65 6c 6c 6f>
const buffer = Buffer.from('hello');
console.log(buffer); // <Buffer 68 65 6c 6c 6f>

const jsonBase64 = JSON.stringify(buffer, replaceJsonWithBase64);
console.log(jsonBase64); // '{"type":"BufferBase64","data":"aGVsbG8="}'

const parsedFromBase64 = JSON.parse(jsonBase64, reviveFromBase64Representation);
console.log(parsed); // <Buffer 68 65 6c 6c 6f>

Developing and contributing

Developing and contributing to this monorepo

Running tests locally

npm run test -w ./packages/json-replacer-reviver

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @neshca/json-replacer-reviver

Weekly Downloads

8,627

Version

1.1.3

License

MIT

Unpacked Size

25.6 kB

Total Files

13

Last publish

Collaborators

  • caching-tools