cbor2
    Preparing search index...

    Interface EncodeOptions

    interface EncodeOptions {
        avoidInts?: boolean;
        cde?: boolean;
        chunkSize?: number;
        collapseBigInts?: boolean;
        dateTag?: number;
        dcbor?: boolean;
        float64?: boolean;
        flushToZero?: boolean;
        forceEndian?: boolean | null;
        ignoreGlobalTags?: boolean;
        ignoreOriginalEncoding?: boolean;
        largeNegativeAsBigInt?: boolean;
        reduceUnsafeNumbers?: boolean;
        rejectBigInts?: boolean;
        rejectCustomSimples?: boolean;
        rejectDuplicateKeys?: boolean;
        rejectFloats?: boolean;
        rejectUndefined?: boolean;
        simplifyNegativeZero?: boolean;
        sortKeys?: KeySorter | null;
        stringNormalization?: StringNormalization | null;
        types?: TypeEncoderMap | null;
        wtf8?: boolean;
    }

    Hierarchy (View Summary)

    Index

    Properties

    avoidInts?: boolean

    Encode all integers as floating point numbers of the correct size.

    false
    
    cde?: boolean

    Turn on options for draft-ietf-cbor-cde-05.

    chunkSize?: number
    collapseBigInts?: boolean

    Should bigints that can fit into normal integers be collapsed into normal integers?

    true
    
    dateTag?: number

    Which tag to use to encode Date objects?

    1
    
    dcbor?: boolean

    Turn on options for draft-mcnally-deterministic-cbor-11.

    float64?: boolean

    When writing floats, always use the 64-bit version. Often combined with avoidInts.

    false
    
    flushToZero?: boolean

    When writing floats, first flush any subnormal numbers to zero before deciding on encoding.

    forceEndian?: boolean | null

    How to write TypedArrays? Null to use the current platform's endian-ness. True to always use little-endian. False to always use big-endian.

    null
    
    ignoreGlobalTags?: boolean

    Do not consider the global tag registry when encoding tags.

    ignoreOriginalEncoding?: boolean

    Ignore sizes on boxed numbers; they might be overly-large.

    false
    
    largeNegativeAsBigInt?: boolean

    Do not encode numbers in the range [CBOR_NEGATIVE_INT_MAX ... STANDARD_NEGATIVE_INT_MAX - 1] as MT 1.

    false
    
    reduceUnsafeNumbers?: boolean

    From dcbor docs:

    "MUST check whether floating point values to be encoded have the numerically equal value in DCBOR_INT = [-2^63, 2^64-1]. If that is the case, it MUST be converted to that numerically equal integer value before encoding it. (Preferred encoding will then ensure the shortest length encoding is used.) If a floating point value has a non-zero fractional part, or an exponent that takes it out of DCBOR_INT, the original floating point value is used for encoding. (Specifically, conversion to a CBOR bignum is never considered)".

    This should only apply to "integers" that are outside the JS safe range of [-(2^53 - 1), 2^53-1].

    rejectBigInts?: boolean

    Do not encode bigints that cannot be reduced to integers.

    false
    
    rejectCustomSimples?: boolean

    Throw an error when an instance of Simple is encoded.

    false
    
    rejectDuplicateKeys?: boolean

    Check that Maps do not contain keys that encode to the same bytes as one another. This is possible in a Map with object keys.

    false
    
    rejectFloats?: boolean

    Do not encode floating point numbers that cannot be reduced to integers.

    false
    
    rejectUndefined?: boolean

    Error instead of encoding undefined.

    false
    
    simplifyNegativeZero?: boolean

    Encode -0 as 0.

    false
    
    sortKeys?: KeySorter | null

    How should the key/value pairs be sorted before an object or Map gets encoded? If null, no sorting is performed. Modern protocols use coreDeterministic, older ones use lengthFirstDeterministic.

    null
    
    stringNormalization?: StringNormalization | null

    Normalize strings on encoding.

    'NFD' may optimize for CPU, 'NFC' may or may not optimize for size. Don't use this unless your protocl calls for it, or if you have Unicode expertise. In particular, the 'K' forms are really unlikely to be useful.

    undefined
    
    types?: TypeEncoderMap | null

    Override how these types are encoded for this call to encode.

    wtf8?: boolean

    Allow non-wellformed strings (strings containing unpaired surrogates) to be encoded as tag 273.

    This is optional since a) most protocol use cases should use strict UTF8 and b) this adds a check for well-formedness that is potentially-slow for large strings. You may want this if you are storing test inputs or outputs and want to ensure that you have the full range of JS strings as possibilities. Note: I doubt that tag 273 is widely-implemented at this time, so this is another reason you should not use this if you are trying to interoperate.