Global

Type Definitions

BufferLike

Description:
  • Things that can act as inputs, from which a NoFilter can be created.
Source:
Things that can act as inputs, from which a NoFilter can be created.
Type:
  • string | Buffer | ArrayBuffer | ArrayBufferView | DataView | stream.Readable

CommentOptions

Source:
Properties:
Name Type Attributes Default Description
max_depth number <optional>
10 How many times to indent the dashes.
depth number <optional>
1 Initial indentation depth.
no_summary boolean <optional>
false If true, omit the summary of the full bytes read at the end.
tags object <optional>
Mapping from tag number to function(v), where v is the decoded value that comes after the tag, and where the function returns the correctly-created value for that tag.
preferWeb boolean <optional>
false If true, prefer Uint8Arrays to be generated instead of node Buffers. This might turn on some more changes in the future, so forward-compatibility is not guaranteed yet.
encoding BufferEncoding <optional>
'hex' Encoding to use for input, if it is a string.

DecoderOptions

Source:
Properties:
Name Type Attributes Default Description
max_depth number <optional>
-1 The maximum depth to parse. Use -1 for "until you run out of memory". Set this to a finite positive number for un-trusted inputs. Most standard inputs won't nest more than 100 or so levels; I've tested into the millions before running out of memory.
tags Tagged.TagMap <optional>
Mapping from tag number to function(v), where v is the decoded value that comes after the tag, and where the function returns the correctly-created value for that tag.
preferMap boolean <optional>
false If true, prefer to generate Map instances to plain objects, even if there are no entries in the map or if all of the keys are strings.
preferWeb boolean <optional>
false If true, prefer Uint8Arrays to be generated instead of node Buffers. This might turn on some more changes in the future, so forward-compatibility is not guaranteed yet.
encoding BufferEncoding <optional>
'hex' The encoding of the input. Ignored if input is a Buffer.
required boolean <optional>
false Should an error be thrown when no data is in the input?
extendedResults boolean <optional>
false If true, emit extended results, which will be an object with shape ExtendedResults. The value will already have been null-checked.
preventDuplicateKeys boolean <optional>
false If true, error is thrown if a map has duplicate keys.

DiagnoseOptions

Source:
Properties:
Name Type Attributes Default Description
separator string <optional>
'\n' Output between detected objects.
stream_errors boolean <optional>
false Put error info into the output stream.
max_depth number <optional>
-1 The maximum depth to parse. Use -1 for "until you run out of memory". Set this to a finite positive number for un-trusted inputs. Most standard inputs won't nest more than 100 or so levels; I've tested into the millions before running out of memory.
tags object <optional>
Mapping from tag number to function(v), where v is the decoded value that comes after the tag, and where the function returns the correctly-created value for that tag.
preferWeb boolean <optional>
false If true, prefer Uint8Arrays to be generated instead of node Buffers. This might turn on some more changes in the future, so forward-compatibility is not guaranteed yet.
encoding BufferEncoding <optional>
'hex' The encoding of input, ignored if input is not string.

EncodeFunction(enc, val) → {boolean}

Description:
  • Generate the CBOR for a value. If you are using this, you'll either need to call Encoder.write with a Buffer, or look into the internals of Encoder to reuse existing non-documented behavior.
Source:
Parameters:
Name Type Description
enc Encoder The encoder to use.
val any The value to encode.
Returns:
True on success.
Type
boolean

EncodingOptions

Source:
Properties:
Name Type Attributes Default Description
genTypes Array.<any> | object <optional>
[] Array of pairs of `type`, `function(Encoder)` for semantic types to be encoded. Not needed for Array, Date, Buffer, Map, RegExp, Set, or URL. If an object, the keys are the constructor names for the types.
canonical boolean <optional>
false Should the output be canonicalized.
detectLoops boolean | WeakSet <optional>
false Should object loops be detected? This will currently add memory to track every part of the object being encoded in a WeakSet. Do not encode the same object twice on the same encoder, without calling `removeLoopDetectors` in between, which will clear the WeakSet. You may pass in your own WeakSet to be used; this is useful in some recursive scenarios.
dateType "number" | "float" | "int" | "string" <optional>
"number" how should dates be encoded? "number" means float or int, if no fractional seconds.
encodeUndefined any <optional>
How should an "undefined" in the input be encoded. By default, just encode a CBOR undefined. If this is a buffer, use those bytes without re-encoding them. If this is a function, the function will be called (which is a good time to throw an exception, if that's what you want), and the return value will be used according to these rules. Anything else will be encoded as CBOR.
disallowUndefinedKeys boolean <optional>
false Should "undefined" be disallowed as a key in a Map that is serialized? If this is true, encode(new Map([[undefined, 1]])) will throw an exception. Note that it is impossible to get a key of undefined in a normal JS object.
collapseBigIntegers boolean <optional>
false Should integers that come in as ECMAscript bigint's be encoded as normal CBOR integers if they fit, discarding type information?
chunkSize number <optional>
4096 Number of characters or bytes for each chunk, if obj is a string or Buffer, when indefinite encoding.
omitUndefinedProperties boolean <optional>
false When encoding objects or Maps, do not include a key if its corresponding value is `undefined`.

ExtendedResults

Source:
Properties:
Name Type Attributes Description
value any The value that was found.
length number The number of bytes of the original input that were read.
bytes Buffer The bytes of the original input that were used to produce the value.
unused Buffer <optional>
The bytes that were left over from the original input. This property only exists if Decoder.decodeFirst or Decoder.decodeFirstSync was called.

ObjectOptions

Source:
Properties:
Name Type Attributes Default Description
indefinite boolean <optional>
false Force indefinite encoding for this object.
skipTypes boolean <optional>
false Do not use available type mappings for this object, but encode it as a "normal" JS object would be.

SemanticMap

Description:
  • A mapping from tag number to a tag decoding function.
Source:
A mapping from tag number to a tag decoding function.
Type:

TagFunction(value, tag) → {any}

Description:
  • Convert a tagged value to a more interesting JavaScript type. Errors thrown in this function will be captured into the "err" property of the original Tagged instance.
Source:
Parameters:
Name Type Description
value any The value inside the tag.
tag Tagged The enclosing Tagged instance; useful if you want to modify it and return it. Also available as "this".
Returns:
The transformed value.
Type
any

TagMap

Description:
  • A mapping from tag number to a tag decoding function.
Source:
A mapping from tag number to a tag decoding function.
Type:

commentCallback(erroropt, commentedopt) → {void}

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
If one was generated.
commented string <optional>
The comment string.
Returns:
Type
void

decodeAllCallback(error, value)

Source:
Parameters:
Name Type Description
error Error If one was generated.
value Array.<ExtendedResults> | Array.<any> All of the decoded values, wrapped in an Array.

decodeCallback(erroropt, valueopt) → {void}

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
If one was generated.
value any <optional>
The decoded value.
Returns:
Type
void

diagnoseCallback(erroropt, valueopt) → {void}

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
If one was generated.
value string <optional>
The diagnostic value.
Returns:
Type
void