@se-oss/msgpack
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@se-oss/msgpack

CI NPM Version MIT License Install Size

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.


📦 Installation

npm install @se-oss/msgpack

📖 Usage

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);

📚 Documentation

For all configuration options, please see the API docs.

API
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;
}

🤝 Contributing

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! 🙏

Relevant

License

MIT © Shahrad Elahi and contributors.

Package Sidebar

Install

npm i @se-oss/msgpack

Weekly Downloads

30

Version

1.0.0

License

MIT

Unpacked Size

15 kB

Total Files

6

Last publish

Collaborators

  • shahradelahi