Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @stablelib/cbor

Index

Type aliases

DecoderOptions: { ignoreExtraData?: boolean; noCopy?: boolean; strictMapKeys?: boolean; taggedDecoders?: TaggedDecoder<any>[]; uniqueMapKeys?: boolean }

Specifies options for decoder.

Type declaration

  • Optional ignoreExtraData?: boolean

    If true, ignore extra data at the end of the source buffer. Otherwise, decoder throws an error if extra data is detected.

    To get the number of extra bytes left, use undecodedLength.

    By default, false.

  • Optional noCopy?: boolean

    If true, instead of copying byte arrays return subarrays into CBOR buffer.

    By default, false.

  • Optional strictMapKeys?: boolean

    If true, allow only string and number keys for maps. Throw if encountered any other type.

    By default, false.

  • Optional taggedDecoders?: TaggedDecoder<any>[]

    Tagged object decoders.

    By default, DEFAULT_TAGGED_DECODERS, which converts tagged Tags.DateString and Tags.DateNumber to Date and Tags.RegExp to RegExp objects.

    Pass empty array to disable tagged decoders.

  • Optional uniqueMapKeys?: boolean

    If true, map keys must be unique (after conversion to string). Throw if encountered duplicate keys.

    By default, false.

EncoderOptions: { intKeys?: boolean; taggedEncoders?: TaggedEncoder<any>[] }

Specifies options for encoder.

Type declaration

  • Optional intKeys?: boolean

    In JavaScript, object keys are strings, so by default CBOR encoding will produce string keys for maps.

    Setting intKeys to true will make encoder first try to convert each object key to integer and encode it as such if conversion succeeds. Keys that cannot be converted will be encoded as strings. Note that if object contains both integer and string keys, the map will be encoded as such.

    By default, false.

  • Optional taggedEncoders?: TaggedEncoder<any>[]

    Tagged object encoders.

    By default, DEFAULT_TAGGED_ENCODERS, which encodes Dates (as a string) and RegExps.

    Pass empty array to disable tagged encoders.

TaggedDecoder<T>: (tagged: Tagged) => T | undefined

Type parameters

  • T

Type declaration

    • (tagged: Tagged): T | undefined
    • Tagged value decoder.

      If it can decode a Tagged value (by checking its tag property), it must return this value, otherwise must return undefined.

      Parameters

      Returns T | undefined

TaggedEncoder<T>: (obj: T | object) => Tagged | undefined

Type parameters

  • T

Type declaration

    • (obj: T | object): Tagged | undefined
    • Tagged value encoder.

      If it can encode the object, it must return a Tagged instance, otherwise must return undefined.

      Parameters

      • obj: T | object

      Returns Tagged | undefined

Variables

DEFAULT_DECODER_OPTIONS: DecoderOptions = ...
DEFAULT_ENCODER_OPTIONS: EncoderOptions = ...
DEFAULT_TAGGED_DECODERS: TaggedDecoder<any>[] = ...

Default tagged values decoders.

DEFAULT_TAGGED_ENCODERS: TaggedEncoder<any>[] = ...

Default tagged values encoders.

Functions

  • DateNumberDecoder(tagged: Tagged): undefined | Date
  • DateNumberEncoder(obj: object | Date): undefined | Tagged
  • DateStringDecoder(tagged: Tagged): undefined | Date
  • DateStringEncoder(obj: object | Date): undefined | Tagged
  • RegExpDecoder(tagged: Tagged): undefined | RegExp
  • RegExpEncoder(obj: object | RegExp): undefined | Tagged
  • decode(src: Uint8Array, options?: DecoderOptions): any | null | undefined
  • Decodes src from CBOR.

    If noCopy is true, the returned Uint8Arrays will be a subarrays of src otherwise they will be newly allocated. It is not recommended to set it to true, due to the possibility of hard-to-detect bugs resulting from it and preventing chunks of memory from being garbage collected.

    If ignoreExtraData is true, decoder will not throw an error if there's undecoded data at the end of the source.

    Parameters

    Returns any | null | undefined

Generated using TypeDoc