Skip to content

Commit

Permalink
Add documentation for writeFunction, #134
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed May 11, 2024
1 parent 943ed70 commit 0cb465d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ The following options properties can be provided to the Packr or Unpackr constru
* `encodeUndefinedAsNil` - Encodes a value of `undefined` as a MessagePack `nil`, the same as a `null`.
* `int64AsType` - This will decode uint64 and int64 numbers as the specified type. The type can be `bigint` (default), `number`, `string`, or `auto` (where range [-2^53...2^53] is represented by number and everything else by a bigint).
* `onInvalidDate` - This can be provided as function that will be called when an invalid date is provided. The function can throw an error, or return a value that will be encoded in place of the invalid date. If not provided, an invalid date will be encoded as an invalid timestamp (which decodes with msgpackr back to an invalid date).
* `writeFunction` - This can be provided as function that will be called when a function is encountered. The function can throw an error, or return a value that will be encoded in place of the function. If not provided, a function will be encoded as undefined (similar to `JSON.stringify`).
* `mapAsEmptyObject` - Encodes JS `Map`s as empty objects (for back-compat with older libraries).
* `setAsEmptyObject` - Encodes JS `Set`s as empty objects (for back-compat with older libraries).

Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Options {
maxOwnStructures?: number
mapAsEmptyObject?: boolean
setAsEmptyObject?: boolean
writeFunction?: () => any
/** @deprecated use int64AsType: 'number' */
int64AsNumber?: boolean
int64AsType?: 'bigint' | 'number' | 'string'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "msgpackr",
"author": "Kris Zyp",
"version": "1.10.1",
"version": "1.10.2",
"description": "Ultra-fast MessagePack implementation with extensions for records and structured cloning",
"license": "MIT",
"types": "./index.d.ts",
Expand Down

0 comments on commit 0cb465d

Please sign in to comment.