{"_id":"algo-msgpack-with-bigint","_rev":"2-5b27f4e40981613e9398ae2bc5ef9701","name":"algo-msgpack-with-bigint","dist-tags":{"latest":"2.1.1"},"versions":{"2.1.0":{"name":"algo-msgpack-with-bigint","version":"2.1.0","description":"MessagePack for JavaScript/ECMA-262, with changed behavior for BigInts","author":{"name":"The MessagePack community orginally; forked by @EvanJRichard for Algorand"},"license":"ISC","main":"./dist/index.js","browser":"./dist.es5/msgpack.min.js","types":"./dist/index.d.ts","sideEffects":false,"scripts":{"build":"npm publish --dry-run","prepare":"npm run clean && tsc -p tsconfig.dist.json && webpack","prepublishOnly":"run-p 'test:dist:*' && npm run test:browser","clean":"rimraf build dist dist.*","test":"mocha 'test/**/*.test.ts'","test:purejs":"TEXT_ENCODING=never mocha 'test/**/*.test.ts'","test:te":"TEXT_ENCODING=force mocha 'test/**/*.test.ts'","test:dist:purejs":"TS_NODE_PROJECT=tsconfig.test-dist-es5-purejs.json npm run test:purejs -- --reporter=dot","test:cover":"npm run cover:clean && npm-run-all 'test:cover:*' && npm run cover:report","test:cover:purejs":"npx nyc --no-clean npm run test:purejs","test:cover:te":"npx nyc --no-clean npm run test:te","cover:clean":"rimraf .nyc_output coverage/","cover:report":"npx nyc report --reporter=text-summary --reporter=html --reporter=json","test:browser":"karma start --single-run","test:browser:firefox":"karma start --single-run --browsers FirefoxHeadless","test:browser:chrome":"karma start --single-run --browsers ChromeHeadless","test:watch:browser":"karma start --browsers ChromeHeadless,FirefoxHeadless","test:watch:nodejs":"mocha -w 'test/**/*.test.ts'","lint":"eslint --ext .ts src test","lint:fix":"eslint --fix --ext .ts src test","lint:print-config":"eslint --print-config .eslintrc.js","update-dependencies":"npx rimraf node_modules/ package-lock.json && npm install && npm dedupe"},"homepage":"https://msgpack.org/","repository":{"type":"git","url":"git+https://github.com/msgpack/msgpack-javascript.git"},"bugs":{"url":"https://github.com/msgpack/msgpack-javascript/issues"},"keywords":["msgpack","MessagePack","serialization","universal"],"engines":{"node":">= 10"},"devDependencies":{"@bitjourney/check-es-version-webpack-plugin":"latest","@types/mocha":"latest","@types/node":"latest","@typescript-eslint/eslint-plugin":"latest","@typescript-eslint/parser":"latest","assert":"latest","blob-polyfill":"latest","core-js":"latest","eslint":"latest","eslint-config-prettier":"latest","eslint-plugin-import":"latest","eslint-plugin-prettier":"latest","ieee754":"latest","karma":"latest","karma-chrome-launcher":"latest","karma-cli":"latest","karma-firefox-launcher":"latest","karma-mocha":"latest","karma-sauce-launcher":"latest","karma-sourcemap-loader":"latest","karma-webpack":"latest","lodash":"latest","mocha":"latest","msgpack-test-js":"latest","npm-run-all":"latest","prettier":"latest","rimraf":"latest","ts-loader":"latest","ts-node":"^9.0.0","tsconfig-paths":"latest","typescript":"latest","web-streams-polyfill":"latest","webpack":"latest","webpack-cli":"latest"},"dependencies":{},"gitHead":"d128047628fe2a0dd8b1a35f61f9bf3c862e5820","_id":"algo-msgpack-with-bigint@2.1.0","_nodeVersion":"14.4.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-Ac+rO/njXaBvECLLRqZezjQ6z+xtyRMVGcYzW3ghNxAzUPN9Xpo3vTPVhdArh2gehEtCnnAtsPhRpj5OwPMHMQ==","shasum":"00002c6b20912b263f96b4b9b9c4f8acb8cfc1cb","tarball":"https://registry.npmjs.org/algo-msgpack-with-bigint/-/algo-msgpack-with-bigint-2.1.0.tgz","fileCount":72,"unpackedSize":518498,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfhM8PCRA9TVsSAnZWagAAnHAP/jI06A9gmz63ET1O840Z\nkwEDhudKhkeXctM69wIMcxjkiQdNi7cxA93m5MyAr+i6OxZDCZD+Ta1BRaDo\nvNQ3E8iVNQqg2kC1T1ag6hSiRMt6c3Mq5sQwWKD/h5Rx+oY/qXzp85LzTH+x\nw8YC8MF1BbzEQLwBEjs5YsWoL/SYafO3JHJVYx64QHBXd+u+NGSuIpvfurYd\nCCu9ocHKSrPzU95jqbg0P4B6sgeHcqz6r69/9v9ksozmu5jKguQlp9N5u55Q\nA9u0NtOVtIXF/RclbVojMc6hBcciKLFvGHEaKMNWf1JwRz8GiWF1M+s/fPSM\nv4mOAHvTHDz/dZq9xOW86V5hNTBkS8feq8goZgUYMDw+lDy38fcpCjvCCje+\nMyrOZBgcfxRKyM8f/8wH13j5fRX5tyqhY9PIx/p53otcYownJ4Ym23t+uBBX\n371PF1QXOc94QTvcjY2Yv5fxMCkwEL978rvznSznNya417PSd+S3ZF3m8aWX\nFo+Q5NdyUmojMHG2cVxY4xyC1bAXbmhwh+iivZjMS53vb7+t13K5sR9BMRbw\nsuXIipjH5V1ZusoWFr0SdjeVtQLi/LONmj0NDG063Klg7/LPTamHBWwwc8Kc\nfhNVdS/BvLqm673LVMenT08hgJShdxXFDJspom2Tdmc2ZDZjZ2ecC+5geHWe\neLfV\r\n=gIhB\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICigDKC9q7OlLphI+wxtMzt0BLkmRgbUv46qPbcpelgRAiBRWnQ+TpTOc6vekosVEXff3fyqhiMT3eqfJXdvXYVySQ=="}]},"maintainers":[{"name":"evanjrichard","email":"evanjrichard@gmail.com"}],"_npmUser":{"name":"evanjrichard","email":"evanjrichard@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/algo-msgpack-with-bigint_2.1.0_1602539278464_0.40245329412719877"},"_hasShrinkwrap":false},"2.1.1":{"name":"algo-msgpack-with-bigint","version":"2.1.1","description":"MessagePack for JavaScript/ECMA-262, with changed behavior for BigInts","author":{"name":"The MessagePack community orginally; forked by @EvanJRichard for Algorand"},"license":"ISC","main":"./dist/index.js","browser":"./dist.es5/msgpack.min.js","types":"./dist/index.d.ts","sideEffects":false,"scripts":{"build":"npm publish --dry-run","prepare":"npm run clean && tsc -p tsconfig.dist.json && webpack","prepublishOnly":"run-p 'test:dist:*' && npm run test:browser","clean":"rimraf build dist dist.*","test":"mocha 'test/**/*.test.ts'","test:purejs":"TEXT_ENCODING=never mocha 'test/**/*.test.ts'","test:te":"TEXT_ENCODING=force mocha 'test/**/*.test.ts'","test:dist:purejs":"TS_NODE_PROJECT=tsconfig.test-dist-es5-purejs.json npm run test:purejs -- --reporter=dot","test:cover":"npm run cover:clean && npm-run-all 'test:cover:*' && npm run cover:report","test:cover:purejs":"npx nyc --no-clean npm run test:purejs","test:cover:te":"npx nyc --no-clean npm run test:te","cover:clean":"rimraf .nyc_output coverage/","cover:report":"npx nyc report --reporter=text-summary --reporter=html --reporter=json","test:browser":"karma start --single-run","test:browser:firefox":"karma start --single-run --browsers FirefoxHeadless","test:browser:chrome":"karma start --single-run --browsers ChromeHeadless","test:watch:browser":"karma start --browsers ChromeHeadless,FirefoxHeadless","test:watch:nodejs":"mocha -w 'test/**/*.test.ts'","lint":"eslint --ext .ts src test","lint:fix":"eslint --fix --ext .ts src test","lint:print-config":"eslint --print-config .eslintrc.js","update-dependencies":"npx rimraf node_modules/ package-lock.json && npm install && npm dedupe"},"homepage":"https://msgpack.org/","repository":{"type":"git","url":"git+https://github.com/EvanJRichard/msgpack-javascript.git"},"bugs":{"url":"https://github.com/msgpack/msgpack-javascript/issues"},"keywords":["msgpack","MessagePack","serialization","universal"],"engines":{"node":">= 10"},"devDependencies":{"@bitjourney/check-es-version-webpack-plugin":"latest","@types/mocha":"latest","@types/node":"latest","@typescript-eslint/eslint-plugin":"latest","@typescript-eslint/parser":"latest","assert":"latest","blob-polyfill":"latest","core-js":"latest","eslint":"latest","eslint-config-prettier":"latest","eslint-plugin-import":"latest","eslint-plugin-prettier":"latest","ieee754":"latest","karma":"latest","karma-chrome-launcher":"latest","karma-cli":"latest","karma-firefox-launcher":"latest","karma-mocha":"latest","karma-sauce-launcher":"latest","karma-sourcemap-loader":"latest","karma-webpack":"latest","lodash":"latest","mocha":"latest","msgpack-test-js":"latest","npm-run-all":"latest","prettier":"latest","rimraf":"latest","ts-loader":"latest","ts-node":"^9.0.0","tsconfig-paths":"latest","typescript":"latest","web-streams-polyfill":"latest","webpack":"latest","webpack-cli":"latest"},"dependencies":{},"gitHead":"982c93b42a9c6c5d1037973bfb77cc11f7bc6d36","_id":"algo-msgpack-with-bigint@2.1.1","_nodeVersion":"14.4.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-F1tGh056XczEaEAqu7s+hlZUDWwOBT70Eq0lfMpBP2YguSQVyxRbprLq5rELXKQOyOaixTWYhMeMQMzP0U5FoQ==","shasum":"38bb717220525b3ff42232eefdcd9efb9ad405d6","tarball":"https://registry.npmjs.org/algo-msgpack-with-bigint/-/algo-msgpack-with-bigint-2.1.1.tgz","fileCount":72,"unpackedSize":518503,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfkG5kCRA9TVsSAnZWagAAjasP/Rt6mn3ikg14oTZHyQl/\nX7hY+9oHrj3GCa7oRwyE3HqNxRkoHHARSzuf892eUZZSTyyOBkRBX/VEJRFb\nCMNxXl7RppOTfiUkK+zTrJiFVJxXmaSsA2VXF20h+1wAi38Kp4DW587hkC6Z\n2ln7XbC7z0zQ9O57goji+pya72AFnIiyYP9hb41VurlYKJZJMUUjipM846sL\ntv0WrRiXOC5hHd3iQD2Nd/EYPx/BVaaEYJk4wXirirygVqIvUUgcAWur7Bl3\nwXGe5nhRJlZR7w31HzDppHg5pvzOSMzQjovPQOm9ORh4qODuaK6l6NTHoonI\nmN9JeE3wLRnbFO3aJlf1K1YbisuWX8x+8UqAtkrdXdrZHA6YBpfJsmqHyCQv\n+GTPSNg9yvwVBZwfp7PxJBmDjIslZbDPP/2kttfSLp+63f6KNumq3JAhtA7Z\nOQXtah2V0itjOvTotiNQboCrEZ8uxAgq38rF+Z3TCB3V6vr9e5fnJQrJo28o\n1SOEDaM9DuS8qAfunOTptbIHll/QfhaRrCRKRU/UKj0xai8iyrJZhax+wjQK\n6GDKUsT/0jaxl1po0IDnDNo/m+lHfuZ/6L2pgj/PTz0zKg9xjZkKg/wJafrd\nsDa0UXKBKU/2Ws8Mph5AA/NaHC5lcmNldf5zT+p/Y0WUdU8z98aPBKbI8pVA\n094+\r\n=/MiO\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBCaoQPpJD8IHOY1uHY4/5SfUynlwe8F/m9nXe7wePY1AiBxxp1FXe/1B9NAU6CdhpHf1PMknJDHFyvkq7H/Fz3lAw=="}]},"maintainers":[{"name":"evanjrichard","email":"evanjrichard@gmail.com"}],"_npmUser":{"name":"evanjrichard","email":"evanjrichard@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/algo-msgpack-with-bigint_2.1.1_1603300963863_0.23933768009905343"},"_hasShrinkwrap":false}},"time":{"created":"2020-10-12T21:47:58.463Z","2.1.0":"2020-10-12T21:47:58.637Z","modified":"2022-04-11T13:22:49.649Z","2.1.1":"2020-10-21T17:22:44.017Z"},"maintainers":[{"name":"evanjrichard","email":"evanjrichard@gmail.com"}],"description":"MessagePack for JavaScript/ECMA-262, with changed behavior for BigInts","homepage":"https://msgpack.org/","keywords":["msgpack","MessagePack","serialization","universal"],"repository":{"type":"git","url":"git+https://github.com/EvanJRichard/msgpack-javascript.git"},"author":{"name":"The MessagePack community orginally; forked by @EvanJRichard for Algorand"},"bugs":{"url":"https://github.com/msgpack/msgpack-javascript/issues"},"license":"ISC","readme":"# MessagePack for JavaScript/ECMA-262\n\n[![npm version](https://img.shields.io/npm/v/@msgpack/msgpack.svg)](https://www.npmjs.com/package/@msgpack/msgpack) [![Build Status](https://travis-ci.org/msgpack/msgpack-javascript.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-javascript) [![codecov](https://codecov.io/gh/msgpack/msgpack-javascript/branch/master/graphs/badge.svg)](https://codecov.io/gh/msgpack/msgpack-javascript) [![bundlephobia](https://badgen.net/bundlephobia/minzip/@msgpack/msgpack)](https://bundlephobia.com/result?p=@msgpack/msgpack)\n\n[![Browser Matrix powered by Sauce Labs](https://saucelabs.com/browser-matrix/gfx2019.svg)](https://saucelabs.com)\n\nThis is a JavaScript/ECMA-262 implementation of **MessagePack**, an efficient binary serilization format:\n\nhttps://msgpack.org/\n\nThis library is a universal JavaScript, meaning it is compatible with all the major browsers and NodeJS. In addition, because it is implemented in [TypeScript](https://www.typescriptlang.org/), type definition files (`d.ts`) are bundled in the distribution.\n\n*Note that this is the second version of MessagePack for JavaScript. The first version, which was implemented in ES5 and was never released to npmjs.com, is tagged as [classic](https://github.com/msgpack/msgpack-javascript/tree/classic).*\n\n## Synopsis\n\n```typescript\nimport { deepStrictEqual } from \"assert\";\nimport { encode, decode } from \"@msgpack/msgpack\";\n\nconst object = {\n  nil: null,\n  integer: 1,\n  float: Math.PI,\n  string: \"Hello, world!\",\n  binary: Uint8Array.from([1, 2, 3]),\n  array: [10, 20, 30],\n  map: { foo: \"bar\" },\n  timestampExt: new Date(),\n};\n\nconst encoded: Uint8Array = encode(object);\n\ndeepStrictEqual(decode(encoded), object);\n```\n\n## Table of Contents\n\n<!-- TOC depthFrom:2 anchorMode:github.com -->\n\n- [Synopsis](#synopsis)\n- [Table of Contents](#table-of-contents)\n- [Install](#install)\n- [API](#api)\n  - [`encode(data: unknown, options?: EncodeOptions): Uint8Array`](#encodedata-unknown-options-encodeoptions-uint8array)\n    - [`EncodeOptions`](#encodeoptions)\n  - [`decode(buffer: ArrayLike<number> | ArrayBuffer, options?: DecodeOptions): unknown`](#decodebuffer-arraylikenumber--arraybuffer-options-decodeoptions-unknown)\n    - [`DecodeOptions`](#decodeoptions)\n  - [`decodeAsync(stream: AsyncIterable<ArrayLike<number>> | ReadableStream<ArrayLike<number>>, options?: DecodeAsyncOptions): Promise<unknown>`](#decodeasyncstream-asynciterablearraylikenumber--readablestreamarraylikenumber-options-decodeasyncoptions-promiseunknown)\n  - [`decodeArrayStream(stream: AsyncIterable<ArrayLike<number>> | ReadableStream<ArrayLike<number>>, options?: DecodeAsyncOptions): AsyncIterable<unknown>`](#decodearraystreamstream-asynciterablearraylikenumber--readablestreamarraylikenumber-options-decodeasyncoptions-asynciterableunknown)\n  - [`decodeStream(stream: AsyncIterable<ArrayLike<number>> | ReadableStream<ArrayLike<number>>, options?: DecodeAsyncOptions): AsyncIterable<unknown>`](#decodestreamstream-asynciterablearraylikenumber--readablestreamarraylikenumber-options-decodeasyncoptions-asynciterableunknown)\n  - [Reusing Encoder and Decoder instances](#reusing-encoder-and-decoder-instances)\n- [Extension Types](#extension-types)\n    - [ExtensionCodec context](#extensioncodec-context)\n    - [Handling BigInt with ExtensionCodec](#handling-bigint-with-extensioncodec)\n    - [The temporal module as timestamp extensions](#the-temporal-module-as-timestamp-extensions)\n- [Decoding a Blob](#decoding-a-blob)\n- [MessagePack Specification](#messagepack-specification)\n  - [MessagePack Mapping Table](#messagepack-mapping-table)\n- [Prerequsites](#prerequsites)\n  - [ECMA-262](#ecma-262)\n  - [NodeJS](#nodejs)\n- [Benchmark](#benchmark)\n- [Distribution](#distribution)\n  - [NPM / npmjs.com](#npm--npmjscom)\n  - [CDN / unpkg.com](#cdn--unpkgcom)\n- [Maintenance](#maintenance)\n  - [Testing](#testing)\n  - [Continuous Integration](#continuous-integration)\n  - [Release Engineering](#release-engineering)\n  - [Updating Dependencies](#updating-dependencies)\n- [Big Thanks](#big-thanks)\n- [License](#license)\n\n<!-- /TOC -->\n\n## Install\n\nThis library is published to `npmjs.com` as [@msgpack/msgpack](https://www.npmjs.com/package/@msgpack/msgpack).\n\n```shell\nnpm install @msgpack/msgpack\n```\n\n## API\n\n### `encode(data: unknown, options?: EncodeOptions): Uint8Array`\n\nIt encodes `data` and returns a byte array as `Uint8Array`, throwing errors if `data` is, or includes, a non-serializable object such as a `function` or a `symbol`.\n\nfor example:\n\n```typescript\nimport { encode } from \"@msgpack/msgpack\";\n\nconst encoded: Uint8Array = encode({ foo: \"bar\" });\nconsole.log(encoded);\n```\n\nIf you'd like to convert the uint8array to a NodeJS `Buffer`, use `Buffer.from(arrayBuffer, offset, length)` in order not to copy the underlying `ArrayBuffer`, while `Buffer.from(uint8array)` copies it:\n\n```typescript\nimport { encode } from \"@msgpack/msgpack\";\n\nconst encoded: Uint8Array = encode({ foo: \"bar\" });\n\n// `buffer` refers the same ArrayBuffer as `encoded`.\nconst buffer: Buffer = Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength);\nconsole.log(buffer);\n```\n\n#### `EncodeOptions`\n\nName|Type|Default\n----|----|----\nextensionCodec | ExtensionCodec | `ExtensinCodec.defaultCodec`\nmaxDepth | number | `100`\ninitialBufferSize | number | `2048`\nsortKeys | boolean | false\nforceFloat32 | boolean | false\nforceIntegerToFloat | boolean | false\nignoreUndefined | boolean | false\ncontext | user-defined | -\n\n### `decode(buffer: ArrayLike<number> | ArrayBuffer, options?: DecodeOptions): unknown`\n\nIt decodes `buffer` encoded in MessagePack, and returns a decoded object as `uknown`.\n\n`buffer` must be an array of bytes, which is typically `Uint8Array`, or `ArrayBuffer`.\n\nfor example:\n\n```typescript\nimport { decode } from \"@msgpack/msgpack\";\n\nconst encoded: Uint8Array;\nconst object = decode(encoded);\nconsole.log(object);\n```\n\nNodeJS `Buffer` is also acceptable because it is a subclass of `Uint8Array`.\n\n#### `DecodeOptions`\n\nName|Type|Default\n----|----|----\nextensionCodec | ExtensionCodec | `ExtensinCodec.defaultCodec`\nmaxStrLength | number | `4_294_967_295` (UINT32_MAX)\nmaxBinLength | number | `4_294_967_295` (UINT32_MAX)\nmaxArrayLength | number | `4_294_967_295` (UINT32_MAX)\nmaxMapLength | number | `4_294_967_295` (UINT32_MAX)\nmaxExtLength | number | `4_294_967_295` (UINT32_MAX)\ncontext | user-defined | -\n\nYou can use `max${Type}Length` to limit the length of each type decoded.\n\n### `decodeAsync(stream: AsyncIterable<ArrayLike<number>> | ReadableStream<ArrayLike<number>>, options?: DecodeAsyncOptions): Promise<unknown>`\n\nIt decodes `stream` in an async iterable of byte arrays, and returns decoded object as `uknown` type, wrapped in `Promise`. This function works asyncronously.\n\n`DecodeAsyncOptions` is the same as `DecodeOptions` for `decode()`.\n\nThis function is designed to work with whatwg `fetch()` like this:\n\n```typescript\nimport { decodeAsync } from \"@msgpack/msgpack\";\n\nconst MSGPACK_TYPE = \"application/x-msgpack\";\n\nconst response = await fetch(url);\nconst contentType = response.headers.get(\"Content-Type\");\nif (contentType && contentType.startsWith(MSGPACK_TYPE) && response.body != null) {\n  const object = await decodeAsync(response.body);\n  // do something with object\n} else { /* handle errors */ }\n```\n\n### `decodeArrayStream(stream: AsyncIterable<ArrayLike<number>> | ReadableStream<ArrayLike<number>>, options?: DecodeAsyncOptions): AsyncIterable<unknown>`\n\nIt is alike to `decodeAsync()`, but only accepts an array of items as the input `stream`, and emits the decoded item one by one.\n\nIt throws errors when the input is not an array-family.\n\nfor example:\n\n```typescript\nimport { encode } from \"@msgpack/msgpack\";\n\nconst stream: AsyncIterator<Uint8Array>;\n\n// in an async function:\nfor await (const item of decodeArrayStream(stream)) {\n  console.log(item);\n}\n```\n\n\n### `decodeStream(stream: AsyncIterable<ArrayLike<number>> | ReadableStream<ArrayLike<number>>, options?: DecodeAsyncOptions): AsyncIterable<unknown>`\n\nIt is alike to `decodeAsync()` and `decodeArrayStream()`, but the input `stream` consists of independent MessagePack items.\n\nIn other words, it decodes an unlimited stream and emits an item one by one.\n\nfor example:\n\n```typescript\nimport { encode } from \"@msgpack/msgpack\";\n\nconst stream: AsyncIterator<Uint8Array>;\n\n// in an async function:\nfor await (const item of decodeStream(stream)) {\n  console.log(item);\n}\n```\n\n### Reusing Encoder and Decoder instances\n\n`Encoder` and `Decoder` classes is provided for better performance:\n\n```typescript\nimport { deepStrictEqual } from \"assert\";\nimport { Encoder, Decoder } from \"@msgpack/msgpack\";\n\nconst encoder = new Encoder();\nconst decoder = new Decoder();\n\nconst encoded: Uint8Array = encoder.encode(object);\ndeepStrictEqual(decoder.decode(encoded), object);\n```\n\nAccording to our benchmark, reusing `Encoder` instance is about 20% faster\nthan `encode()` function, and reusing `Decoder` instance is about 2% faster\nthan `decode()` function. Note that the result should vary in environments\nand data structure.\n\n## Extension Types\n\nTo handle [MessagePack Extension Types](https://github.com/msgpack/msgpack/blob/master/spec.md#extension-types), this library provides `ExtensionCodec` class.\n\nHere is an example to setup custom extension types that handles `Map` and `Set` classes in TypeScript:\n\n```typescript\nimport { encode, decode, ExtensionCodec } from \"@msgpack/msgpack\";\n\nconst extensionCodec = new ExtensionCodec();\n\n// Set<T>\nconst SET_EXT_TYPE = 0 // Any in 0-127\nextensionCodec.register({\n  type: SET_EXT_TYPE,\n  encode: (object: unknown): Uint8Array | null => {\n    if (object instanceof Set) {\n      return encode([...object]);\n    } else {\n      return null;\n    }\n  },\n  decode: (data: Uint8Array) => {\n    const array = decode(data) as Array<unknown>;\n    return new Set(array);\n  },\n});\n\n// Map<T>\nconst MAP_EXT_TYPE = 1; // Any in 0-127\nextensionCodec.register({\n  type: MAP_EXT_TYPE,\n  encode: (object: unknown): Uint8Array => {\n    if (object instanceof Map) {\n      return encode([...object]);\n    } else {\n      return null;\n    }\n  },\n  decode: (data: Uint8Array) => {\n    const array = decode(data) as Array<[unknown, unknown]>;\n    return new Map(array);\n  },\n});\n\n// and later\nimport { encode, decode } from \"@msgpack/msgpack\";\n\nconst encoded = = encode([new Set<any>(), new Map<any, any>()], { extensionCodec });\nconst decoded = decode(encoded, { extensionCodec });\n```\n\nNot that extension types for custom objects must be `[0, 127]`, while `[-1, -128]` is reserved for MessagePack itself.\n\n#### ExtensionCodec context\n\nWhen using an extension codec, it may be necessary to keep encoding/decoding state, to keep track of which objects got encoded/re-created. To do this, pass a `context` to the `EncodeOptions` and `DecodeOptions` (and if using typescript, type the `ExtensionCodec` too). Don't forget to pass the `{extensionCodec, context}` along recursive encoding/decoding:\n\n```typescript\nimport { encode, decode, ExtensionCodec } from \"@msgpack/msgpack\";\n\nclass MyContext {\n  track(object: any) { /*...*/ }\n}\n\nclass MyType { /* ... */ }\n\nconst extensionCodec = new ExtensionCodec<MyContext>();\n\n// MyType\nconst MYTYPE_EXT_TYPE = 0 // Any in 0-127\nextensionCodec.register({\n  type: MYTYPE_EXT_TYPE,\n  encode: (object, context) => {\n    if (object instanceof MyType) {\n      context.track(object); // <-- like this\n      return encode(object.toJSON(), { extensionCodec, context });\n    } else {\n      return null;\n    }\n  },\n  decode: (data, extType, context) => {\n    const decoded = decode(data, { extensionCodec, context });\n    const my = new MyType(decoded);\n    context.track(my); // <-- and like this\n    return my;\n  },\n});\n\n// and later\nimport { encode, decode } from \"@msgpack/msgpack\";\n\nconst context = new MyContext();\n\nconst encoded = = encode({myType: new MyType<any>()}, { extensionCodec, context });\nconst decoded = decode(encoded, { extensionCodec, context });\n```\n\n#### Handling BigInt with ExtensionCodec\n\nThis library does not handle BigInt by default, but you can handle it with `ExtensionCodec` like this:\n\n```typescript\nimport { deepStrictEqual } from \"assert\";\nimport { encode, decode, ExtensionCodec } from \"@msgpack/msgpack\";\n\nconst BIGINT_EXT_TYPE = 0; // Any in 0-127\nconst extensionCodec = new ExtensionCodec();\nextensionCodec.register({\n  type: BIGINT_EXT_TYPE,\n  encode: (input: unknown) => {\n    if (typeof input === \"bigint\") {\n      return encode(input.toString());\n    } else {\n      return null;\n    }\n  },\n  decode: (data: Uint8Array) => {\n    return BigInt(decode(data));\n  },\n});\n\nconst value = BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1);\nconst encoded: = encode(value, { extensionCodec });\ndeepStrictEqual(decode(encoded, { extensionCodec }), value);\n```\n\n#### The temporal module as timestamp extensions\n\nThere is a proposal for a new date/time representations in JavaScript:\n\n* https://github.com/tc39/proposal-temporal\n\nThis library maps `Date` to the MessagePack timestamp extension by default, but you can re-map the temporal module (or [Temporal Polyfill](https://github.com/tc39/proposal-temporal/tree/main/polyfill)) to the timestamp extension like this:\n\n```typescript\nimport { Instant } from \"@std-proposal/temporal\";\nimport { deepStrictEqual } from \"assert\";\nimport {\n  encode,\n  decode,\n  ExtensionCodec,\n  EXT_TIMESTAMP,\n  encodeTimeSpecToTimestamp,\n  decodeTimestampToTimeSpec,\n} from \"@msgpack/msgpack\";\n\nconst extensionCodec = new ExtensionCodec();\nextensionCodec.register({\n  type: EXT_TIMESTAMP, // override the default behavior!\n  encode: (input: any) => {\n    if (input instanceof Instant) {\n      const sec = input.seconds;\n      const nsec = Number(input.nanoseconds - BigInt(sec) * BigInt(1e9));\n      return encodeTimeSpecToTimestamp({ sec, nsec });\n    } else {\n      return null;\n    }\n  },\n  decode: (data: Uint8Array) => {\n    const timeSpec = decodeTimestampToTimeSpec(data);\n    const sec = BigInt(timeSpec.sec);\n    const nsec = BigInt(timeSpec.nsec);\n    return Instant.fromEpochNanoseconds(sec * BigInt(1e9) + nsec);\n  },\n});\n\nconst instant = Instant.fromEpochMilliseconds(Date.now());\nconst encoded = encode(instant, { extensionCodec });\nconst decoded = decode(encoded, { extensionCodec });\ndeepStrictEqual(decoded, instant);\n```\n\nThis will be default once the temporal module is standardizied, which is not a near-future, though.\n\n## Decoding a Blob\n\n[`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) is a binary data container provided by browsers. To read its contents, you can use `Blob#arrayBuffer()` or `Blob#stream()`. `Blob#stream()`\nis recommended if your target platform support it. This is because streaming\ndecode should be faster for large objects. In both ways, you need to use\nasynchronous API.\n\n```typescript\nasync function decodeFromBlob(blob: Blob): unknown {\n  if (blob.stream) {\n    // Blob#stream(): ReadableStream<Uint8Array> (recommended)\n    return await decodeAsync(blob.stream());\n  } else {\n    // Blob#arrayBuffer(): Promise<ArrayBuffer> (if stream() is not available)\n    return decode(await blob.arrayBuffer());\n  }\n}\n```\n\n## MessagePack Specification\n\nThis library is compatible with the \"August 2017\" revision of MessagePack specification at the point where timestamp ext was added:\n\n* [x] str/bin separation, added at August 2013\n* [x] extension types, added at August 2013\n* [x] timestamp ext type, added at August 2017\n\nThe livinng specification is here:\n\nhttps://github.com/msgpack/msgpack\n\nNote that as of June 2019 there're no official \"version\" on the MessagePack specification. See https://github.com/msgpack/msgpack/issues/195 for the discussions.\n\n### MessagePack Mapping Table\n\nThe following table shows how JavaScript values are mapped to [MessagePack formats](https://github.com/msgpack/msgpack/blob/master/spec.md) and vice versa.\n\nSource Value|MessagePack Format|Value Decoded\n----|----|----\nnull, undefined|nil|null (*1)\nboolean (true, false)|bool family|boolean (true, false)\nnumber (53-bit int)|int family|number (53-bit int)\nnumber (64-bit float)|float family|number (64-bit float)\nstring|str family|string\nArrayBufferView |bin family|Uint8Array (*2)\nArray|array family|Array\nObject|map family|Object (*3)\nDate|timestamp ext family|Date (*4)\n\n* *1 Both `null` and `undefined` are mapped to `nil` (`0xC0`) type, and are decoded into `null`\n* *2 Any `ArrayBufferView`s including NodeJS's `Buffer` are mapped to `bin` family, and are decoded into `Uint8Array`\n* *3 In handling `Object`, it is regarded as `Record<string, unknown>` in terms of TypeScript\n* *4 MessagePack timestamps may have nanoseconds, which will lost when it is decoded into JavaScript `Date`. This behavior can be overridden by registering `-1` for the extension codec.\n\n## Prerequsites\n\nThis is a universal JavaScript library that supports major browsers and NodeJS.\n\n### ECMA-262\n\n* ES5 language features\n* ES2018 standard library, including:\n  * Typed arrays (ES2015)\n  * Async iterations (ES2018)\n  * Features added in ES2015-ES2018\n\nES2018 standard library used in this library can be polyfilled with [core-js](https://github.com/zloirock/core-js).\n\nIf you support IE11, import `core-js` in your application entrypoints, as this library does in testing for browsers.\n\n### NodeJS\n\nNodeJS v10 is required, but NodeJS v12 or later is recommended because it includes the V8 feature of [Improving DataView performance in V8](https://v8.dev/blog/dataview).\n\nNodeJS before v10 will work by importing `@msgpack/msgpack/dist.es5/msgpack`.\n\n## Benchmark\n\nRun-time performance is not the only reason to use MessagePack, but it's important to choose MessagePack libraries, so a benchmark suite is provided to monitor the performance of this library.\n\nV8's built-in JSON has been improved for years, esp. `JSON.parse()` is [significantly improved in V8/7.6](https://v8.dev/blog/v8-release-76), it is the fastest deserializer as of 2019, as the benchmark result bellow suggests.\n\nHowever, MessagePack can handles binary data effectively, actual performance depends on situations. You'd better take benchmark on your own use-case if performance matters.\n\nBenchmark on NodeJS/v12.18.3 (V8/7.8)\n\noperation                                                         |   op   |   ms  |  op/s\n----------------------------------------------------------------- | ------: | ----: | ------:\nbuf = Buffer.from(JSON.stringify(obj));                           |  840700 |  5000 |  168140\nbuf = JSON.stringify(obj);                                        | 1249800 |  5000 |  249960\nobj = JSON.parse(buf);                                            | 1648000 |  5000 |  329600\nbuf = require(\"msgpack-lite\").encode(obj);                        |  603500 |  5000 |  120700\nobj = require(\"msgpack-lite\").decode(buf);                        |  315900 |  5000 |   63180\nbuf = require(\"@msgpack/msgpack\").encode(obj);                    |  945400 |  5000 |  189080\nobj = require(\"@msgpack/msgpack\").decode(buf);                    |  770200 |  5000 |  154040\nbuf = /* @msgpack/msgpack */ encoder.encode(obj);                 | 1162600 |  5000 |  232520\nobj = /* @msgpack/msgpack */ decoder.decode(buf);                 |  787800 |  5000 |  157560\n\nNote that `Buffer.from()` for `JSON.stringify()` is necessary to emulate I/O where a JavaScript string must be converted into a byte array encoded in UTF-8, whereas MessagePack's `encode()` returns a byte array.\n\n## Distribution\n\n### NPM / npmjs.com\n\nThe NPM package distributed in npmjs.com includes both ES2015+ and ES5 files:\n\n* `dist/` is compiled into ES2015+\n* `dist.es5/` is compiled into ES5 and bundled to singile file\n  * `dist.es5/msgpack.min.js` - the default, minified file (UMD)\n  * `dist.es5/msgpack.js` - an optional, non-minified file (UMD)\n\nIf you use NodeJS and/or webpack, their module resolvers use the suitable one automatically.\n\n### CDN / unpkg.com\n\nThis library is availble via CDN:\n\n```html\n<script crossorigin src=\"https://unpkg.com/@msgpack/msgpack\"></script>\n```\n\nIt loads `MessagePack` module to the global object.\n\n## Maintenance\n\n### Testing\n\nFor simple testing:\n\n```\nnpm run test\n```\n\n### Continuous Integration\n\nThis library uses Travis CI.\n\ntest matrix:\n\n* TypeScript targets\n  * `target=es2019` / `target=es5`\n* JavaScript engines\n  * NodeJS, borwsers (Chrome, Firefox, Safari, IE11, and so on)\n\nSee [test:* in package.json](./package.json) and [.travis.yml](./.travis.yml) for details.\n\n### Release Engineering\n\n```console\n# run tests on NodeJS, Chrome, and Firefox\nmake test-all\n\n# edit the changelog\ncode CHANGELOG.md\n\n# bump version\nnpm version patch|minor|major\n\n# run the publishing task\nmake publish\n```\n\n### Updating Dependencies\n\n```console\nnpm run update-dependencies\n```\n\n## Big Thanks\n\nCross-browser Testing Platform and Open Source <3 Provided by Sauce Labs.\n\n<a href=\"https://saucelabs.com\"><img src=\"./assets/SauceLabs.svg\" alt=\"Sauce Labs\" width=\"280\"></a>\n\n## License\n\nCopyright 2019 The MessagePack community.\n\nThis software uses the ISC license:\n\nhttps://opensource.org/licenses/ISC\n\nSee [LICENSE](./LICENSE) for details.\n","readmeFilename":"README.md"}