@neshca/json-replacer-reviver
v1.1.3
Published
Utility library for handling `Buffer` object serialization and deserialization with JSON, offering base64 representations
Downloads
38,384
Readme
@neshca/json-replacer-reviver
Utility library for handling Buffer
object serialization and deserialization with JSON, offering base64 representations.
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