A lightweight utility for encoding objects and buffers into base64 MessagePack and decoding them back to their original form. Provides seamless conversion between JSON and MessagePack, with support for custom encoding and decoding options.
npm install @se-oss/msgpack
import { MSGPack } from '@se-oss/msgpack';
// Basic usage example to stringify object to Base64
const obj = { hello: 'world', numbers: [1, 2, 3], nested: { a: 1, b: 2 } };
const encoded = MSGPack.stringify(obj);
console.log('Encoded:', encoded);
const decoded = MSGPack.parse(encoded);
console.log('Decoded:', decoded);
// Using with custom options
const customEncoded = MSGPack.stringify(obj, {
maxDepth: 3,
ignoreUndefined: true,
});
console.log('Custom encoded:', customEncoded);
For all configuration options, please see the API docs.
class MSGPack {
/**
* Parses a base64 encoded string into its original form.
*
* @param input - A base64 encoded string to be parsed.
* @param options - Optional decoder options for the msgpack decode function.
* @returns The decoded object or value.
* @throws {TypeError} If the input is not a valid base64 encoded string.
*/
static parse(input: string, options?: Partial<DecoderOptions>): unknown;
/**
* Stringifies an object or value into a base64 encoded string.
*
* @param {ObjectLike} input - An object or value to be stringified.
* @param options - Optional encoder options for the msgpack encode function.
* @returns A base64 encoded string representing the input object or value.
* @throws {TypeError} If the input is not an object.
*/
static stringify(input: ObjectLike, options?: Partial<EncoderOptions> ): string;
}
Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub
Thanks again for your support, it is much appreciated! 🙏
MIT © Shahrad Elahi and contributors.