notepack.io
Advanced tools
Changelog
3.0.0 (2022-05-22)
This change allows to properly encode BigInt objects:
// always as string
BigInt.prototype.toJSON = function () {
return String(this);
};
// or either as string or number, depending on the value
BigInt.prototype.toJSON = function () {
var isSafeNumber = Number.MIN_SAFE_INTEGER <= this && this <= Number.MAX_SAFE_INTEGER;
return isSafeNumber ? Number(this) : String(this);
};
import { encode } from "notepack.io";
encode(Uint8Array.of(1, 2, 3, 4));
// before: <Buffer c7 04 00 01 02 03 04>
// after: <Buffer c4 04 01 02 03 04>
ArrayBuffer objects encoded with previous versions of the library will still be decoded, but as Buffer instead of Uint8Array.
Reference: https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family
import { encode } from "notepack.io";
encode(new Date("2000-06-13T00:00:00.000Z"));
// before: <Buffer d7 00 00 00 00 df b7 62 9c 00>
// after: <Buffer d6 ff 39 45 79 80>
Date objects encoded with previous versions of the library will still be properly decoded.
Reference: https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type
The library will now match the behavior of the JSON.stringify() method:
import { encode, decode } from "notepack.io";
const value = {
a: undefined,
b: null,
c: [undefined, null]
};
decode(encode(value));
// before:
// {
// a: undefined,
// b: null,
// c: [undefined, null]
// }
// after:
// {
// b: null,
// c: [null, null]
// }