Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.71 KB

File metadata and controls

63 lines (43 loc) · 1.71 KB

@neshca/json-replacer-reviver

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

npm package Dependencies License

Installation

npm add @neshca/json-replacer-reviver
pnpm add @neshca/json-replacer-reviver
yarn add @neshca/json-replacer-reviver
bun add @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

pnpm -F @repo/json-replacer-reviver test

License

MIT