🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

cborg

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cborg - npm Package Compare versions

Comparing version
4.5.8
to
5.0.0
+122
example-extended.js
/*
cborg/extended provides built-in support for extended JavaScript types.
Compare this to example-bytestrings.js which manually implements TypedArray support
in ~150 lines. With cborg/extended, it's just import and use.
The type support is similar to the browser's structured clone algorithm - Date, Map,
Set, RegExp, BigInt, Error, and all TypedArrays round-trip with full type fidelity.
*/
import { encode, decode } from 'cborg/extended'
// All these types "just work" - no configuration needed
const original = {
// Date with millisecond precision
timestamp: new Date('2024-01-15T12:30:45.123Z'),
// RegExp with flags
pattern: /hello\s+world/gi,
// Map with non-string keys (impossible in JSON)
lookup: new Map([
['string-key', 'string value'],
[42, 'number key'],
[true, 'boolean key']
]),
// Set (not just array)
uniqueIds: new Set([1, 2, 3, 2, 1]), // duplicates removed
// BigInt (JSON throws on these)
bigNumber: 9007199254740993n, // beyond Number.MAX_SAFE_INTEGER
// Error types preserve their class and message
error: new TypeError('something went wrong'),
// TypedArrays preserve their exact type
floats: new Float32Array([1.5, 2.5, 3.5]),
integers: new Int16Array([-32768, 0, 32767]),
bigInts: new BigUint64Array([0n, 18446744073709551615n]),
// Negative zero is preserved (JSON and base cborg lose the sign)
negativeZero: -0
}
console.log('Original:')
console.log(original)
console.log()
// Encode to CBOR bytes
const encoded = encode(original)
console.log('Encoded size:', encoded.length, 'bytes')
console.log()
// Decode back - all types preserved
// By default, plain objects stay as plain objects (useMaps: false)
const decoded = decode(encoded)
console.log('Decoded:')
console.log(decoded)
console.log()
// Verify types are preserved
console.log('Type checks:')
console.log(' timestamp is Date:', decoded.timestamp instanceof Date)
console.log(' pattern is RegExp:', decoded.pattern instanceof RegExp)
console.log(' lookup is Map:', decoded.lookup instanceof Map)
console.log(' uniqueIds is Set:', decoded.uniqueIds instanceof Set)
console.log(' bigNumber is bigint:', typeof decoded.bigNumber === 'bigint')
console.log(' error is TypeError:', decoded.error instanceof TypeError)
console.log(' floats is Float32Array:', decoded.floats instanceof Float32Array)
console.log(' integers is Int16Array:', decoded.integers instanceof Int16Array)
console.log(' bigInts is BigUint64Array:', decoded.bigInts instanceof BigUint64Array)
console.log(' negativeZero is -0:', Object.is(decoded.negativeZero, -0))
console.log()
// Maps with non-string keys work correctly
console.log('Map key types preserved:')
console.log(' lookup.get(42):', decoded.lookup.get(42))
console.log(' lookup.get(true):', decoded.lookup.get(true))
/* Expected output:
Original:
{
timestamp: 2024-01-15T12:30:45.123Z,
pattern: /hello\s+world/gi,
lookup: Map(3) { 'string-key' => 'string value', 42 => 'number key', true => 'boolean key' },
uniqueIds: Set(3) { 1, 2, 3 },
bigNumber: 9007199254740993n,
error: TypeError: something went wrong,
floats: Float32Array(3) [ 1.5, 2.5, 3.5 ],
integers: Int16Array(3) [ -32768, 0, 32767 ],
bigInts: BigUint64Array(2) [ 0n, 18446744073709551615n ],
negativeZero: -0
}
Encoded size: ~230 bytes
Decoded:
{
timestamp: 2024-01-15T12:30:45.123Z,
pattern: /hello\s+world/gi,
lookup: Map(3) { 'string-key' => 'string value', 42 => 'number key', true => 'boolean key' },
...
}
Type checks:
timestamp is Date: true
pattern is RegExp: true
lookup is Map: true
uniqueIds is Set: true
bigNumber is bigint: true
error is TypeError: true
floats is Float32Array: true
integers is Int16Array: true
bigInts is BigUint64Array: true
negativeZero is -0: true
Map key types preserved:
lookup.get(42): number key
lookup.get(true): boolean key
*/
/**
* cborg/extended - Extended JavaScript type support for CBOR
*
* This module provides encode/decode functions that support extended JavaScript
* types: Date, RegExp, Map, Set, BigInt, and all TypedArray types.
*
* Similar to the browser's structured clone algorithm, this module prioritises
* JavaScript type preservation using standard CBOR tags. Unlike base cborg
* (designed for IPLD/content-addressed data), types round-trip with full fidelity.
*/
import { encode as _encode, decode as _decode } from '../../cborg.js'
import {
// BigInt
structBigIntEncoder,
bigIntDecoder,
bigNegIntDecoder,
// Date
dateEncoder,
dateDecoder,
// RegExp
regExpEncoder,
regExpDecoder,
// Set
setEncoder,
setDecoder,
// Map
mapEncoder,
mapDecoder,
// Error
errorEncoder,
errorDecoder,
// Negative zero
negativeZeroEncoder,
// TypedArrays
uint8ArrayEncoder,
uint8ArrayDecoder,
uint8ClampedArrayEncoder,
uint8ClampedArrayDecoder,
int8ArrayEncoder,
int8ArrayDecoder,
uint16ArrayEncoder,
uint16ArrayDecoder,
uint32ArrayEncoder,
uint32ArrayDecoder,
int16ArrayEncoder,
int16ArrayDecoder,
int32ArrayEncoder,
int32ArrayDecoder,
float32ArrayEncoder,
float32ArrayDecoder,
float64ArrayEncoder,
float64ArrayDecoder,
bigUint64ArrayEncoder,
bigUint64ArrayDecoder,
bigInt64ArrayEncoder,
bigInt64ArrayDecoder,
// Tag constants
TAG_DATE_EPOCH,
TAG_BIGINT_POS,
TAG_BIGINT_NEG,
TAG_OBJECT_CLASS,
TAG_UINT8_ARRAY,
TAG_UINT8_CLAMPED_ARRAY,
TAG_INT8_ARRAY,
TAG_UINT16_ARRAY_LE,
TAG_UINT32_ARRAY_LE,
TAG_BIGUINT64_ARRAY_LE,
TAG_INT16_ARRAY_LE,
TAG_INT32_ARRAY_LE,
TAG_BIGINT64_ARRAY_LE,
TAG_FLOAT32_ARRAY_LE,
TAG_FLOAT64_ARRAY_LE,
TAG_SET,
TAG_MAP,
TAG_REGEXP
} from '../taglib.js'
/**
* @typedef {import('../../interface.js').EncodeOptions} EncodeOptions
* @typedef {import('../../interface.js').DecodeOptions} DecodeOptions
*/
/**
* Type encoders for all supported types
*/
const typeEncoders = {
number: negativeZeroEncoder,
bigint: structBigIntEncoder,
Date: dateEncoder,
RegExp: regExpEncoder,
Set: setEncoder,
Map: mapEncoder,
Error: errorEncoder,
EvalError: errorEncoder,
RangeError: errorEncoder,
ReferenceError: errorEncoder,
SyntaxError: errorEncoder,
TypeError: errorEncoder,
URIError: errorEncoder,
Uint8Array: uint8ArrayEncoder,
Uint8ClampedArray: uint8ClampedArrayEncoder,
Int8Array: int8ArrayEncoder,
Uint16Array: uint16ArrayEncoder,
Uint32Array: uint32ArrayEncoder,
Int16Array: int16ArrayEncoder,
Int32Array: int32ArrayEncoder,
Float32Array: float32ArrayEncoder,
Float64Array: float64ArrayEncoder,
BigUint64Array: bigUint64ArrayEncoder,
BigInt64Array: bigInt64ArrayEncoder
}
/**
* Tag decoders for all supported tags
*/
const tags = {
[TAG_DATE_EPOCH]: dateDecoder,
[TAG_BIGINT_POS]: bigIntDecoder,
[TAG_BIGINT_NEG]: bigNegIntDecoder,
[TAG_OBJECT_CLASS]: errorDecoder,
[TAG_REGEXP]: regExpDecoder,
[TAG_SET]: setDecoder,
[TAG_MAP]: mapDecoder,
[TAG_UINT8_ARRAY]: uint8ArrayDecoder,
[TAG_UINT8_CLAMPED_ARRAY]: uint8ClampedArrayDecoder,
[TAG_INT8_ARRAY]: int8ArrayDecoder,
[TAG_UINT16_ARRAY_LE]: uint16ArrayDecoder,
[TAG_UINT32_ARRAY_LE]: uint32ArrayDecoder,
[TAG_INT16_ARRAY_LE]: int16ArrayDecoder,
[TAG_INT32_ARRAY_LE]: int32ArrayDecoder,
[TAG_FLOAT32_ARRAY_LE]: float32ArrayDecoder,
[TAG_FLOAT64_ARRAY_LE]: float64ArrayDecoder,
[TAG_BIGUINT64_ARRAY_LE]: bigUint64ArrayDecoder,
[TAG_BIGINT64_ARRAY_LE]: bigInt64ArrayDecoder
}
/**
* Encode a value to CBOR with extended JavaScript type support.
*
* Supported types beyond standard cborg:
* - Date (Tag 1)
* - RegExp (Tag 21066)
* - Map (Tag 259)
* - Set (Tag 258)
* - BigInt (Tags 2/3, always tagged)
* - All TypedArrays (Tags 64-87)
*
* @param {any} obj - Value to encode
* @param {EncodeOptions} [options] - Additional options (merged with extended defaults)
* @returns {Uint8Array}
*/
export function encode (obj, options = {}) {
return _encode(obj, {
mapSorter: undefined, // Preserve insertion order for type fidelity (like structured clone)
...options,
typeEncoders: { ...typeEncoders, ...options.typeEncoders }
})
}
/**
* Decode CBOR to a value with extended JavaScript type support.
*
* @param {Uint8Array} data - CBOR data to decode
* @param {DecodeOptions} [options] - Additional options (merged with extended defaults)
* @returns {any}
*/
export function decode (data, options = {}) {
return _decode(data, {
...options,
tags: { ...tags, ...options.tags }
// useMaps defaults to false: plain objects decode as objects, Tag 259 Maps decode as Maps.
// The mapDecoder uses decode.entries() to preserve key types regardless of useMaps setting.
})
}
// Re-export all taglib components for users who want to customize
export {
// Tag constants
TAG_DATE_EPOCH,
TAG_BIGINT_POS,
TAG_BIGINT_NEG,
TAG_UINT8_ARRAY,
TAG_UINT8_CLAMPED_ARRAY,
TAG_INT8_ARRAY,
TAG_UINT16_ARRAY_LE,
TAG_UINT32_ARRAY_LE,
TAG_BIGUINT64_ARRAY_LE,
TAG_INT16_ARRAY_LE,
TAG_INT32_ARRAY_LE,
TAG_BIGINT64_ARRAY_LE,
TAG_FLOAT32_ARRAY_LE,
TAG_FLOAT64_ARRAY_LE,
TAG_SET,
TAG_MAP,
TAG_REGEXP,
// BigInt
structBigIntEncoder,
bigIntDecoder,
bigNegIntDecoder,
// Date
dateEncoder,
dateDecoder,
// RegExp
regExpEncoder,
regExpDecoder,
// Set
setEncoder,
setDecoder,
// Map
mapEncoder,
mapDecoder,
// TypedArrays
uint8ArrayEncoder,
uint8ArrayDecoder,
uint8ClampedArrayEncoder,
uint8ClampedArrayDecoder,
int8ArrayEncoder,
int8ArrayDecoder,
uint16ArrayEncoder,
uint16ArrayDecoder,
uint32ArrayEncoder,
uint32ArrayDecoder,
int16ArrayEncoder,
int16ArrayDecoder,
int32ArrayEncoder,
int32ArrayDecoder,
float32ArrayEncoder,
float32ArrayDecoder,
float64ArrayEncoder,
float64ArrayDecoder,
bigUint64ArrayEncoder,
bigUint64ArrayDecoder,
bigInt64ArrayEncoder,
bigInt64ArrayDecoder
}
import { Token, Type } from '../cborg.js'
import { objectToTokens, Ref } from './encode.js'
/*
A collection of standard CBOR tags for extended JavaScript type support.
There are no tags included by default in the cborg encoder or decoder, you have
to include them by passing options. `typeEncoders` for encode() and `tags` for
decode().
The encoders here can be included with these options (see the tests for how this
can be done), or as examples for writing additional tags.
For convenience, cborg/extended provides a pre-configured encode/decode that
includes all of these, with type support similar to the browser's structured
clone algorithm.
*/
// =============================================================================
// Tag Constants
// =============================================================================
// Standard Tags (RFC 8949)
export const TAG_DATE_STRING = 0 // RFC 3339 date/time string
export const TAG_DATE_EPOCH = 1 // Epoch-based date/time (integer or float)
export const TAG_BIGINT_POS = 2 // Unsigned bignum
export const TAG_BIGINT_NEG = 3 // Negative bignum
// TypedArray Tags (RFC 8746) - Single-byte arrays (no endianness)
export const TAG_UINT8_ARRAY = 64
export const TAG_UINT8_CLAMPED_ARRAY = 68
export const TAG_INT8_ARRAY = 72
// TypedArray Tags (RFC 8746) - Little-endian multi-byte arrays
export const TAG_UINT16_ARRAY_LE = 69
export const TAG_UINT32_ARRAY_LE = 70
export const TAG_BIGUINT64_ARRAY_LE = 71
export const TAG_INT16_ARRAY_LE = 77
export const TAG_INT32_ARRAY_LE = 78
export const TAG_BIGINT64_ARRAY_LE = 79
export const TAG_FLOAT32_ARRAY_LE = 85
export const TAG_FLOAT64_ARRAY_LE = 86
// Generic Object Tag (IANA Registry)
export const TAG_OBJECT_CLASS = 27 // Serialised object with class name and constructor arguments
// Extended Tags (IANA Registry)
export const TAG_SET = 258 // Mathematical finite set
export const TAG_MAP = 259 // Map datatype
export const TAG_REGEXP = 21066 // ECMAScript RegExp
// =============================================================================
// BigInt (Tags 2/3) - RFC 8949 Section 3.4.3
// =============================================================================
const neg1b = BigInt(-1)
const pos1b = BigInt(1)
const zerob = BigInt(0)
const eightb = BigInt(8)
/**
* Decode a positive bignum from bytes (Tag 2)
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {bigint}
*/
export function bigIntDecoder (decode) {
const bytes = /** @type {Uint8Array} */ (decode())
let bi = zerob
for (let ii = 0; ii < bytes.length; ii++) {
bi = (bi << eightb) + BigInt(bytes[ii])
}
return bi
}
/**
* Convert a BigInt to bytes
* @param {bigint} bi
* @returns {Uint8Array}
*/
const ffb = BigInt(0xff)
/**
* @param {bigint} bi
*/
function fromBigInt (bi) {
const buf = []
while (bi > 0) {
// Use BigInt operations to avoid Number precision loss
buf.unshift(Number(bi & ffb))
bi >>= eightb
}
return Uint8Array.from(buf.length ? buf : [0])
}
// For IPLD compatibility: only tag BigInts outside 64-bit range
const maxSafeBigInt = BigInt('18446744073709551615') // 2^64 - 1
const minSafeBigInt = BigInt('-18446744073709551616') // -2^64
/**
* Encode a BigInt, only using tags for values outside 64-bit range (IPLD compatible)
* @param {bigint} obj
* @returns {Token[]|null}
*/
export function bigIntEncoder (obj) {
if (obj >= minSafeBigInt && obj <= maxSafeBigInt) {
return null // null = encode as native CBOR integer
}
return [
new Token(Type.tag, obj >= zerob ? TAG_BIGINT_POS : TAG_BIGINT_NEG),
new Token(Type.bytes, fromBigInt(obj >= zerob ? obj : obj * neg1b - pos1b))
]
}
/**
* Encode a BigInt, always using tags 2/3 (for extended mode, full round-trip fidelity)
* @param {bigint} obj
* @returns {Token[]}
*/
export function structBigIntEncoder (obj) {
return [
new Token(Type.tag, obj >= zerob ? TAG_BIGINT_POS : TAG_BIGINT_NEG),
new Token(Type.bytes, fromBigInt(obj >= zerob ? obj : obj * neg1b - pos1b))
]
}
/**
* Decode a negative bignum from bytes (Tag 3)
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {bigint}
*/
export function bigNegIntDecoder (decode) {
const bytes = /** @type {Uint8Array} */ (decode())
let bi = zerob
for (let ii = 0; ii < bytes.length; ii++) {
bi = (bi << eightb) + BigInt(bytes[ii])
}
return neg1b - bi
}
// =============================================================================
// Date (Tag 1) - RFC 8949 Section 3.4.2
// =============================================================================
/**
* Encode a Date as Tag 1 (epoch seconds as float)
* @param {Date} date
* @returns {Token[]}
*/
export function dateEncoder (date) {
// Use float for millisecond precision
const seconds = date.getTime() / 1000
return [
new Token(Type.tag, TAG_DATE_EPOCH),
new Token(Type.float, seconds)
]
}
/**
* Decode Tag 1 (epoch seconds) to a Date
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Date}
*/
export function dateDecoder (decode) {
const seconds = /** @type {number} */ (decode())
return new Date(seconds * 1000)
}
// =============================================================================
// RegExp (Tag 21066) - IANA Registry
// =============================================================================
/**
* Encode a RegExp as Tag 21066
* @param {RegExp} re
* @returns {Token[]}
*/
export function regExpEncoder (re) {
if (re.flags) {
return [
new Token(Type.tag, TAG_REGEXP),
new Token(Type.array, 2),
new Token(Type.string, re.source),
new Token(Type.string, re.flags)
]
}
return [
new Token(Type.tag, TAG_REGEXP),
new Token(Type.array, 1),
new Token(Type.string, re.source)
]
}
/**
* Decode Tag 21066 to a RegExp
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {RegExp}
*/
export function regExpDecoder (decode) {
const val = /** @type {string[]|string} */ (decode())
if (Array.isArray(val)) {
return new RegExp(val[0], val[1] || '')
}
return new RegExp(val)
}
// =============================================================================
// Set (Tag 258) - IANA Registry
// =============================================================================
/**
* Encode a Set as Tag 258 + array
* This is a typeEncoder, receives (obj, typ, options, refStack)
* @param {Set<any>} set
* @param {string} _typ
* @param {import('../interface.js').EncodeOptions} options
* @param {import('../interface.js').Reference} [refStack]
* @returns {import('../interface.js').TokenOrNestedTokens[]}
*/
export function setEncoder (set, _typ, options, refStack) {
if (set.size === 0) {
return [
new Token(Type.tag, TAG_SET),
new Token(Type.array, 0)
]
}
refStack = Ref.createCheck(refStack, set)
const values = []
for (const v of set) {
values.push(objectToTokens(v, options, refStack))
}
return [
new Token(Type.tag, TAG_SET),
new Token(Type.array, set.size),
values
]
}
/**
* Decode Tag 258 to a Set
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Set<any>}
*/
export function setDecoder (decode) {
const val = /** @type {any[]} */ (decode())
return new Set(val)
}
// =============================================================================
// Map (Tag 259) - IANA Registry
// Tag 259 wraps a CBOR map to indicate it should decode as a JS Map
// =============================================================================
/**
* Encode a Map as Tag 259 + CBOR map
* This is a typeEncoder, receives (obj, typ, options, refStack)
* @param {Map<any, any>} map
* @param {string} _typ
* @param {import('../interface.js').EncodeOptions} options
* @param {import('../interface.js').Reference} [refStack]
* @returns {import('../interface.js').TokenOrNestedTokens[]}
*/
export function mapEncoder (map, _typ, options, refStack) {
if (map.size === 0) {
return [
new Token(Type.tag, TAG_MAP),
new Token(Type.map, 0)
]
}
refStack = Ref.createCheck(refStack, map)
const entries = []
for (const [key, value] of map) {
entries.push([
objectToTokens(key, options, refStack),
objectToTokens(value, options, refStack)
])
}
// Sort entries if mapSorter is provided (for deterministic encoding)
if (options.mapSorter) {
entries.sort(options.mapSorter)
}
return [
new Token(Type.tag, TAG_MAP),
new Token(Type.map, map.size),
entries
]
}
/**
* Decode Tag 259 to a Map
* Uses decode.entries() to preserve key types (integers, etc.) regardless of useMaps setting
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Map<any, any>}
*/
export function mapDecoder (decode) {
return new Map(decode.entries())
}
// =============================================================================
// TypedArrays (Tags 64-87) - RFC 8746
// Uses little-endian tags for multi-byte arrays (JS native byte order)
// =============================================================================
/**
* Helper to create a TypedArray from an ArrayBuffer
* @template {ArrayBufferView} T
* @param {new (buffer: ArrayBuffer) => T} TypedArrayClass
* @returns {(decode: import('../interface.js').TagDecodeControl) => T}
*/
function createTypedArrayDecoder (TypedArrayClass) {
return function (decode) {
const bytes = /** @type {Uint8Array} */ (decode())
// bytes is a Uint8Array, need to get properly sliced ArrayBuffer
const buffer = /** @type {ArrayBuffer} */ (bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength))
return new TypedArrayClass(buffer)
}
}
/**
* Helper to create a TypedArray encoder
* @param {number} tag
* @returns {(arr: ArrayBufferView) => Token[]}
*/
function createTypedArrayEncoder (tag) {
return function (arr) {
// Get the bytes from the TypedArray's underlying buffer
const bytes = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength)
return [
new Token(Type.tag, tag),
new Token(Type.bytes, bytes)
]
}
}
// Uint8Array (Tag 64), no endianness concerns
export const uint8ArrayEncoder = createTypedArrayEncoder(TAG_UINT8_ARRAY)
export const uint8ArrayDecoder = createTypedArrayDecoder(Uint8Array)
// Uint8ClampedArray (Tag 68), no endianness concerns
export const uint8ClampedArrayEncoder = createTypedArrayEncoder(TAG_UINT8_CLAMPED_ARRAY)
export const uint8ClampedArrayDecoder = createTypedArrayDecoder(Uint8ClampedArray)
// Int8Array (Tag 72), no endianness concerns
export const int8ArrayEncoder = createTypedArrayEncoder(TAG_INT8_ARRAY)
export const int8ArrayDecoder = createTypedArrayDecoder(Int8Array)
// Uint16Array (Tag 69, little endian)
export const uint16ArrayEncoder = createTypedArrayEncoder(TAG_UINT16_ARRAY_LE)
export const uint16ArrayDecoder = createTypedArrayDecoder(Uint16Array)
// Uint32Array (Tag 70, little endian)
export const uint32ArrayEncoder = createTypedArrayEncoder(TAG_UINT32_ARRAY_LE)
export const uint32ArrayDecoder = createTypedArrayDecoder(Uint32Array)
// BigUint64Array (Tag 71, little endian)
export const bigUint64ArrayEncoder = createTypedArrayEncoder(TAG_BIGUINT64_ARRAY_LE)
export const bigUint64ArrayDecoder = createTypedArrayDecoder(BigUint64Array)
// Int16Array (Tag 77, little endian)
export const int16ArrayEncoder = createTypedArrayEncoder(TAG_INT16_ARRAY_LE)
export const int16ArrayDecoder = createTypedArrayDecoder(Int16Array)
// Int32Array (Tag 78, little endian)
export const int32ArrayEncoder = createTypedArrayEncoder(TAG_INT32_ARRAY_LE)
export const int32ArrayDecoder = createTypedArrayDecoder(Int32Array)
// BigInt64Array (Tag 79, little endian)
export const bigInt64ArrayEncoder = createTypedArrayEncoder(TAG_BIGINT64_ARRAY_LE)
export const bigInt64ArrayDecoder = createTypedArrayDecoder(BigInt64Array)
// Float32Array (Tag 85, little endian)
export const float32ArrayEncoder = createTypedArrayEncoder(TAG_FLOAT32_ARRAY_LE)
export const float32ArrayDecoder = createTypedArrayDecoder(Float32Array)
// Float64Array (Tag 86, little endian)
export const float64ArrayEncoder = createTypedArrayEncoder(TAG_FLOAT64_ARRAY_LE)
export const float64ArrayDecoder = createTypedArrayDecoder(Float64Array)
// =============================================================================
// Error (Tag 27) - IANA "object with class name and constructor arguments"
// Format: Tag 27: [className, message, options?]
// =============================================================================
/**
* Known JavaScript Error constructors
* @type {Record<string, ErrorConstructor>}
*/
const errorConstructors = {
Error,
EvalError,
RangeError,
ReferenceError,
SyntaxError,
TypeError,
URIError
}
/**
* Encode an Error as Tag 27: [className, message]
* @param {Error} err
* @returns {Token[]}
*/
export function errorEncoder (err) {
const className = err.name
// Only encode name and message (not stack, which is environment-specific)
return [
new Token(Type.tag, TAG_OBJECT_CLASS),
new Token(Type.array, 2),
new Token(Type.string, className),
new Token(Type.string, err.message)
]
}
/**
* Decode Tag 27 to an Error (or Error subclass)
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Error}
*/
export function errorDecoder (decode) {
const arr = /** @type {[string, string]} */ (decode())
const [className, message] = arr
const Ctor = errorConstructors[className] || Error
const err = new Ctor(message)
// If the constructor doesn't match (e.g., custom error name), set the name
if (err.name !== className && className in errorConstructors) {
err.name = className
}
return err
}
// =============================================================================
// Negative Zero (-0) Support
// CBOR can represent -0 as a float, but by default numbers encode as integers.
// This encoder ensures -0 is preserved by encoding it as a float.
// =============================================================================
/**
* Encode a number, preserving -0 as a float
* Use this as a typeEncoder for 'number' to preserve -0 fidelity
* @param {number} num
* @returns {Token[] | null}
*/
export function negativeZeroEncoder (num) {
if (Object.is(num, -0)) {
return [new Token(Type.float, -0)]
}
// Return null to fall through to default number encoding
return null
}
/* eslint-env mocha */
/**
* Test vectors for cborg/extended tag encoders/decoders
*
* Sources:
* - RFC 8949 Appendix A (Date tags 0, 1)
* - RFC 8746 (TypedArray tags 64-87)
* - CBOR Sets Spec: https://github.com/input-output-hk/cbor-sets-spec (Tag 258)
* - CBOR Map Spec: https://github.com/shanewholloway/js-cbor-codec (Tag 259)
*/
import * as chai from 'chai'
import { encode, decode } from '../lib/extended/extended.js'
import { fromHex, toHex } from '../lib/byte-utils.js'
const { assert } = chai
describe('cborg/extended test vectors', () => {
describe('Tag 1 - Date (RFC 8949 Appendix A)', () => {
it('decodes epoch integer: c11a514b67b0 → Date(1363896240000)', () => {
// From RFC 8949 Appendix A: 1(1363896240)
const bytes = fromHex('c11a514b67b0')
const result = decode(bytes)
assert.ok(result instanceof Date)
assert.strictEqual(result.getTime(), 1363896240000)
})
it('decodes epoch float: c1fb41d452d9ec200000 → Date(1363896240500)', () => {
// From RFC 8949 Appendix A: 1(1363896240.5)
const bytes = fromHex('c1fb41d452d9ec200000')
const result = decode(bytes)
assert.ok(result instanceof Date)
assert.strictEqual(result.getTime(), 1363896240500)
})
it('round-trips date with millisecond precision', () => {
const date = new Date(1363896240500) // 2013-03-21T20:04:00.500Z
const encoded = encode(date)
const decoded = decode(encoded)
assert.strictEqual(decoded.getTime(), date.getTime())
})
})
describe('Tag 2/3 - BigInt (RFC 8949)', () => {
it('decodes positive bigint: c249010000000000000000 → 2^64', () => {
// Tag 2 with bytes for 2^64
const bytes = fromHex('c249010000000000000000')
const result = decode(bytes)
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, BigInt('18446744073709551616'))
})
it('decodes negative bigint: c349010000000000000000 → -(2^64 + 1)', () => {
// Tag 3 with bytes for -(2^64 + 1)
const bytes = fromHex('c349010000000000000000')
const result = decode(bytes)
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, BigInt('-18446744073709551617'))
})
it('round-trips large positive bigint', () => {
const n = BigInt('18446744073709551616') // 2^64
const encoded = encode(n)
// Verify it uses tag 2
assert.strictEqual(encoded[0], 0xc2) // Tag 2
const decoded = decode(encoded)
assert.strictEqual(decoded, n)
})
it('round-trips large negative bigint', () => {
const n = BigInt('-18446744073709551617') // -(2^64 + 1)
const encoded = encode(n)
// Verify it uses tag 3
assert.strictEqual(encoded[0], 0xc3) // Tag 3
const decoded = decode(encoded)
assert.strictEqual(decoded, n)
})
})
describe('Tag 258 - Set (IANA Registry)', () => {
it('decodes official vector: d9010283010203 → Set([1, 2, 3])', () => {
// From https://github.com/input-output-hk/cbor-sets-spec
const bytes = fromHex('d9010283010203')
const result = decode(bytes)
assert.ok(result instanceof Set)
assert.strictEqual(result.size, 3)
assert.ok(result.has(1))
assert.ok(result.has(2))
assert.ok(result.has(3))
})
it('encodes Set([1, 2, 3]) with tag 258', () => {
const set = new Set([1, 2, 3])
const encoded = encode(set)
// First two bytes should be d9 0102 (tag 258)
assert.strictEqual(encoded[0], 0xd9)
assert.strictEqual(encoded[1], 0x01)
assert.strictEqual(encoded[2], 0x02)
})
it('round-trips empty set', () => {
const set = new Set()
const encoded = encode(set)
const decoded = decode(encoded)
assert.ok(decoded instanceof Set)
assert.strictEqual(decoded.size, 0)
})
})
describe('Tag 259 - Map (IANA Registry)', () => {
it('decodes official vector: d90103a2626b31627631626b32627632 → Map', () => {
// From https://github.com/shanewholloway/js-cbor-codec
// Map with string keys: {k1: v1, k2: v2}
const bytes = fromHex('d90103a2626b31627631626b32627632')
const result = decode(bytes)
assert.ok(result instanceof Map)
assert.strictEqual(result.get('k1'), 'v1')
assert.strictEqual(result.get('k2'), 'v2')
})
it('encodes Map with tag 259', () => {
const map = new Map([['k1', 'v1'], ['k2', 'v2']])
const encoded = encode(map)
// First two bytes should be d9 0103 (tag 259)
assert.strictEqual(encoded[0], 0xd9)
assert.strictEqual(encoded[1], 0x01)
assert.strictEqual(encoded[2], 0x03)
})
it('round-trips map with non-string keys', () => {
const map = new Map([[42, 'answer'], [true, 'yes']])
const encoded = encode(map)
const decoded = decode(encoded)
assert.ok(decoded instanceof Map)
assert.strictEqual(decoded.get(42), 'answer')
assert.strictEqual(decoded.get(true), 'yes')
})
})
describe('Tags 64-87 - TypedArrays (RFC 8746)', () => {
// RFC 8746 defines tags for typed arrays
// We use little-endian tags (69, 70, 71, 77, 78, 79, 85, 86) for multi-byte types
it('Tag 64: Uint8Array round-trips', () => {
const arr = new Uint8Array([1, 2, 3, 255])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8) // 1-byte tag
assert.strictEqual(encoded[1], 64) // Tag 64
const decoded = decode(encoded)
assert.ok(decoded instanceof Uint8Array)
assert.deepStrictEqual([...decoded], [1, 2, 3, 255])
})
it('Tag 68: Uint8ClampedArray round-trips', () => {
const arr = new Uint8ClampedArray([0, 128, 255])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 68)
const decoded = decode(encoded)
assert.ok(decoded instanceof Uint8ClampedArray)
assert.deepStrictEqual([...decoded], [0, 128, 255])
})
it('Tag 72: Int8Array round-trips', () => {
const arr = new Int8Array([-128, 0, 127])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 72)
const decoded = decode(encoded)
assert.ok(decoded instanceof Int8Array)
assert.deepStrictEqual([...decoded], [-128, 0, 127])
})
it('Tag 69: Uint16Array (LE) round-trips', () => {
const arr = new Uint16Array([0, 256, 65535])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 69)
const decoded = decode(encoded)
assert.ok(decoded instanceof Uint16Array)
assert.deepStrictEqual([...decoded], [0, 256, 65535])
})
it('Tag 77: Int16Array (LE) round-trips', () => {
const arr = new Int16Array([-32768, 0, 32767])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 77)
const decoded = decode(encoded)
assert.ok(decoded instanceof Int16Array)
assert.deepStrictEqual([...decoded], [-32768, 0, 32767])
})
it('Tag 70: Uint32Array (LE) round-trips', () => {
const arr = new Uint32Array([0, 65536, 4294967295])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 70)
const decoded = decode(encoded)
assert.ok(decoded instanceof Uint32Array)
assert.deepStrictEqual([...decoded], [0, 65536, 4294967295])
})
it('Tag 78: Int32Array (LE) round-trips', () => {
const arr = new Int32Array([-2147483648, 0, 2147483647])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 78)
const decoded = decode(encoded)
assert.ok(decoded instanceof Int32Array)
assert.deepStrictEqual([...decoded], [-2147483648, 0, 2147483647])
})
it('Tag 85: Float32Array (LE) round-trips', () => {
const arr = new Float32Array([1.5, -2.5, 0])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 85)
const decoded = decode(encoded)
assert.ok(decoded instanceof Float32Array)
assert.strictEqual(decoded[0], 1.5)
assert.strictEqual(decoded[1], -2.5)
assert.strictEqual(decoded[2], 0)
})
it('Tag 86: Float64Array (LE) round-trips', () => {
const arr = new Float64Array([Math.PI, -Math.E, Infinity])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 86)
const decoded = decode(encoded)
assert.ok(decoded instanceof Float64Array)
assert.strictEqual(decoded[0], Math.PI)
assert.strictEqual(decoded[1], -Math.E)
assert.strictEqual(decoded[2], Infinity)
})
it('Tag 71: BigUint64Array (LE) round-trips', () => {
const arr = new BigUint64Array([0n, 1n, BigInt('18446744073709551615')])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 71)
const decoded = decode(encoded)
assert.ok(decoded instanceof BigUint64Array)
assert.deepStrictEqual([...decoded], [0n, 1n, BigInt('18446744073709551615')])
})
it('Tag 79: BigInt64Array (LE) round-trips', () => {
const arr = new BigInt64Array([BigInt('-9223372036854775808'), 0n, BigInt('9223372036854775807')])
const encoded = encode(arr)
assert.strictEqual(encoded[0], 0xd8)
assert.strictEqual(encoded[1], 79)
const decoded = decode(encoded)
assert.ok(decoded instanceof BigInt64Array)
assert.deepStrictEqual([...decoded], [BigInt('-9223372036854775808'), 0n, BigInt('9223372036854775807')])
})
})
describe('cross-implementation compatibility', () => {
it('generates deterministic output for Set', () => {
// Sets should encode consistently
const set = new Set([1, 2, 3])
const encoded1 = encode(set)
const encoded2 = encode(set)
assert.strictEqual(toHex(encoded1), toHex(encoded2))
})
it('generates deterministic output for Map', () => {
// Maps should encode with consistent key ordering
const map = new Map([['b', 2], ['a', 1]])
const encoded1 = encode(map)
const encoded2 = encode(map)
assert.strictEqual(toHex(encoded1), toHex(encoded2))
})
it('handles nested tagged values', () => {
// A Set containing a Map containing a Date
const nested = new Set([
new Map([['created', new Date('2024-01-01T00:00:00Z')]])
])
const encoded = encode(nested)
const decoded = decode(encoded)
assert.ok(decoded instanceof Set)
const innerMap = [...decoded][0]
assert.ok(innerMap instanceof Map)
const date = innerMap.get('created')
assert.ok(date instanceof Date)
assert.strictEqual(date.toISOString(), '2024-01-01T00:00:00.000Z')
})
})
})
/* eslint-env mocha */
import * as chai from 'chai'
import { encode, decode } from '../lib/extended/extended.js'
import { encode as cborgEncode } from '../cborg.js'
const { assert } = chai
describe('cborg/extended', () => {
describe('Date', () => {
it('round-trips a date', () => {
const d = new Date('2024-01-15T12:30:00.000Z')
const result = decode(encode(d))
assert.ok(result instanceof Date)
assert.strictEqual(result.getTime(), d.getTime())
})
it('round-trips date with milliseconds', () => {
const d = new Date('2024-01-15T12:30:00.123Z')
const result = decode(encode(d))
assert.strictEqual(result.getTime(), d.getTime())
})
it('round-trips epoch date', () => {
const d = new Date(0)
const result = decode(encode(d))
assert.strictEqual(result.getTime(), 0)
})
it('round-trips negative epoch date', () => {
const d = new Date(-86400000) // 1 day before epoch
const result = decode(encode(d))
assert.strictEqual(result.getTime(), d.getTime())
})
})
describe('RegExp', () => {
it('round-trips pattern without flags', () => {
const re = /foo.*bar/
const result = decode(encode(re))
assert.ok(result instanceof RegExp)
assert.strictEqual(result.source, re.source)
assert.strictEqual(result.flags, re.flags)
})
it('round-trips pattern with flags', () => {
const re = /foo.*bar/gim
const result = decode(encode(re))
assert.strictEqual(result.source, re.source)
assert.strictEqual(result.flags, re.flags)
})
it('round-trips complex pattern', () => {
const re = /^[a-z]+\d{2,4}$/i
const result = decode(encode(re))
assert.strictEqual(result.source, re.source)
assert.strictEqual(result.flags, re.flags)
})
it('round-trips empty pattern', () => {
const re = /(?:)/
const result = decode(encode(re))
assert.strictEqual(result.source, '(?:)')
})
})
describe('Set', () => {
it('round-trips empty set', () => {
const s = new Set()
const result = decode(encode(s))
assert.ok(result instanceof Set)
assert.strictEqual(result.size, 0)
})
it('round-trips set with primitives', () => {
const s = new Set([1, 2, 3, 'a', 'b'])
const result = decode(encode(s))
assert.ok(result instanceof Set)
assert.strictEqual(result.size, 5)
assert.ok(result.has(1))
assert.ok(result.has(2))
assert.ok(result.has(3))
assert.ok(result.has('a'))
assert.ok(result.has('b'))
})
it('round-trips set with objects', () => {
const s = new Set([{ x: 1 }, { y: 2 }])
const result = decode(encode(s))
assert.strictEqual(result.size, 2)
const arr = [...result]
// Objects inside the set stay as objects (useMaps: false)
assert.ok(!(arr[0] instanceof Map))
assert.ok(!(arr[1] instanceof Map))
assert.strictEqual(arr[0].x, 1)
assert.strictEqual(arr[1].y, 2)
})
})
describe('Map', () => {
it('round-trips empty map', () => {
const m = new Map()
const result = decode(encode(m))
assert.ok(result instanceof Map)
assert.strictEqual(result.size, 0)
})
it('round-trips map with string keys', () => {
const m = new Map([['a', 1], ['b', 2]])
const result = decode(encode(m))
assert.ok(result instanceof Map)
assert.strictEqual(result.get('a'), 1)
assert.strictEqual(result.get('b'), 2)
})
it('round-trips map with number keys', () => {
const m = new Map([[1, 'one'], [2, 'two']])
const result = decode(encode(m))
assert.ok(result instanceof Map)
assert.strictEqual(result.get(1), 'one')
assert.strictEqual(result.get(2), 'two')
})
it('round-trips map with mixed keys', () => {
const m = new Map([['str', 1], [42, 2], [true, 3]])
const result = decode(encode(m))
assert.strictEqual(result.get('str'), 1)
assert.strictEqual(result.get(42), 2)
assert.strictEqual(result.get(true), 3)
})
it('round-trips map with object values', () => {
const m = new Map([
['user1', { name: 'Alice', age: 30 }],
['user2', { name: 'Bob', age: 25 }]
])
const result = decode(encode(m))
assert.ok(result instanceof Map)
// Values should be plain objects, not Maps
assert.ok(!(result.get('user1') instanceof Map))
assert.strictEqual(result.get('user1').name, 'Alice')
assert.strictEqual(result.get('user2').age, 25)
})
it('round-trips map with nested map values', () => {
const m = new Map([
['outer', new Map([['inner', 'value']])]
])
const result = decode(encode(m))
assert.ok(result instanceof Map)
assert.ok(result.get('outer') instanceof Map)
assert.strictEqual(result.get('outer').get('inner'), 'value')
})
it('round-trips map with BigInt keys', () => {
const m = new Map([
[123n, 'small bigint'],
[BigInt('9007199254740993'), 'large bigint']
])
const result = decode(encode(m))
assert.ok(result instanceof Map)
assert.strictEqual(result.get(123n), 'small bigint')
assert.strictEqual(result.get(BigInt('9007199254740993')), 'large bigint')
})
it('round-trips map with Date keys', () => {
const d1 = new Date('2024-01-01')
const d2 = new Date('2024-12-31')
const m = new Map([
[d1, 'new year'],
[d2, 'new year eve']
])
const result = decode(encode(m))
assert.ok(result instanceof Map)
// Date keys become new Date instances, so we need to find by time
const keys = [...result.keys()]
assert.ok(keys[0] instanceof Date)
assert.ok(keys[1] instanceof Date)
assert.strictEqual(keys[0].getTime(), d1.getTime())
assert.strictEqual(keys[1].getTime(), d2.getTime())
})
})
describe('object containing Map', () => {
it('round-trips object with Map property', () => {
const obj = {
name: 'test',
data: new Map([[1, 'one'], [2, 'two']])
}
const result = decode(encode(obj))
// Outer should be plain object
assert.ok(!(result instanceof Map))
assert.strictEqual(result.name, 'test')
// Inner Map should be Map with integer keys preserved
assert.ok(result.data instanceof Map)
assert.strictEqual(result.data.get(1), 'one')
assert.strictEqual(result.data.get(2), 'two')
})
it('round-trips deeply nested object/Map mix', () => {
const obj = {
level1: {
level2: new Map([
['key', { level3: new Map([[42, 'deep']]) }]
])
}
}
const result = decode(encode(obj))
// Check structure preservation
assert.ok(!(result instanceof Map))
assert.ok(!(result.level1 instanceof Map))
assert.ok(result.level1.level2 instanceof Map)
assert.ok(!(result.level1.level2.get('key') instanceof Map))
assert.ok(result.level1.level2.get('key').level3 instanceof Map)
assert.strictEqual(result.level1.level2.get('key').level3.get(42), 'deep')
})
})
describe('BigInt', () => {
it('round-trips zero', () => {
const result = decode(encode(0n))
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, 0n)
})
it('round-trips small positive', () => {
const result = decode(encode(100n))
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, 100n)
})
it('round-trips small negative', () => {
const result = decode(encode(-1n))
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, -1n)
})
it('round-trips beyond MAX_SAFE_INTEGER', () => {
const n = 9007199254740993n
const result = decode(encode(n))
assert.strictEqual(result, n)
})
it('round-trips large positive', () => {
const n = BigInt('123456789012345678901234567890')
const result = decode(encode(n))
assert.strictEqual(result, n)
})
it('round-trips large negative', () => {
const n = BigInt('-123456789012345678901234567890')
const result = decode(encode(n))
assert.strictEqual(result, n)
})
})
describe('TypedArrays', () => {
it('Uint8Array', () => {
const arr = new Uint8Array([1, 2, 3, 4, 5])
const result = decode(encode(arr))
assert.ok(result instanceof Uint8Array)
assert.deepStrictEqual([...result], [1, 2, 3, 4, 5])
})
it('Uint8ClampedArray', () => {
const arr = new Uint8ClampedArray([0, 128, 255])
const result = decode(encode(arr))
assert.ok(result instanceof Uint8ClampedArray)
assert.deepStrictEqual([...result], [0, 128, 255])
})
it('Int8Array', () => {
const arr = new Int8Array([-128, 0, 127])
const result = decode(encode(arr))
assert.ok(result instanceof Int8Array)
assert.deepStrictEqual([...result], [-128, 0, 127])
})
it('Uint16Array', () => {
const arr = new Uint16Array([0, 256, 65535])
const result = decode(encode(arr))
assert.ok(result instanceof Uint16Array)
assert.deepStrictEqual([...result], [0, 256, 65535])
})
it('Int16Array', () => {
const arr = new Int16Array([-32768, 0, 32767])
const result = decode(encode(arr))
assert.ok(result instanceof Int16Array)
assert.deepStrictEqual([...result], [-32768, 0, 32767])
})
it('Uint32Array', () => {
const arr = new Uint32Array([0, 65536, 4294967295])
const result = decode(encode(arr))
assert.ok(result instanceof Uint32Array)
assert.deepStrictEqual([...result], [0, 65536, 4294967295])
})
it('Int32Array', () => {
const arr = new Int32Array([-2147483648, 0, 2147483647])
const result = decode(encode(arr))
assert.ok(result instanceof Int32Array)
assert.deepStrictEqual([...result], [-2147483648, 0, 2147483647])
})
it('Float32Array', () => {
const arr = new Float32Array([1.5, -2.5, 3.14])
const result = decode(encode(arr))
assert.ok(result instanceof Float32Array)
assert.strictEqual(result[0], 1.5)
assert.strictEqual(result[1], -2.5)
assert.ok(Math.abs(result[2] - 3.14) < 0.001)
})
it('Float64Array', () => {
const arr = new Float64Array([1.1, -2.2, Math.PI, Infinity, -Infinity])
const result = decode(encode(arr))
assert.ok(result instanceof Float64Array)
assert.deepStrictEqual([...result], [1.1, -2.2, Math.PI, Infinity, -Infinity])
})
it('BigUint64Array', () => {
const arr = new BigUint64Array([0n, 1n, BigInt('18446744073709551615')])
const result = decode(encode(arr))
assert.ok(result instanceof BigUint64Array)
assert.deepStrictEqual([...result], [0n, 1n, BigInt('18446744073709551615')])
})
it('BigInt64Array', () => {
const arr = new BigInt64Array([BigInt('-9223372036854775808'), 0n, BigInt('9223372036854775807')])
const result = decode(encode(arr))
assert.ok(result instanceof BigInt64Array)
assert.deepStrictEqual([...result], [BigInt('-9223372036854775808'), 0n, BigInt('9223372036854775807')])
})
it('TypedArray view of larger buffer', () => {
const buffer = new ArrayBuffer(100)
const view = new Uint8Array(buffer, 10, 5)
view.set([1, 2, 3, 4, 5])
const result = decode(encode(view))
assert.strictEqual(result.length, 5)
assert.deepStrictEqual([...result], [1, 2, 3, 4, 5])
})
})
describe('nested structures', () => {
it('object with multiple types', () => {
const obj = {
date: new Date('2024-01-15T12:00:00Z'),
pattern: /test/gi,
mapping: new Map([['key', 'value']]),
collection: new Set([1, 2, 3]),
binary: new Uint8Array([1, 2, 3]),
bignum: 123n
}
const result = decode(encode(obj))
// Plain objects stay as objects (useMaps: false by default)
assert.ok(!(result instanceof Map))
assert.ok(typeof result === 'object')
assert.ok(result.date instanceof Date)
assert.strictEqual(result.date.getTime(), obj.date.getTime())
assert.ok(result.pattern instanceof RegExp)
assert.strictEqual(result.pattern.source, 'test')
assert.strictEqual(result.pattern.flags, 'gi')
// Tagged Maps decode as Maps
assert.ok(result.mapping instanceof Map)
assert.strictEqual(result.mapping.get('key'), 'value')
assert.ok(result.collection instanceof Set)
assert.strictEqual(result.collection.size, 3)
assert.ok(result.binary instanceof Uint8Array)
assert.deepStrictEqual([...result.binary], [1, 2, 3])
assert.strictEqual(typeof result.bignum, 'bigint')
assert.strictEqual(result.bignum, 123n)
})
it('deeply nested maps and sets', () => {
const obj = {
outer: new Map([
['inner', new Set([
new Map([['deep', 'value']])
])]
])
}
const result = decode(encode(obj))
// Plain objects stay as objects, tagged Maps become Maps
assert.ok(!(result instanceof Map))
assert.ok(result.outer instanceof Map)
const inner = result.outer.get('inner')
assert.ok(inner instanceof Set)
const deepMap = [...inner][0]
assert.ok(deepMap instanceof Map)
assert.strictEqual(deepMap.get('deep'), 'value')
})
it('array of dates', () => {
const dates = [
new Date('2024-01-01'),
new Date('2024-06-15'),
new Date('2024-12-31')
]
const result = decode(encode(dates))
assert.strictEqual(result.length, 3)
assert.ok(result[0] instanceof Date)
assert.ok(result[1] instanceof Date)
assert.ok(result[2] instanceof Date)
assert.strictEqual(result[0].getTime(), dates[0].getTime())
assert.strictEqual(result[1].getTime(), dates[1].getTime())
assert.strictEqual(result[2].getTime(), dates[2].getTime())
})
})
describe('undefined and null', () => {
it('preserves undefined in objects', () => {
const obj = { a: undefined, b: null, c: 1 }
const result = decode(encode(obj))
// Plain objects stay as objects
assert.ok(!(result instanceof Map))
assert.strictEqual(result.a, undefined)
assert.strictEqual(result.b, null)
assert.strictEqual(result.c, 1)
})
it('preserves null values', () => {
const result = decode(encode(null))
assert.strictEqual(result, null)
})
it('preserves undefined values', () => {
const result = decode(encode(undefined))
assert.strictEqual(result, undefined)
})
})
describe('compatibility', () => {
it('plain objects decode as objects (useMaps: false is default)', () => {
const obj = { a: 1, b: [2, 3], c: 'hello' }
const result = decode(encode(obj))
// Plain objects stay as objects
assert.ok(!(result instanceof Map))
assert.strictEqual(result.a, 1)
assert.deepStrictEqual(result.b, [2, 3])
assert.strictEqual(result.c, 'hello')
})
it('plain objects decode as Maps with useMaps: true', () => {
const obj = { a: 1, b: [2, 3], c: 'hello' }
const result = decode(encode(obj), { useMaps: true })
assert.ok(result instanceof Map)
assert.strictEqual(result.get('a'), 1)
})
it('plain arrays still work', () => {
const arr = [1, 'two', { three: 3 }]
const result = decode(encode(arr))
assert.ok(Array.isArray(result))
assert.strictEqual(result[0], 1)
assert.strictEqual(result[1], 'two')
// Nested objects stay as objects
assert.ok(!(result[2] instanceof Map))
assert.strictEqual(result[2].three, 3)
})
it('can decode standard cborg output', () => {
const obj = { a: 1, b: 'hello' }
const standardCbor = cborgEncode(obj)
const result = decode(standardCbor)
// Plain objects stay as objects
assert.ok(!(result instanceof Map))
assert.strictEqual(result.a, 1)
assert.strictEqual(result.b, 'hello')
})
it('primitives round-trip correctly', () => {
assert.strictEqual(decode(encode(true)), true)
assert.strictEqual(decode(encode(false)), false)
assert.strictEqual(decode(encode(42)), 42)
assert.strictEqual(decode(encode(-42)), -42)
assert.strictEqual(decode(encode(3.14)), 3.14)
assert.strictEqual(decode(encode('hello')), 'hello')
assert.strictEqual(decode(encode('')), '')
})
})
describe('edge cases', () => {
it('empty object', () => {
const result = decode(encode({}))
// Plain objects stay as objects
assert.ok(!(result instanceof Map))
assert.deepStrictEqual(result, {})
})
it('empty array', () => {
const result = decode(encode([]))
assert.deepStrictEqual(result, [])
})
it('object with numeric string keys', () => {
const obj = { 1: 'one', 2: 'two' }
const result = decode(encode(obj))
// Plain objects stay as objects
// Note: JS object keys are strings, so { 1: 'one' } has key '1' not 1
assert.ok(!(result instanceof Map))
assert.strictEqual(result['1'], 'one')
assert.strictEqual(result['2'], 'two')
})
it('very long string', () => {
const str = 'x'.repeat(10000)
const result = decode(encode(str))
assert.strictEqual(result, str)
})
it('special float values', () => {
assert.strictEqual(decode(encode(Infinity)), Infinity)
assert.strictEqual(decode(encode(-Infinity)), -Infinity)
assert.ok(Number.isNaN(decode(encode(NaN))))
})
})
describe('insertion order preservation', () => {
it('preserves Map key insertion order', () => {
// Keys intentionally not in alphabetical or length-first order
const map = new Map([
['zebra', 1],
['a', 2],
['mango', 3],
['b', 4]
])
const result = decode(encode(map))
const keys = [...result.keys()]
assert.deepStrictEqual(keys, ['zebra', 'a', 'mango', 'b'])
})
it('preserves Map key insertion order with mixed key types', () => {
const map = new Map([
[100, 'hundred'],
['first', 1],
[1, 'one'],
['zzz', 'last']
])
const result = decode(encode(map))
const keys = [...result.keys()]
assert.deepStrictEqual(keys, [100, 'first', 1, 'zzz'])
})
it('preserves object key insertion order', () => {
// Keys intentionally not in alphabetical or length-first order
const obj = {
zebra: 1,
a: 2,
mango: 3,
b: 4
}
const result = decode(encode(obj))
const keys = Object.keys(result)
assert.deepStrictEqual(keys, ['zebra', 'a', 'mango', 'b'])
})
it('preserves nested Map and object insertion order', () => {
const data = {
zz: 'first',
aa: new Map([
['zzz', 1],
['aaa', 2]
]),
mm: 'last'
}
const result = decode(encode(data))
// Object key order preserved
assert.deepStrictEqual(Object.keys(result), ['zz', 'aa', 'mm'])
// Nested Map key order preserved
assert.deepStrictEqual([...result.aa.keys()], ['zzz', 'aaa'])
})
})
describe('Error types', () => {
it('round-trips Error', () => {
const err = new Error('test error')
const result = decode(encode(err))
assert.ok(result instanceof Error)
assert.strictEqual(result.message, 'test error')
assert.strictEqual(result.name, 'Error')
})
it('round-trips TypeError', () => {
const err = new TypeError('type mismatch')
const result = decode(encode(err))
assert.ok(result instanceof TypeError)
assert.strictEqual(result.message, 'type mismatch')
assert.strictEqual(result.name, 'TypeError')
})
it('round-trips RangeError', () => {
const err = new RangeError('out of range')
const result = decode(encode(err))
assert.ok(result instanceof RangeError)
assert.strictEqual(result.message, 'out of range')
assert.strictEqual(result.name, 'RangeError')
})
it('round-trips SyntaxError', () => {
const err = new SyntaxError('bad syntax')
const result = decode(encode(err))
assert.ok(result instanceof SyntaxError)
assert.strictEqual(result.message, 'bad syntax')
})
it('round-trips ReferenceError', () => {
const err = new ReferenceError('not defined')
const result = decode(encode(err))
assert.ok(result instanceof ReferenceError)
assert.strictEqual(result.message, 'not defined')
})
it('round-trips EvalError', () => {
const err = new EvalError('eval failed')
const result = decode(encode(err))
assert.ok(result instanceof EvalError)
assert.strictEqual(result.message, 'eval failed')
})
it('round-trips URIError', () => {
const err = new URIError('bad URI')
const result = decode(encode(err))
assert.ok(result instanceof URIError)
assert.strictEqual(result.message, 'bad URI')
})
it('round-trips Error with empty message', () => {
const err = new Error()
const result = decode(encode(err))
assert.ok(result instanceof Error)
assert.strictEqual(result.message, '')
})
it('round-trips Error in object', () => {
const obj = { error: new TypeError('failed'), code: 500 }
const result = decode(encode(obj))
assert.ok(result.error instanceof TypeError)
assert.strictEqual(result.error.message, 'failed')
assert.strictEqual(result.code, 500)
})
})
describe('negative zero', () => {
it('round-trips -0', () => {
const result = decode(encode(-0))
assert.ok(Object.is(result, -0))
})
it('distinguishes -0 from 0', () => {
const negZero = decode(encode(-0))
const posZero = decode(encode(0))
assert.ok(Object.is(negZero, -0))
assert.ok(Object.is(posZero, 0))
assert.ok(!Object.is(negZero, posZero))
})
it('round-trips -0 in object', () => {
const obj = { neg: -0, pos: 0 }
const result = decode(encode(obj))
assert.ok(Object.is(result.neg, -0))
assert.ok(Object.is(result.pos, 0))
})
it('round-trips -0 in array', () => {
const arr = [-0, 0, -0]
const result = decode(encode(arr))
assert.ok(Object.is(result[0], -0))
assert.ok(Object.is(result[1], 0))
assert.ok(Object.is(result[2], -0))
})
})
})
/* eslint-env mocha */
import * as chai from 'chai'
import { encode, decode } from '../cborg.js'
import {
// Tag constants
TAG_DATE_EPOCH,
TAG_BIGINT_POS,
TAG_BIGINT_NEG,
TAG_UINT8_ARRAY,
TAG_UINT8_CLAMPED_ARRAY,
TAG_INT8_ARRAY,
TAG_UINT16_ARRAY_LE,
TAG_UINT32_ARRAY_LE,
TAG_BIGUINT64_ARRAY_LE,
TAG_INT16_ARRAY_LE,
TAG_INT32_ARRAY_LE,
TAG_BIGINT64_ARRAY_LE,
TAG_FLOAT32_ARRAY_LE,
TAG_FLOAT64_ARRAY_LE,
TAG_SET,
TAG_MAP,
TAG_REGEXP,
// BigInt
bigIntEncoder,
bigIntDecoder,
bigNegIntDecoder,
structBigIntEncoder,
// Date
dateEncoder,
dateDecoder,
// RegExp
regExpEncoder,
regExpDecoder,
// Set
setEncoder,
setDecoder,
// Map
mapEncoder,
mapDecoder,
// TypedArrays
uint8ArrayEncoder,
uint8ArrayDecoder,
uint8ClampedArrayEncoder,
uint8ClampedArrayDecoder,
int8ArrayEncoder,
int8ArrayDecoder,
uint16ArrayEncoder,
uint16ArrayDecoder,
uint32ArrayEncoder,
uint32ArrayDecoder,
bigUint64ArrayEncoder,
bigUint64ArrayDecoder,
int16ArrayEncoder,
int16ArrayDecoder,
int32ArrayEncoder,
int32ArrayDecoder,
bigInt64ArrayEncoder,
bigInt64ArrayDecoder,
float32ArrayEncoder,
float32ArrayDecoder,
float64ArrayEncoder,
float64ArrayDecoder
} from '../lib/taglib.js'
const { assert } = chai
/**
* Create a mock decode control for unit testing decoders
* @param {any} value - The value that decode() should return
* @param {Array<[any, any]>} [entries] - Optional entries for decode.entries()
* @returns {import('../interface').TagDecodeControl}
*/
function mockDecode (value, entries) {
const fn = () => value
fn.entries = () => entries || []
return fn
}
describe('taglib', () => {
describe('tag constants', () => {
it('has correct standard tag values', () => {
assert.strictEqual(TAG_DATE_EPOCH, 1)
assert.strictEqual(TAG_BIGINT_POS, 2)
assert.strictEqual(TAG_BIGINT_NEG, 3)
})
it('has correct TypedArray tag values', () => {
assert.strictEqual(TAG_UINT8_ARRAY, 64)
assert.strictEqual(TAG_UINT8_CLAMPED_ARRAY, 68)
assert.strictEqual(TAG_INT8_ARRAY, 72)
assert.strictEqual(TAG_UINT16_ARRAY_LE, 69)
assert.strictEqual(TAG_UINT32_ARRAY_LE, 70)
assert.strictEqual(TAG_BIGUINT64_ARRAY_LE, 71)
assert.strictEqual(TAG_INT16_ARRAY_LE, 77)
assert.strictEqual(TAG_INT32_ARRAY_LE, 78)
assert.strictEqual(TAG_BIGINT64_ARRAY_LE, 79)
assert.strictEqual(TAG_FLOAT32_ARRAY_LE, 85)
assert.strictEqual(TAG_FLOAT64_ARRAY_LE, 86)
})
it('has correct extended tag values', () => {
assert.strictEqual(TAG_SET, 258)
assert.strictEqual(TAG_MAP, 259)
assert.strictEqual(TAG_REGEXP, 21066)
})
})
describe('BigInt', () => {
describe('bigIntDecoder', () => {
it('decodes zero', () => {
assert.strictEqual(bigIntDecoder(mockDecode(new Uint8Array([0]))), 0n)
})
it('decodes small positive', () => {
assert.strictEqual(bigIntDecoder(mockDecode(new Uint8Array([100]))), 100n)
})
it('decodes large positive', () => {
// 0x0100000000000000 = 72057594037927936
assert.strictEqual(
bigIntDecoder(mockDecode(new Uint8Array([1, 0, 0, 0, 0, 0, 0, 0]))),
72057594037927936n
)
})
})
describe('bigNegIntDecoder', () => {
it('decodes -1', () => {
assert.strictEqual(bigNegIntDecoder(mockDecode(new Uint8Array([0]))), -1n)
})
it('decodes negative', () => {
// -1 - 100 = -101
assert.strictEqual(bigNegIntDecoder(mockDecode(new Uint8Array([100]))), -101n)
})
})
describe('bigIntEncoder (IPLD compatible)', () => {
it('returns null for small values (within 64-bit range)', () => {
assert.strictEqual(bigIntEncoder(0n), null)
assert.strictEqual(bigIntEncoder(100n), null)
assert.strictEqual(bigIntEncoder(-100n), null)
assert.strictEqual(bigIntEncoder(BigInt('18446744073709551615')), null)
assert.strictEqual(bigIntEncoder(BigInt('-18446744073709551616')), null)
})
it('returns tokens for large positive values', () => {
const tokens = bigIntEncoder(BigInt('18446744073709551616'))
assert.ok(Array.isArray(tokens))
assert.strictEqual(tokens[0].value, TAG_BIGINT_POS)
})
it('returns tokens for large negative values', () => {
const tokens = bigIntEncoder(BigInt('-18446744073709551617'))
assert.ok(Array.isArray(tokens))
assert.strictEqual(tokens[0].value, TAG_BIGINT_NEG)
})
})
describe('structBigIntEncoder (always tags)', () => {
it('returns tokens for zero', () => {
const tokens = structBigIntEncoder(0n)
assert.ok(Array.isArray(tokens))
assert.strictEqual(tokens[0].value, TAG_BIGINT_POS)
})
it('returns tokens for small positive', () => {
const tokens = structBigIntEncoder(100n)
assert.ok(Array.isArray(tokens))
assert.strictEqual(tokens[0].value, TAG_BIGINT_POS)
})
it('returns tokens for small negative', () => {
const tokens = structBigIntEncoder(-1n)
assert.ok(Array.isArray(tokens))
assert.strictEqual(tokens[0].value, TAG_BIGINT_NEG)
})
})
describe('round-trip via encode/decode', () => {
const opts = {
typeEncoders: { bigint: structBigIntEncoder },
tags: { [TAG_BIGINT_POS]: bigIntDecoder, [TAG_BIGINT_NEG]: bigNegIntDecoder }
}
it('round-trips 0n', () => {
const result = decode(encode(0n, opts), opts)
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, 0n)
})
it('round-trips 100n', () => {
const result = decode(encode(100n, opts), opts)
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, 100n)
})
it('round-trips -1n', () => {
const result = decode(encode(-1n, opts), opts)
assert.strictEqual(typeof result, 'bigint')
assert.strictEqual(result, -1n)
})
it('round-trips large positive', () => {
const n = BigInt('9007199254740993')
const result = decode(encode(n, opts), opts)
assert.strictEqual(result, n)
})
it('round-trips large negative', () => {
const n = BigInt('-18446744073709551617')
const result = decode(encode(n, opts), opts)
assert.strictEqual(result, n)
})
})
})
describe('Date', () => {
describe('dateEncoder', () => {
it('returns tag 1 with float seconds', () => {
const tokens = dateEncoder(new Date(1000))
assert.strictEqual(tokens[0].value, TAG_DATE_EPOCH)
assert.strictEqual(tokens[1].value, 1) // 1000ms = 1 second
})
it('handles milliseconds', () => {
const tokens = dateEncoder(new Date(1500))
assert.strictEqual(tokens[1].value, 1.5)
})
it('handles epoch', () => {
const tokens = dateEncoder(new Date(0))
assert.strictEqual(tokens[1].value, 0)
})
})
describe('dateDecoder', () => {
it('decodes seconds to Date', () => {
const date = dateDecoder(mockDecode(1))
assert.ok(date instanceof Date)
assert.strictEqual(date.getTime(), 1000)
})
it('decodes float seconds', () => {
const date = dateDecoder(mockDecode(1.5))
assert.strictEqual(date.getTime(), 1500)
})
})
describe('round-trip via encode/decode', () => {
const opts = {
typeEncoders: { Date: dateEncoder },
tags: { [TAG_DATE_EPOCH]: dateDecoder }
}
it('round-trips a date', () => {
const d = new Date('2024-01-15T12:30:00.000Z')
const result = decode(encode(d, opts), opts)
assert.ok(result instanceof Date)
assert.strictEqual(result.getTime(), d.getTime())
})
it('round-trips date with milliseconds', () => {
const d = new Date('2024-01-15T12:30:00.123Z')
const result = decode(encode(d, opts), opts)
assert.strictEqual(result.getTime(), d.getTime())
})
it('round-trips epoch date', () => {
const d = new Date(0)
const result = decode(encode(d, opts), opts)
assert.strictEqual(result.getTime(), 0)
})
})
})
describe('RegExp', () => {
describe('regExpEncoder', () => {
it('encodes pattern without flags', () => {
const tokens = regExpEncoder(/foo/)
assert.strictEqual(tokens[0].value, TAG_REGEXP)
assert.strictEqual(tokens[1].value, 1) // array length 1
assert.strictEqual(tokens[2].value, 'foo')
})
it('encodes pattern with flags', () => {
const tokens = regExpEncoder(/foo/gi)
assert.strictEqual(tokens[0].value, TAG_REGEXP)
assert.strictEqual(tokens[1].value, 2) // array length 2
assert.strictEqual(tokens[2].value, 'foo')
assert.strictEqual(tokens[3].value, 'gi')
})
})
describe('regExpDecoder', () => {
it('decodes array with pattern only', () => {
const re = regExpDecoder(mockDecode(['foo']))
assert.ok(re instanceof RegExp)
assert.strictEqual(re.source, 'foo')
assert.strictEqual(re.flags, '')
})
it('decodes array with pattern and flags', () => {
const re = regExpDecoder(mockDecode(['foo', 'gi']))
assert.strictEqual(re.source, 'foo')
assert.strictEqual(re.flags, 'gi')
})
})
describe('round-trip via encode/decode', () => {
const opts = {
typeEncoders: { RegExp: regExpEncoder },
tags: { [TAG_REGEXP]: regExpDecoder }
}
it('round-trips pattern without flags', () => {
const re = /foo.*bar/
const result = decode(encode(re, opts), opts)
assert.ok(result instanceof RegExp)
assert.strictEqual(result.source, re.source)
assert.strictEqual(result.flags, re.flags)
})
it('round-trips pattern with flags', () => {
const re = /foo.*bar/gim
const result = decode(encode(re, opts), opts)
assert.strictEqual(result.source, re.source)
assert.strictEqual(result.flags, re.flags)
})
it('round-trips empty pattern', () => {
const re = /(?:)/
const result = decode(encode(re, opts), opts)
assert.strictEqual(result.source, '(?:)')
})
})
})
describe('Set', () => {
describe('setEncoder', () => {
it('encodes empty set', () => {
const tokens = setEncoder(new Set(), 'Set', {})
assert.strictEqual(tokens[0].value, TAG_SET)
assert.strictEqual(tokens[1].value, 0) // array length 0
})
})
describe('setDecoder', () => {
it('decodes array to Set', () => {
const s = setDecoder(mockDecode([1, 2, 3]))
assert.ok(s instanceof Set)
assert.strictEqual(s.size, 3)
assert.ok(s.has(1))
assert.ok(s.has(2))
assert.ok(s.has(3))
})
})
describe('round-trip via encode/decode', () => {
const opts = {
typeEncoders: { Set: setEncoder },
tags: { [TAG_SET]: setDecoder }
}
it('round-trips empty set', () => {
const s = new Set()
const result = decode(encode(s, opts), opts)
assert.ok(result instanceof Set)
assert.strictEqual(result.size, 0)
})
it('round-trips set with primitives', () => {
const s = new Set([1, 2, 3, 'a', 'b'])
const result = decode(encode(s, opts), opts)
assert.ok(result instanceof Set)
assert.strictEqual(result.size, 5)
assert.ok(result.has(1))
assert.ok(result.has('a'))
})
it('round-trips set with nested objects', () => {
const s = new Set([{ x: 1 }, { y: 2 }])
const result = decode(encode(s, opts), opts)
assert.strictEqual(result.size, 2)
const arr = [...result]
assert.deepStrictEqual(arr[0], { x: 1 })
assert.deepStrictEqual(arr[1], { y: 2 })
})
})
})
describe('Map (Tag 259)', () => {
describe('mapEncoder', () => {
it('encodes empty map', () => {
const tokens = mapEncoder(new Map(), 'Map', {})
assert.strictEqual(tokens[0].value, TAG_MAP)
assert.strictEqual(tokens[1].value, 0) // map length 0
})
})
describe('mapDecoder', () => {
it('decodes entries as Map', () => {
const result = mapDecoder(mockDecode(null, [['a', 1]]))
assert.ok(result instanceof Map)
assert.strictEqual(result.get('a'), 1)
})
it('decodes multiple entries as Map', () => {
const result = mapDecoder(mockDecode(null, [['a', 1], ['b', 2]]))
assert.ok(result instanceof Map)
assert.strictEqual(result.get('a'), 1)
assert.strictEqual(result.get('b'), 2)
})
it('preserves non-string keys', () => {
const result = mapDecoder(mockDecode(null, [[1, 'one'], [2, 'two']]))
assert.ok(result instanceof Map)
assert.strictEqual(result.get(1), 'one')
assert.strictEqual(result.get(2), 'two')
})
})
describe('round-trip via encode/decode', () => {
const opts = {
typeEncoders: { Map: mapEncoder },
tags: { [TAG_MAP]: mapDecoder }
// useMaps not needed - mapDecoder uses decode.entries() to preserve key types
}
it('round-trips empty map', () => {
const m = new Map()
const result = decode(encode(m, opts), opts)
assert.ok(result instanceof Map)
assert.strictEqual(result.size, 0)
})
it('round-trips map with string keys', () => {
const m = new Map([['a', 1], ['b', 2]])
const result = decode(encode(m, opts), opts)
assert.ok(result instanceof Map)
assert.strictEqual(result.get('a'), 1)
assert.strictEqual(result.get('b'), 2)
})
it('round-trips map with number keys', () => {
const m = new Map([[1, 'one'], [2, 'two']])
const result = decode(encode(m, opts), opts)
assert.ok(result instanceof Map)
assert.strictEqual(result.get(1), 'one')
assert.strictEqual(result.get(2), 'two')
})
})
})
describe('TypedArrays', () => {
describe('Uint8Array', () => {
const opts = {
typeEncoders: { Uint8Array: uint8ArrayEncoder },
tags: { [TAG_UINT8_ARRAY]: uint8ArrayDecoder }
}
it('encodes with tag 64', () => {
const tokens = uint8ArrayEncoder(new Uint8Array([1, 2, 3]))
assert.strictEqual(tokens[0].value, TAG_UINT8_ARRAY)
})
it('round-trips', () => {
const arr = new Uint8Array([1, 2, 3, 4, 5])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Uint8Array)
assert.deepStrictEqual([...result], [1, 2, 3, 4, 5])
})
it('round-trips view of larger buffer', () => {
const buffer = new ArrayBuffer(100)
const view = new Uint8Array(buffer, 10, 5)
view.set([1, 2, 3, 4, 5])
const result = decode(encode(view, opts), opts)
assert.strictEqual(result.length, 5)
assert.deepStrictEqual([...result], [1, 2, 3, 4, 5])
})
})
describe('Uint8ClampedArray', () => {
const opts = {
typeEncoders: { Uint8ClampedArray: uint8ClampedArrayEncoder },
tags: { [TAG_UINT8_CLAMPED_ARRAY]: uint8ClampedArrayDecoder }
}
it('round-trips', () => {
const arr = new Uint8ClampedArray([0, 128, 255])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Uint8ClampedArray)
assert.deepStrictEqual([...result], [0, 128, 255])
})
})
describe('Int8Array', () => {
const opts = {
typeEncoders: { Int8Array: int8ArrayEncoder },
tags: { [TAG_INT8_ARRAY]: int8ArrayDecoder }
}
it('round-trips', () => {
const arr = new Int8Array([-128, 0, 127])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Int8Array)
assert.deepStrictEqual([...result], [-128, 0, 127])
})
})
describe('Uint16Array', () => {
const opts = {
typeEncoders: { Uint16Array: uint16ArrayEncoder },
tags: { [TAG_UINT16_ARRAY_LE]: uint16ArrayDecoder }
}
it('round-trips', () => {
const arr = new Uint16Array([0, 256, 65535])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Uint16Array)
assert.deepStrictEqual([...result], [0, 256, 65535])
})
})
describe('Uint32Array', () => {
const opts = {
typeEncoders: { Uint32Array: uint32ArrayEncoder },
tags: { [TAG_UINT32_ARRAY_LE]: uint32ArrayDecoder }
}
it('round-trips', () => {
const arr = new Uint32Array([0, 65536, 4294967295])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Uint32Array)
assert.deepStrictEqual([...result], [0, 65536, 4294967295])
})
})
describe('Int16Array', () => {
const opts = {
typeEncoders: { Int16Array: int16ArrayEncoder },
tags: { [TAG_INT16_ARRAY_LE]: int16ArrayDecoder }
}
it('round-trips', () => {
const arr = new Int16Array([-32768, 0, 32767])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Int16Array)
assert.deepStrictEqual([...result], [-32768, 0, 32767])
})
})
describe('Int32Array', () => {
const opts = {
typeEncoders: { Int32Array: int32ArrayEncoder },
tags: { [TAG_INT32_ARRAY_LE]: int32ArrayDecoder }
}
it('round-trips', () => {
const arr = new Int32Array([-2147483648, 0, 2147483647])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Int32Array)
assert.deepStrictEqual([...result], [-2147483648, 0, 2147483647])
})
})
describe('Float32Array', () => {
const opts = {
typeEncoders: { Float32Array: float32ArrayEncoder },
tags: { [TAG_FLOAT32_ARRAY_LE]: float32ArrayDecoder }
}
it('round-trips', () => {
const arr = new Float32Array([1.5, -2.5, 3.14])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Float32Array)
// Float32 has limited precision
assert.strictEqual(result[0], 1.5)
assert.strictEqual(result[1], -2.5)
assert.ok(Math.abs(result[2] - 3.14) < 0.001)
})
})
describe('Float64Array', () => {
const opts = {
typeEncoders: { Float64Array: float64ArrayEncoder },
tags: { [TAG_FLOAT64_ARRAY_LE]: float64ArrayDecoder }
}
it('round-trips', () => {
const arr = new Float64Array([1.1, -2.2, Math.PI, Infinity, -Infinity])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof Float64Array)
assert.deepStrictEqual([...result], [1.1, -2.2, Math.PI, Infinity, -Infinity])
})
})
describe('BigUint64Array', () => {
const opts = {
typeEncoders: { BigUint64Array: bigUint64ArrayEncoder },
tags: { [TAG_BIGUINT64_ARRAY_LE]: bigUint64ArrayDecoder }
}
it('round-trips', () => {
const arr = new BigUint64Array([0n, 1n, BigInt('18446744073709551615')])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof BigUint64Array)
assert.deepStrictEqual([...result], [0n, 1n, BigInt('18446744073709551615')])
})
})
describe('BigInt64Array', () => {
const opts = {
typeEncoders: { BigInt64Array: bigInt64ArrayEncoder },
tags: { [TAG_BIGINT64_ARRAY_LE]: bigInt64ArrayDecoder }
}
it('round-trips', () => {
const arr = new BigInt64Array([BigInt('-9223372036854775808'), 0n, BigInt('9223372036854775807')])
const result = decode(encode(arr, opts), opts)
assert.ok(result instanceof BigInt64Array)
assert.deepStrictEqual([...result], [BigInt('-9223372036854775808'), 0n, BigInt('9223372036854775807')])
})
})
})
})
/**
* Encode a value to CBOR with extended JavaScript type support.
*
* Supported types beyond standard cborg:
* - Date (Tag 1)
* - RegExp (Tag 21066)
* - Map (Tag 259)
* - Set (Tag 258)
* - BigInt (Tags 2/3, always tagged)
* - All TypedArrays (Tags 64-87)
*
* @param {any} obj - Value to encode
* @param {EncodeOptions} [options] - Additional options (merged with extended defaults)
* @returns {Uint8Array}
*/
export function encode(obj: any, options?: EncodeOptions): Uint8Array;
/**
* Decode CBOR to a value with extended JavaScript type support.
*
* @param {Uint8Array} data - CBOR data to decode
* @param {DecodeOptions} [options] - Additional options (merged with extended defaults)
* @returns {any}
*/
export function decode(data: Uint8Array, options?: DecodeOptions): any;
export type EncodeOptions = import("../../interface.js").EncodeOptions;
export type DecodeOptions = import("../../interface.js").DecodeOptions;
import { TAG_DATE_EPOCH } from '../taglib.js';
import { TAG_BIGINT_POS } from '../taglib.js';
import { TAG_BIGINT_NEG } from '../taglib.js';
import { TAG_UINT8_ARRAY } from '../taglib.js';
import { TAG_UINT8_CLAMPED_ARRAY } from '../taglib.js';
import { TAG_INT8_ARRAY } from '../taglib.js';
import { TAG_UINT16_ARRAY_LE } from '../taglib.js';
import { TAG_UINT32_ARRAY_LE } from '../taglib.js';
import { TAG_BIGUINT64_ARRAY_LE } from '../taglib.js';
import { TAG_INT16_ARRAY_LE } from '../taglib.js';
import { TAG_INT32_ARRAY_LE } from '../taglib.js';
import { TAG_BIGINT64_ARRAY_LE } from '../taglib.js';
import { TAG_FLOAT32_ARRAY_LE } from '../taglib.js';
import { TAG_FLOAT64_ARRAY_LE } from '../taglib.js';
import { TAG_SET } from '../taglib.js';
import { TAG_MAP } from '../taglib.js';
import { TAG_REGEXP } from '../taglib.js';
import { structBigIntEncoder } from '../taglib.js';
import { bigIntDecoder } from '../taglib.js';
import { bigNegIntDecoder } from '../taglib.js';
import { dateEncoder } from '../taglib.js';
import { dateDecoder } from '../taglib.js';
import { regExpEncoder } from '../taglib.js';
import { regExpDecoder } from '../taglib.js';
import { setEncoder } from '../taglib.js';
import { setDecoder } from '../taglib.js';
import { mapEncoder } from '../taglib.js';
import { mapDecoder } from '../taglib.js';
import { uint8ArrayEncoder } from '../taglib.js';
import { uint8ArrayDecoder } from '../taglib.js';
import { uint8ClampedArrayEncoder } from '../taglib.js';
import { uint8ClampedArrayDecoder } from '../taglib.js';
import { int8ArrayEncoder } from '../taglib.js';
import { int8ArrayDecoder } from '../taglib.js';
import { uint16ArrayEncoder } from '../taglib.js';
import { uint16ArrayDecoder } from '../taglib.js';
import { uint32ArrayEncoder } from '../taglib.js';
import { uint32ArrayDecoder } from '../taglib.js';
import { int16ArrayEncoder } from '../taglib.js';
import { int16ArrayDecoder } from '../taglib.js';
import { int32ArrayEncoder } from '../taglib.js';
import { int32ArrayDecoder } from '../taglib.js';
import { float32ArrayEncoder } from '../taglib.js';
import { float32ArrayDecoder } from '../taglib.js';
import { float64ArrayEncoder } from '../taglib.js';
import { float64ArrayDecoder } from '../taglib.js';
import { bigUint64ArrayEncoder } from '../taglib.js';
import { bigUint64ArrayDecoder } from '../taglib.js';
import { bigInt64ArrayEncoder } from '../taglib.js';
import { bigInt64ArrayDecoder } from '../taglib.js';
export { TAG_DATE_EPOCH, TAG_BIGINT_POS, TAG_BIGINT_NEG, TAG_UINT8_ARRAY, TAG_UINT8_CLAMPED_ARRAY, TAG_INT8_ARRAY, TAG_UINT16_ARRAY_LE, TAG_UINT32_ARRAY_LE, TAG_BIGUINT64_ARRAY_LE, TAG_INT16_ARRAY_LE, TAG_INT32_ARRAY_LE, TAG_BIGINT64_ARRAY_LE, TAG_FLOAT32_ARRAY_LE, TAG_FLOAT64_ARRAY_LE, TAG_SET, TAG_MAP, TAG_REGEXP, structBigIntEncoder, bigIntDecoder, bigNegIntDecoder, dateEncoder, dateDecoder, regExpEncoder, regExpDecoder, setEncoder, setDecoder, mapEncoder, mapDecoder, uint8ArrayEncoder, uint8ArrayDecoder, uint8ClampedArrayEncoder, uint8ClampedArrayDecoder, int8ArrayEncoder, int8ArrayDecoder, uint16ArrayEncoder, uint16ArrayDecoder, uint32ArrayEncoder, uint32ArrayDecoder, int16ArrayEncoder, int16ArrayDecoder, int32ArrayEncoder, int32ArrayDecoder, float32ArrayEncoder, float32ArrayDecoder, float64ArrayEncoder, float64ArrayDecoder, bigUint64ArrayEncoder, bigUint64ArrayDecoder, bigInt64ArrayEncoder, bigInt64ArrayDecoder };
//# sourceMappingURL=extended.d.ts.map
{"version":3,"file":"extended.d.ts","sourceRoot":"","sources":["../../../lib/extended/extended.js"],"names":[],"mappings":"AAiJA;;;;;;;;;;;;;;GAcG;AACH,4BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAQtB;AAED;;;;;;GAMG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CASf;4BA/FY,OAAO,oBAAoB,EAAE,aAAa;4BAC1C,OAAO,oBAAoB,EAAE,aAAa;+BAJhD,cAAc;+BAAd,cAAc;+BAAd,cAAc;gCAAd,cAAc;wCAAd,cAAc;+BAAd,cAAc;oCAAd,cAAc;oCAAd,cAAc;uCAAd,cAAc;mCAAd,cAAc;mCAAd,cAAc;sCAAd,cAAc;qCAAd,cAAc;qCAAd,cAAc;wBAAd,cAAc;wBAAd,cAAc;2BAAd,cAAc;oCAAd,cAAc;8BAAd,cAAc;iCAAd,cAAc;4BAAd,cAAc;4BAAd,cAAc;8BAAd,cAAc;8BAAd,cAAc;2BAAd,cAAc;2BAAd,cAAc;2BAAd,cAAc;2BAAd,cAAc;kCAAd,cAAc;kCAAd,cAAc;yCAAd,cAAc;yCAAd,cAAc;iCAAd,cAAc;iCAAd,cAAc;mCAAd,cAAc;mCAAd,cAAc;mCAAd,cAAc;mCAAd,cAAc;kCAAd,cAAc;kCAAd,cAAc;kCAAd,cAAc;kCAAd,cAAc;oCAAd,cAAc;oCAAd,cAAc;oCAAd,cAAc;oCAAd,cAAc;sCAAd,cAAc;sCAAd,cAAc;qCAAd,cAAc;qCAAd,cAAc"}
/**
* Decode a positive bignum from bytes (Tag 2)
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {bigint}
*/
export function bigIntDecoder(decode: import("../interface.js").TagDecodeControl): bigint;
/**
* Encode a BigInt, only using tags for values outside 64-bit range (IPLD compatible)
* @param {bigint} obj
* @returns {Token[]|null}
*/
export function bigIntEncoder(obj: bigint): Token[] | null;
/**
* Encode a BigInt, always using tags 2/3 (for extended mode, full round-trip fidelity)
* @param {bigint} obj
* @returns {Token[]}
*/
export function structBigIntEncoder(obj: bigint): Token[];
/**
* Decode a negative bignum from bytes (Tag 3)
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {bigint}
*/
export function bigNegIntDecoder(decode: import("../interface.js").TagDecodeControl): bigint;
/**
* Encode a Date as Tag 1 (epoch seconds as float)
* @param {Date} date
* @returns {Token[]}
*/
export function dateEncoder(date: Date): Token[];
/**
* Decode Tag 1 (epoch seconds) to a Date
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Date}
*/
export function dateDecoder(decode: import("../interface.js").TagDecodeControl): Date;
/**
* Encode a RegExp as Tag 21066
* @param {RegExp} re
* @returns {Token[]}
*/
export function regExpEncoder(re: RegExp): Token[];
/**
* Decode Tag 21066 to a RegExp
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {RegExp}
*/
export function regExpDecoder(decode: import("../interface.js").TagDecodeControl): RegExp;
/**
* Encode a Set as Tag 258 + array
* This is a typeEncoder, receives (obj, typ, options, refStack)
* @param {Set<any>} set
* @param {string} _typ
* @param {import('../interface.js').EncodeOptions} options
* @param {import('../interface.js').Reference} [refStack]
* @returns {import('../interface.js').TokenOrNestedTokens[]}
*/
export function setEncoder(set: Set<any>, _typ: string, options: import("../interface.js").EncodeOptions, refStack?: import("../interface.js").Reference): import("../interface.js").TokenOrNestedTokens[];
/**
* Decode Tag 258 to a Set
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Set<any>}
*/
export function setDecoder(decode: import("../interface.js").TagDecodeControl): Set<any>;
/**
* Encode a Map as Tag 259 + CBOR map
* This is a typeEncoder, receives (obj, typ, options, refStack)
* @param {Map<any, any>} map
* @param {string} _typ
* @param {import('../interface.js').EncodeOptions} options
* @param {import('../interface.js').Reference} [refStack]
* @returns {import('../interface.js').TokenOrNestedTokens[]}
*/
export function mapEncoder(map: Map<any, any>, _typ: string, options: import("../interface.js").EncodeOptions, refStack?: import("../interface.js").Reference): import("../interface.js").TokenOrNestedTokens[];
/**
* Decode Tag 259 to a Map
* Uses decode.entries() to preserve key types (integers, etc.) regardless of useMaps setting
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Map<any, any>}
*/
export function mapDecoder(decode: import("../interface.js").TagDecodeControl): Map<any, any>;
/**
* Encode an Error as Tag 27: [className, message]
* @param {Error} err
* @returns {Token[]}
*/
export function errorEncoder(err: Error): Token[];
/**
* Decode Tag 27 to an Error (or Error subclass)
* @param {import('../interface.js').TagDecodeControl} decode
* @returns {Error}
*/
export function errorDecoder(decode: import("../interface.js").TagDecodeControl): Error;
/**
* Encode a number, preserving -0 as a float
* Use this as a typeEncoder for 'number' to preserve -0 fidelity
* @param {number} num
* @returns {Token[] | null}
*/
export function negativeZeroEncoder(num: number): Token[] | null;
export const TAG_DATE_STRING: 0;
export const TAG_DATE_EPOCH: 1;
export const TAG_BIGINT_POS: 2;
export const TAG_BIGINT_NEG: 3;
export const TAG_UINT8_ARRAY: 64;
export const TAG_UINT8_CLAMPED_ARRAY: 68;
export const TAG_INT8_ARRAY: 72;
export const TAG_UINT16_ARRAY_LE: 69;
export const TAG_UINT32_ARRAY_LE: 70;
export const TAG_BIGUINT64_ARRAY_LE: 71;
export const TAG_INT16_ARRAY_LE: 77;
export const TAG_INT32_ARRAY_LE: 78;
export const TAG_BIGINT64_ARRAY_LE: 79;
export const TAG_FLOAT32_ARRAY_LE: 85;
export const TAG_FLOAT64_ARRAY_LE: 86;
export const TAG_OBJECT_CLASS: 27;
export const TAG_SET: 258;
export const TAG_MAP: 259;
export const TAG_REGEXP: 21066;
export const uint8ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const uint8ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Uint8Array<ArrayBuffer>;
export const uint8ClampedArrayEncoder: (arr: ArrayBufferView) => Token[];
export const uint8ClampedArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Uint8ClampedArray<ArrayBuffer>;
export const int8ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const int8ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Int8Array<ArrayBuffer>;
export const uint16ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const uint16ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Uint16Array<ArrayBuffer>;
export const uint32ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const uint32ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Uint32Array<ArrayBuffer>;
export const bigUint64ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const bigUint64ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => BigUint64Array<ArrayBuffer>;
export const int16ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const int16ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Int16Array<ArrayBuffer>;
export const int32ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const int32ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Int32Array<ArrayBuffer>;
export const bigInt64ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const bigInt64ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => BigInt64Array<ArrayBuffer>;
export const float32ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const float32ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Float32Array<ArrayBuffer>;
export const float64ArrayEncoder: (arr: ArrayBufferView) => Token[];
export const float64ArrayDecoder: (decode: import("../interface.js").TagDecodeControl) => Float64Array<ArrayBuffer>;
import { Token } from '../cborg.js';
//# sourceMappingURL=taglib.d.ts.map
{"version":3,"file":"taglib.d.ts","sourceRoot":"","sources":["../../lib/taglib.js"],"names":[],"mappings":"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"}
+4
-0

@@ -10,2 +10,4 @@ version: 2

include: 'scope'
cooldown:
default-days: 5
- package-ecosystem: 'npm'

@@ -18,1 +20,3 @@ directory: '/'

include: 'scope'
cooldown:
default-days: 5
+2
-4

@@ -15,3 +15,3 @@ name: Test & Maybe Release

- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v6.2.0
uses: actions/setup-node@v6.3.0
with:

@@ -26,4 +26,2 @@ node-version: ${{ matrix.node }}

npm run test:ci
- name: Typecheck
uses: gozala/typescript-error-reporter-action@v1.0.9
release:

@@ -45,3 +43,3 @@ name: Release

- name: Setup Node.js
uses: actions/setup-node@v6.2.0
uses: actions/setup-node@v6.3.0
with:

@@ -48,0 +46,0 @@ node-version: lts/*

@@ -7,7 +7,7 @@ import { encode, encodeInto, rfc8949EncodeOptions } from './lib/encode.js'

* Export the types that were present in the original manual cborg.d.ts
* @typedef {import('./interface').TagDecoder} TagDecoder
* @typedef {import('./interface.js').TagDecoder} TagDecoder
* There was originally just `TypeEncoder` so don't break types by renaming or not exporting
* @typedef {import('./interface').OptionalTypeEncoder} TypeEncoder
* @typedef {import('./interface').DecodeOptions} DecodeOptions
* @typedef {import('./interface').EncodeOptions} EncodeOptions
* @typedef {import('./interface.js').OptionalTypeEncoder} TypeEncoder
* @typedef {import('./interface.js').DecodeOptions} DecodeOptions
* @typedef {import('./interface.js').EncodeOptions} EncodeOptions
*/

@@ -14,0 +14,0 @@

@@ -0,1 +1,45 @@

## [5.0.0](https://github.com/rvagg/cborg/compare/v4.5.8...v5.0.0) (2026-03-31)
### ⚠ BREAKING CHANGES
* **extended:** Tag decoder signature changed from receiving the decoded
value to receiving a decode control object. See migration guide below.
Add new `cborg/extended` entry point providing encode/decode with built-in
support for Date, RegExp, Set, Map, BigInt, Error, and all TypedArrays using
standard CBOR tags. Type support is similar to the browser's structured
clone algorithm.
Key features:
- Date (Tag 1), RegExp (Tag 21066), Set (Tag 258), Map (Tag 259)
- BigInt always tagged (Tags 2/3) for round-trip fidelity
- All TypedArrays via RFC 8746 tags (64-87)
- Error types via Tag 27 (Error, TypeError, RangeError, etc.)
- Negative zero (-0) round-trips correctly
- Objects round-trip as objects, Maps round-trip as Maps
- Map and object key insertion order preserved (not sorted)
- Mixed structures like { myMap: new Map([[1, 'a']]) } work correctly
The Map/object fidelity is achieved through a new tag decoder API that
gives decoders control over how their content is decoded. Tag 259 (Map)
uses `decode.entries()` to preserve key types regardless of the `useMaps`
setting, while plain CBOR maps decode as objects.
Extends `cborg/taglib` with encoders and decoders for all supported types
(previously only BigInt). Moves taglib.js to lib/taglib.js for consistency
(external API unchanged via package.json exports).
Also fixes a bug in lib/7float.js where -0 lost its sign bit during
half-precision float encoding (bitwise ops on floats convert to int32).
### Features
* **extended:** add cborg/extended module with full JavaScript type fidelity ([#168](https://github.com/rvagg/cborg/issues/168)) ([652730e](https://github.com/rvagg/cborg/commit/652730e5477e90cb95da2bd2b7bb56d171532d6e))
### Trivial Changes
* **deps-dev:** bump typescript from 5.9.3 to 6.0.2 ([5382bfa](https://github.com/rvagg/cborg/commit/5382bfa267b8764047a4263d556e28c0a491c3d6))
* **deps:** bump actions/setup-node from 6.2.0 to 6.3.0 ([#171](https://github.com/rvagg/cborg/issues/171)) ([a2525b9](https://github.com/rvagg/cborg/commit/a2525b94ff8ae217cb572572e22cd46233d5f8b9))
* update deps and upgrade to typescript 6 ([463bdfd](https://github.com/rvagg/cborg/commit/463bdfdbe89702214f392b5b99693a26a0ce96a3))
## [4.5.8](https://github.com/rvagg/cborg/compare/v4.5.7...v4.5.8) (2026-01-21)

@@ -2,0 +46,0 @@

@@ -1,2 +0,2 @@

import { Token } from './lib/token'
import { Token } from './lib/token.js'

@@ -32,4 +32,16 @@ export type TokenOrNestedTokens = Token | Token[] | TokenOrNestedTokens[]

export type TagDecoder = (inner: any) => any
/**
* Control object passed to tag decoders, providing methods to decode the tagged content.
*/
export interface TagDecodeControl {
/** Decode the tagged content */
(): unknown
/** Decode CBOR map content as [key, value] entries array (preserves key types) */
entries(): Array<[unknown, unknown]>
/** @internal Track whether decode was called */
readonly _called?: boolean
}
export type TagDecoder = (decode: TagDecodeControl) => any
export interface DecodeOptions {

@@ -46,3 +58,3 @@ allowIndefinite?: boolean

retainStringBytes?: boolean
tags?: TagDecoder[],
tags?: { [tagNumber: number]: TagDecoder },
tokenizer?: DecodeTokenizer

@@ -49,0 +61,0 @@ }

@@ -9,4 +9,4 @@ /* globals BigInt */

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -13,0 +13,0 @@

@@ -8,4 +8,4 @@ /* eslint-env es2020 */

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -12,0 +12,0 @@

@@ -7,4 +7,4 @@ import { Token, Type } from './token.js'

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -11,0 +11,0 @@

@@ -13,4 +13,4 @@ import { Token, Type } from './token.js'

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -17,0 +17,0 @@

@@ -6,4 +6,4 @@ import { Token, Type } from './token.js'

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -10,0 +10,0 @@

@@ -6,4 +6,4 @@ import { Token, Type } from './token.js'

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -10,0 +10,0 @@

@@ -5,4 +5,4 @@ import { Token, Type } from './token.js'

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -9,0 +9,0 @@

@@ -9,5 +9,5 @@ // TODO: shift some of the bytes logic to bytes-utils so we can use Buffer

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface').EncodeOptions} EncodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').EncodeOptions} EncodeOptions
*/

@@ -199,3 +199,4 @@

// 0.0, -0.0 and subnormals, shouldn't be possible to get here because 0.0 should be counted as an int
dataView.setUint16(0, ((inp & 0x80000000) >> 16) | (mantissa >> 13), false)
// Use valu32 for sign bit since bitwise ops on floats lose -0 sign
dataView.setUint16(0, ((valu32 & 0x80000000) >> 16) | (mantissa >> 13), false)
} else { // standard numbers

@@ -202,0 +203,0 @@ // chunks of logic here borrowed from https://github.com/PJK/libcbor/blob/c78f437182533e3efa8d963ff4b945bb635c2284/src/cbor/encoding.c#L127

@@ -8,4 +8,5 @@ import { decodeErrPrefix } from './common.js'

* @typedef {import('./token.js').Token} Token
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface').DecodeTokenizer} DecodeTokenizer
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').DecodeTokenizer} DecodeTokenizer
* @typedef {import('../interface.js').TagDecodeControl} TagDecodeControl
*/

@@ -138,4 +139,89 @@

/**
* Generator that yields [key, value] entries from a CBOR map token.
* Used by tag decoders that need to preserve key types (e.g., Tag 259 Map).
* @param {Token} token - The map token
* @param {DecodeTokenizer} tokeniser
* @param {DecodeOptions} options
* @returns {Generator<[any, any], void, unknown>}
*/
function * tokenToMapEntries (token, tokeniser, options) {
for (let i = 0; i < token.value; i++) {
const key = tokensToObject(tokeniser, options)
if (key === BREAK) {
if (token.value === Infinity) {
// normal end to indefinite length map
break
}
throw new Error(`${decodeErrPrefix} got unexpected break to lengthed map`)
}
if (key === DONE) {
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no key], expected ${token.value})`)
}
const value = tokensToObject(tokeniser, options)
if (value === DONE) {
throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${i} [no value], expected ${token.value})`)
}
yield [key, value]
}
}
/**
* Creates a TagDecodeControl object for tag decoders.
* @param {DecodeTokenizer} tokeniser
* @param {DecodeOptions} options
* @returns {TagDecodeControl}
*/
function createTagDecodeControl (tokeniser, options) {
let called = false
/**
* @type {TagDecodeControl}
*/
const decode = function () {
if (called) {
throw new Error(`${decodeErrPrefix} tag decode() may only be called once`)
}
called = true
const value = tokensToObject(tokeniser, options)
if (value === DONE) {
throw new Error(`${decodeErrPrefix} tag content missing`)
}
if (value === BREAK) {
throw new Error(`${decodeErrPrefix} got unexpected break in tag content`)
}
return value
}
decode.entries = function () {
if (called) {
throw new Error(`${decodeErrPrefix} tag decode() may only be called once`)
}
called = true
// Get the next token and ensure it's a map
const token = tokeniser.next()
if (!Type.equals(token.type, Type.map)) {
throw new Error(`${decodeErrPrefix} entries() requires map content, got ${token.type.name}`)
}
// Collect all entries into an array (ensures full content consumption)
const entries = []
for (const entry of tokenToMapEntries(token, tokeniser, options)) {
entries.push(entry)
}
return entries
}
// For internal tracking
Object.defineProperty(decode, '_called', {
get () { return called },
enumerable: false
})
return decode
}
/**
* @param {DecodeTokenizer} tokeniser
* @param {DecodeOptions} options
* @returns {any|BREAK|DONE}

@@ -170,4 +256,8 @@ */

if (options.tags && typeof options.tags[token.value] === 'function') {
const tagged = tokensToObject(tokeniser, options)
return options.tags[token.value](tagged)
const decodeControl = createTagDecodeControl(tokeniser, options)
const result = options.tags[token.value](decodeControl)
if (!decodeControl._called) {
throw new Error(`${decodeErrPrefix} tag decoder must call decode() or entries()`)
}
return result
}

@@ -174,0 +264,0 @@ throw new Error(`${decodeErrPrefix} tag not supported (${token.value})`)

@@ -18,9 +18,9 @@ import { is } from './is.js'

/**
* @typedef {import('../interface').EncodeOptions} EncodeOptions
* @typedef {import('../interface').OptionalTypeEncoder} OptionalTypeEncoder
* @typedef {import('../interface').Reference} Reference
* @typedef {import('../interface').StrictTypeEncoder} StrictTypeEncoder
* @typedef {import('../interface').TokenTypeEncoder} TokenTypeEncoder
* @typedef {import('../interface').TokenOrNestedTokens} TokenOrNestedTokens
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface.js').EncodeOptions} EncodeOptions
* @typedef {import('../interface.js').OptionalTypeEncoder} OptionalTypeEncoder
* @typedef {import('../interface.js').Reference} Reference
* @typedef {import('../interface.js').StrictTypeEncoder} StrictTypeEncoder
* @typedef {import('../interface.js').TokenTypeEncoder} TokenTypeEncoder
* @typedef {import('../interface.js').TokenOrNestedTokens} TokenOrNestedTokens
* @typedef {import('../interface.js').ByteWriter} ByteWriter
*/

@@ -27,0 +27,0 @@

@@ -7,4 +7,4 @@ import { decode as _decode, decodeFirst as _decodeFirst } from '../decode.js'

/**
* @typedef {import('../../interface').DecodeOptions} DecodeOptions
* @typedef {import('../../interface').DecodeTokenizer} DecodeTokenizer
* @typedef {import('../../interface.js').DecodeOptions} DecodeOptions
* @typedef {import('../../interface.js').DecodeTokenizer} DecodeTokenizer
*/

@@ -11,0 +11,0 @@

@@ -7,5 +7,5 @@ import { Type } from '../token.js'

/**
* @typedef {import('../../interface').EncodeOptions} EncodeOptions
* @typedef {import('../../interface').ByteWriter} ByteWriter
* @typedef {import('../token').Token} Token
* @typedef {import('../../interface.js').EncodeOptions} EncodeOptions
* @typedef {import('../../interface.js').ByteWriter} ByteWriter
* @typedef {import('../token.js').Token} Token
*/

@@ -12,0 +12,0 @@

@@ -14,3 +14,3 @@ import { Token, Type } from './token.js'

/**
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -17,0 +17,0 @@

@@ -5,5 +5,5 @@ import { makeCborEncoders, objectToTokens } from './encode.js'

/**
* @typedef {import('../interface').EncodeOptions} EncodeOptions
* @typedef {import('../interface').TokenTypeEncoder} TokenTypeEncoder
* @typedef {import('../interface').TokenOrNestedTokens} TokenOrNestedTokens
* @typedef {import('../interface.js').EncodeOptions} EncodeOptions
* @typedef {import('../interface.js').TokenTypeEncoder} TokenTypeEncoder
* @typedef {import('../interface.js').TokenOrNestedTokens} TokenOrNestedTokens
*/

@@ -10,0 +10,0 @@

{
"name": "cborg",
"version": "4.5.8",
"version": "5.0.0",
"description": "Fast CBOR with a focus on strictness",

@@ -33,19 +33,19 @@ "main": "cborg.js",

"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^13.0.0",
"@semantic-release/commit-analyzer": "^13.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^12.0.0",
"@semantic-release/npm": "^13.0.0",
"@semantic-release/release-notes-generator": "^14.0.1",
"@types/chai": "^5.0.0",
"@types/mocha": "^10.0.8",
"@types/node": "^25.0.0",
"c8": "^10.1.2",
"chai": "^6.0.1",
"conventional-changelog-conventionalcommits": "^9.0.0",
"@semantic-release/github": "^12.0.6",
"@semantic-release/npm": "^13.1.5",
"@semantic-release/release-notes-generator": "^14.1.0",
"@types/chai": "^5.2.3",
"@types/mocha": "^10.0.10",
"@types/node": "^25.5.0",
"c8": "^11.0.0",
"chai": "^6.2.2",
"conventional-changelog-conventionalcommits": "^9.3.0",
"ipld-garbage": "^5.0.0",
"mocha": "^11.0.1",
"polendina": "^3.2.2",
"semantic-release": "^25.0.0",
"mocha": "^11.7.5",
"polendina": "^3.2.20",
"semantic-release": "^25.0.3",
"standard": "^17.1.2",
"typescript": "^5.6.2"
"typescript": "^6.0.2"
},

@@ -62,4 +62,4 @@ "exports": {

"./taglib": {
"import": "./taglib.js",
"types": "./types/taglib.d.ts"
"import": "./lib/taglib.js",
"types": "./types/lib/taglib.d.ts"
},

@@ -70,2 +70,6 @@ "./json": {

},
"./extended": {
"import": "./lib/extended/extended.js",
"types": "./types/lib/extended/extended.d.ts"
},
"./interface": {

@@ -72,0 +76,0 @@ "types": "./types/interface.d.ts"

+213
-9

@@ -42,2 +42,10 @@ # cborg - fast CBOR with a focus on strictness

* [Advanced types and tags](#advanced-types-and-tags)
* [Extended JavaScript types (`cborg/extended`)](#extended-javascript-types-cborgextended)
* [When to use `cborg/extended`](#when-to-use-cborgextended)
* [Supported types](#supported-types)
* [Type fidelity: objects vs Maps](#type-fidelity-objects-vs-maps)
* [Interoperability](#interoperability)
* [Selective type support (`cborg/taglib`)](#selective-type-support-cborgtaglib)
* [`cborg/extended` vs `cborg/taglib`](#cborgextended-vs-cborgtaglib)
* [Available exports](#available-exports)
* [License and Copyright](#license-and-copyright)

@@ -384,10 +392,15 @@

By default cborg does not support decoding of any tags. Where a tag is encountered during decode, an error will be thrown. If tag support is needed, they will need to be supplied as options to the `decode()` function. The `tags` property should contain an array where the indexes correspond to the tag numbers that are encountered during decode, and the values are functions that are able to turn the following token(s) into a JavaScript object. Each tag token in CBOR is followed by a data item, often a byte array of arbitrary length, but can be a more complex series of tokens that form a nested data item. This token is supplied to the tag decoder function.
By default cborg does not support decoding of any tags. Where a tag is encountered during decode, an error will be thrown. If tag support is needed, they will need to be supplied as options to the `decode()` function. The `tags` property should contain an object mapping tag numbers to decoder functions.
This example is available from the cborg taglib as `bigIntDecoder` and `bigNegIntDecoder` (`import { bigIntDecoder, bigNegIntDecoder } as taglib from 'cborg/taglib'`) and implements CBOR tags 2 and 3 (bigint and negative bigint). This function would be registered using an options parameter:
Tag decoder functions receive a `decode` control object with two methods:
- `decode()`: decode the tagged content and return it
- `decode.entries()`: for map content, returns `[[key, value], ...]` preserving key types
This example is available from the cborg taglib as `bigIntDecoder` and `bigNegIntDecoder` (`import { bigIntDecoder, bigNegIntDecoder } from 'cborg/taglib'`) and implements CBOR tags 2 and 3 (bigint and negative bigint). This function would be registered using an options parameter:
```js
const tags = []
tags[2] = bigIntDecoder
tags[3] = bigNegIntDecoder
const tags = {
2: bigIntDecoder,
3: bigNegIntDecoder
}

@@ -400,3 +413,4 @@ decode(bytes, { tags })

```js
function bigIntDecoder (bytes) {
function bigIntDecoder (decode) {
const bytes = decode() // get the tagged byte content
let bi = 0n

@@ -409,7 +423,21 @@ for (let ii = 0; ii < bytes.length; ii++) {

function bigNegIntDecoder (bytes) {
return -1n - bigIntDecoder(bytes)
function bigNegIntDecoder (decode) {
const bytes = decode()
let bi = 0n
for (let ii = 0; ii < bytes.length; ii++) {
bi = (bi << 8n) + BigInt(bytes[ii])
}
return -1n - bi
}
```
For tags that wrap CBOR maps and need to preserve non-string key types, use `decode.entries()`:
```js
// Tag 259: Map with any key type
function mapDecoder (decode) {
return new Map(decode.entries())
}
```
## Decoding with a custom tokeniser

@@ -473,3 +501,3 @@

By default, cborg allows for some flexibility on **decode** of objects, which will present some challenges if users wish to impose strictness requirements at both serialization _and_ deserialization. Options that can be provided to `decode()` to impose some strictness requirements are:
By default, cborg allows for some flexibility on **decode** of objects, which will present some challenges if users wish to impose strictness requirements at both serialisation _and_ deserialisation. Options that can be provided to `decode()` to impose some strictness requirements are:

@@ -555,2 +583,178 @@ * `strict: true` to impose strict sizing rules for int, negative ints and lengths of lengthed objects

## Extended JavaScript types (`cborg/extended`)
Need to serialise `Date`, `Map`, `Set`, `RegExp`, `BigInt`, `Error`, or `TypedArray`? The `cborg/extended` module provides encode/decode with built-in support for native JavaScript types that JSON can't handle.
The type support is similar to the browser's **[structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm)**, the built-in deep-copy mechanism that handles these same types. `cborg/extended` provides similar type fidelity in a compact binary serialisation format.
See [example-extended.js](./example-extended.js) for a runnable demo.
```js
import { encode, decode } from 'cborg/extended'
const data = {
date: new Date(),
pattern: /foo.*bar/gi,
mapping: new Map([['key', 'value'], [42, 'number key']]),
collection: new Set([1, 2, 3]),
binary: new Uint16Array([1, 2, 3]),
bignum: 12345678901234567890n,
error: new TypeError('something went wrong')
}
const encoded = encode(data)
const decoded = decode(encoded)
// All types are preserved
decoded.date instanceof Date // true
decoded.pattern instanceof RegExp // true
decoded.mapping instanceof Map // true
decoded.collection instanceof Set // true
decoded.binary instanceof Uint16Array // true
typeof decoded.bignum === 'bigint' // true
decoded.error instanceof TypeError // true
```
### When to use `cborg/extended`
Use `cborg/extended` instead of base `cborg` or JSON when you need:
- **Date serialisation**: JSON requires manual `toISOString()`/`new Date()` conversion
- **BigInt support**: JSON throws on BigInt; base cborg only preserves BigInts outside 64-bit range
- **Map with non-string keys**: `new Map([[1, 'one'], [{}, 'object key']])` just works
- **Set preservation**: Sets round-trip as Sets, not Arrays
- **TypedArray types**: `Float32Array` stays `Float32Array`, not `Uint8Array`
- **Error serialisation**: `Error`, `TypeError`, `RangeError`, etc. preserve type and message
- **Negative zero**: `-0` round-trips correctly (base cborg encodes as `0`)
- **Insertion order**: Map and object key order is preserved (not sorted)
- **Binary efficiency**: ~30-50% smaller than JSON for typical data
### Supported types
| Type | CBOR Tag | Notes |
|------|----------|-------|
| `Date` | 1 | Epoch seconds as float (millisecond precision) |
| `RegExp` | 21066 | Pattern and flags preserved |
| `Set` | 258 | IANA registered finite set |
| `Map` | 259 | Supports any key type |
| `BigInt` | 2, 3 | Always tagged for round-trip fidelity |
| `Error` | 27 | All standard error types (`TypeError`, `RangeError`, etc.) |
| `-0` | *(float)* | Negative zero encoded as half-precision float |
| `Uint8Array` | 64 | RFC 8746 |
| `Uint8ClampedArray` | 68 | RFC 8746 |
| `Int8Array` | 72 | RFC 8746 |
| `Uint16Array` | 69 | RFC 8746 (little-endian) |
| `Int16Array` | 77 | RFC 8746 (little-endian) |
| `Uint32Array` | 70 | RFC 8746 (little-endian) |
| `Int32Array` | 78 | RFC 8746 (little-endian) |
| `Float32Array` | 85 | RFC 8746 (little-endian) |
| `Float64Array` | 86 | RFC 8746 (little-endian) |
| `BigUint64Array` | 71 | RFC 8746 (little-endian) |
| `BigInt64Array` | 79 | RFC 8746 (little-endian) |
### Type fidelity: objects vs Maps
`cborg/extended` preserves the distinction between plain objects and `Map` instances:
```js
// Plain objects round-trip as plain objects
const obj = { name: 'Alice', age: 30 }
decode(encode(obj)) // { name: 'Alice', age: 30 }
// Maps round-trip as Maps (including non-string keys)
const map = new Map([[1, 'one'], ['two', 2]])
decode(encode(map)) // Map { 1 => 'one', 'two' => 2 }
// Mixed structures work correctly
const data = {
users: new Map([['alice', { role: 'admin' }]])
}
const decoded = decode(encode(data))
decoded.users instanceof Map // true
decoded.users.get('alice') // { role: 'admin' } (plain object)
```
This works because `Map` instances are encoded with CBOR Tag 259, while plain objects use untagged CBOR maps. The decoder uses `decode.entries()` internally to preserve key types for tagged maps.
### Interoperability and limitations
The tags used by `cborg/extended` are standard CBOR tags registered with IANA:
- Tags 1, 2, 3 (Date, BigInt): RFC 8949
- Tag 27 (Error): IANA "object with class name and constructor arguments"
- Tags 64-87 (TypedArrays): RFC 8746
- Tags 258, 259 (Set, Map): IANA registry
- Tag 21066 (RegExp): IANA registry
**Important considerations:**
- **Parser support varies**: CBOR parsers that don't recognise these tags will either error or return raw tagged values. Many minimal CBOR implementations only handle core types. Test interoperability with your specific target platforms.
- **Not for content addressing**: `cborg/extended` prioritises JavaScript type fidelity over deterministic encoding. Map and object keys preserve insertion order (not sorted), floating-point dates lose sub-millisecond precision, and Set iteration order depends on insertion. The same data structure built differently may encode to different bytes. For content-addressed systems (IPLD, CIDs), use base `cborg` with `@ipld/dag-cbor` conventions instead.
- **Implementation differences**: Even among parsers that support these tags, behaviour may differ. For example, Date precision (seconds vs milliseconds), RegExp flag handling, or TypedArray endianness assumptions. The CBOR specs allow flexibility that can cause subtle incompatibilities.
- **JavaScript-centric**: Types like `RegExp` and JavaScript's specific TypedArray variants don't have equivalents in many languages. Data encoded with `cborg/extended` is best suited for JavaScript-to-JavaScript communication.
## Selective type support (`cborg/taglib`)
If you don't need all extended types, `cborg/taglib` exports individual encoders and decoders. Use this when you want to enable specific types without the full `cborg/extended` configuration, or when you need to customise behaviour.
> **Tip:** See [lib/extended/extended.js](./lib/extended/extended.js) for how `cborg/extended` assembles the taglib components, use it as a template for your own configuration.
```js
import { encode, decode } from 'cborg'
import {
dateEncoder,
dateDecoder,
bigIntEncoder,
bigIntDecoder,
bigNegIntDecoder,
TAG_DATE_EPOCH
} from 'cborg/taglib'
// Enable just Date and BigInt support
const encoded = encode(data, {
typeEncoders: {
Date: dateEncoder,
bigint: bigIntEncoder
}
})
const decoded = decode(encoded, {
tags: {
[TAG_DATE_EPOCH]: dateDecoder,
2: bigIntDecoder,
3: bigNegIntDecoder
}
})
```
### `cborg/extended` vs `cborg/taglib`
| Use case | Module |
|----------|--------|
| Serialize all JS types, minimal config | `cborg/extended` |
| Only need Date and BigInt | `cborg/taglib` with selective imports |
| Custom encode/decode logic | `cborg/taglib` as building blocks |
| Interop with IPLD/content-addressed systems | `cborg/taglib` with `bigIntEncoder` (not `structBigIntEncoder`) |
### Available exports
**Encoders:**
- `dateEncoder`: Date as epoch float (Tag 1)
- `regExpEncoder`: RegExp as [pattern, flags] (Tag 21066)
- `setEncoder`: Set as tagged array (Tag 258)
- `mapEncoder`: Map as tagged CBOR map (Tag 259)
- `bigIntEncoder`: BigInt, only tags values outside 64-bit range (IPLD compatible)
- `structBigIntEncoder`: BigInt, always tags (full round-trip as bigint)
- TypedArray encoders: `uint8ArrayEncoder`, `uint8ClampedArrayEncoder`, `int8ArrayEncoder`, `uint16ArrayEncoder`, `int16ArrayEncoder`, `uint32ArrayEncoder`, `int32ArrayEncoder`, `float32ArrayEncoder`, `float64ArrayEncoder`, `bigUint64ArrayEncoder`, `bigInt64ArrayEncoder`
**Decoders:**
- `dateDecoder`, `regExpDecoder`, `setDecoder`, `mapDecoder`
- `bigIntDecoder` (Tag 2), `bigNegIntDecoder` (Tag 3)
- TypedArray decoders: `uint8ArrayDecoder`, `uint8ClampedArrayDecoder`, `int8ArrayDecoder`, `uint16ArrayDecoder`, `int16ArrayDecoder`, `uint32ArrayDecoder`, `int32ArrayDecoder`, `float32ArrayDecoder`, `float64ArrayDecoder`, `bigUint64ArrayDecoder`, `bigInt64ArrayDecoder`
**Tag constants:** `TAG_DATE_STRING`, `TAG_DATE_EPOCH`, `TAG_BIGINT_POS`, `TAG_BIGINT_NEG`, `TAG_UINT8_ARRAY`, `TAG_UINT8_CLAMPED_ARRAY`, `TAG_INT8_ARRAY`, `TAG_UINT16_ARRAY_LE`, `TAG_INT16_ARRAY_LE`, `TAG_UINT32_ARRAY_LE`, `TAG_INT32_ARRAY_LE`, `TAG_FLOAT32_ARRAY_LE`, `TAG_FLOAT64_ARRAY_LE`, `TAG_BIGUINT64_ARRAY_LE`, `TAG_BIGINT64_ARRAY_LE`, `TAG_SET`, `TAG_MAP`, `TAG_REGEXP`
## License and Copyright

@@ -557,0 +761,0 @@

import { Token, Type } from '../lib/token.js'
export function dateDecoder (obj) {
export function dateDecoder (decode) {
const obj = decode()
if (typeof obj !== 'string') {

@@ -5,0 +6,0 @@ throw new Error('expected string for tag 1')

@@ -20,3 +20,4 @@ /* eslint-env mocha */

function Uint16ArrayDecoder (obj) {
function Uint16ArrayDecoder (decode) {
const obj = decode()
if (typeof obj !== 'string') {

@@ -23,0 +24,0 @@ throw new Error('expected string for tag 23')

@@ -24,3 +24,4 @@ /* eslint-env mocha,es2020 */

tags[0] = function (obj) {
tags[0] = function (decode) {
const obj = decode()
if (typeof obj !== 'string') {

@@ -32,3 +33,4 @@ throw new Error('expected string for tag 1')

tags[1] = function (obj) {
tags[1] = function (decode) {
const obj = decode()
if (typeof obj !== 'number') {

@@ -44,4 +46,5 @@ throw new Error('expected number for tag 1')

tags[23] = function (obj) {
tags[23] = function (decode) {
// expected conversion to base16
const obj = decode()
if (!(obj instanceof Uint8Array)) {

@@ -53,7 +56,12 @@ throw new Error('expected byte array for tag 23')

tags[24] = function (obj) { // embedded cbor, oh my
return tags[23](obj).replace(/^23/, '24')
tags[24] = function (decode) { // embedded cbor, oh my
const obj = decode()
if (!(obj instanceof Uint8Array)) {
throw new Error('expected byte array for tag 24')
}
return `24(h'${toHex(obj)}')`
}
tags[32] = function (obj) { // url
tags[32] = function (decode) { // url
const obj = decode()
if (typeof obj !== 'string') {

@@ -60,0 +68,0 @@ throw new Error('expected string for tag 32')

@@ -19,4 +19,5 @@ {

"esModuleInterop": true,
"target": "ES2018",
"moduleResolution": "node",
"target": "ES2020",
"module": "nodenext",
"moduleResolution": "nodenext",
"declaration": true,

@@ -28,20 +29,15 @@ "declarationMap": true,

"resolveJsonModule": true,
"baseUrl": ".",
"emitDeclarationOnly": true,
"paths": {
"cborg": [
"cborg.js"
]
}
"emitDeclarationOnly": true
},
"include": [
"cborg.js",
"example.js",
"taglib.js",
"interface.ts",
"lib/"
],
"exclude": [
"node_modules"
"node_modules",
"lib/bin.js"
],
"compileOnSave": false
}
/**
* There was originally just `TypeEncoder` so don't break types by renaming or not exporting
*/
export type TagDecoder = import("./interface").TagDecoder;
export type TagDecoder = import("./interface.js").TagDecoder;
/**
* Export the types that were present in the original manual cborg.d.ts
*/
export type TypeEncoder = import("./interface").OptionalTypeEncoder;
export type TypeEncoder = import("./interface.js").OptionalTypeEncoder;
/**
* Export the types that were present in the original manual cborg.d.ts
*/
export type DecodeOptions = import("./interface").DecodeOptions;
export type DecodeOptions = import("./interface.js").DecodeOptions;
/**
* Export the types that were present in the original manual cborg.d.ts
*/
export type EncodeOptions = import("./interface").EncodeOptions;
export type EncodeOptions = import("./interface.js").EncodeOptions;
import { decode } from './lib/decode.js';

@@ -18,0 +18,0 @@ import { decodeFirst } from './lib/decode.js';

@@ -1,1 +0,1 @@

{"version":3,"file":"cborg.d.ts","sourceRoot":"","sources":["../cborg.js"],"names":[],"mappings":";;;yBAMa,OAAO,aAAa,EAAE,UAAU;;;;0BAEhC,OAAO,aAAa,EAAE,mBAAmB;;;;4BACzC,OAAO,aAAa,EAAE,aAAa;;;;4BACnC,OAAO,aAAa,EAAE,aAAa;uBATe,iBAAiB;4BAAjB,iBAAiB;0BAAjB,iBAAiB;+BAAjB,iBAAiB;uBADvB,iBAAiB;2BAAjB,iBAAiB;qCAAjB,iBAAiB;sBAE9C,gBAAgB;qBAAhB,gBAAgB"}
{"version":3,"file":"cborg.d.ts","sourceRoot":"","sources":["../cborg.js"],"names":[],"mappings":";;;yBAMa,OAAO,gBAAgB,EAAE,UAAU;;;;0BAEnC,OAAO,gBAAgB,EAAE,mBAAmB;;;;4BAC5C,OAAO,gBAAgB,EAAE,aAAa;;;;4BACtC,OAAO,gBAAgB,EAAE,aAAa;uBATY,iBAAiB;4BAAjB,iBAAiB;0BAAjB,iBAAiB;+BAAjB,iBAAiB;uBADvB,iBAAiB;2BAAjB,iBAAiB;qCAAjB,iBAAiB;sBAE9C,gBAAgB;qBAAhB,gBAAgB"}

@@ -1,2 +0,2 @@

import { Token } from './lib/token';
import { Token } from './lib/token.js';
export type TokenOrNestedTokens = Token | Token[] | TokenOrNestedTokens[];

@@ -22,3 +22,12 @@ export interface Reference {

}
export type TagDecoder = (inner: any) => any;
/**
* Control object passed to tag decoders, providing methods to decode the tagged content.
*/
export interface TagDecodeControl {
/** Decode the tagged content */
(): unknown;
/** Decode CBOR map content as [key, value] entries array (preserves key types) */
entries(): Array<[unknown, unknown]>;
}
export type TagDecoder = (decode: TagDecodeControl) => any;
export interface DecodeOptions {

@@ -35,3 +44,5 @@ allowIndefinite?: boolean;

retainStringBytes?: boolean;
tags?: TagDecoder[];
tags?: {
[tagNumber: number]: TagDecoder;
};
tokenizer?: DecodeTokenizer;

@@ -38,0 +49,0 @@ }

@@ -1,1 +0,1 @@

{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../interface.ts"],"names":[],"mappings":"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"}
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../interface.ts"],"names":[],"mappings":"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"}
/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -97,5 +97,5 @@ /**

export const uintBoundaries: (number | bigint)[];
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=0uint.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"0uint.d.ts","sourceRoot":"","sources":["../../lib/0uint.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;GAKG;AACH,gCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,CASlB;AAED;;;;;GAKG;AACH,iCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,CASlB;AAED;;;;;GAKG;AACH,iCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,CASlB;AAED;;;;;GAKG;AACH,iCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,GAAC,MAAM,CAkBzB;AASD;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;GAGG;AACH,mCAHW,UAAU,SACV,KAAK,QAIf;;IAqDD;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;IAsBD;;;;OAIG;IACH,6BAJW,KAAK,QACL,KAAK,GACH,MAAM,CAIlB;;AAtFD;;;;GAIG;AACH,wCAJW,UAAU,SACV,MAAM,QACN,MAAM,GAAC,MAAM,QA8CvB;;IAUD;;;OAGG;IACH,2BAHW,MAAM,GACJ,MAAM,CAgBlB;;AApND,iDAA0F;yBAG7E,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBAPrB,YAAY"}
{"version":3,"file":"0uint.d.ts","sourceRoot":"","sources":["../../lib/0uint.js"],"names":[],"mappings":"AAOA;;;GAGG;AAEH;;;;;GAKG;AACH,gCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,CASlB;AAED;;;;;GAKG;AACH,iCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,CASlB;AAED;;;;;GAKG;AACH,iCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,CASlB;AAED;;;;;GAKG;AACH,iCALW,UAAU,UACV,MAAM,WACN,aAAa,GACX,MAAM,GAAC,MAAM,CAkBzB;AASD;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;GAGG;AACH,mCAHW,UAAU,SACV,KAAK,QAIf;;IAqDD;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;IAsBD;;;;OAIG;IACH,6BAJW,KAAK,QACL,KAAK,GACH,MAAM,CAIlB;;AAtFD;;;;GAIG;AACH,wCAJW,UAAU,SACV,MAAM,QACN,MAAM,GAAC,MAAM,QA8CvB;;IAUD;;;OAGG;IACH,2BAHW,MAAM,GACJ,MAAM,CAgBlB;;AApND,iDAA0F;yBAG7E,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;sBAPxB,YAAY"}
/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -55,5 +55,5 @@ /**

}
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=1negint.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"1negint.d.ts","sourceRoot":"","sources":["../../lib/1negint.js"],"names":[],"mappings":"AAMA;;;GAGG;AAEH;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAKD;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAcjB;AAED;;;GAGG;AACH,qCAHW,UAAU,SACV,KAAK,QAMf;;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAoBlB;IAED;;;;OAIG;IACH,6BAJW,KAAK,QACL,KAAK,GACH,MAAM,CAKlB;;yBAvGY,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBANrB,YAAY"}
{"version":3,"file":"1negint.d.ts","sourceRoot":"","sources":["../../lib/1negint.js"],"names":[],"mappings":"AAMA;;;GAGG;AAEH;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAKD;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAcjB;AAED;;;GAGG;AACH,qCAHW,UAAU,SACV,KAAK,QAMf;;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAoBlB;IAED;;;;OAIG;IACH,6BAJW,KAAK,QACL,KAAK,GACH,MAAM,CAKlB;;yBAvGY,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;sBANxB,YAAY"}

@@ -65,5 +65,5 @@ /**

export function compareBytes(b1: Uint8Array, b2: Uint8Array): number;
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=2bytes.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"2bytes.d.ts","sourceRoot":"","sources":["../../lib/2bytes.js"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,yCANW,UAAU,OACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAgBD;;;GAGG;AACH,oCAHW,UAAU,SACV,KAAK,QAMf;;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAKlB;IAED;;;;OAIG;IACH,6BAJW,KAAK,QACL,KAAK,GACH,MAAM,CAIlB;;AAED;;;;GAIG;AACH,iCAJW,UAAU,MACV,UAAU,GACR,MAAM,CAIlB;yBA9HY,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBAPrB,YAAY"}
{"version":3,"file":"2bytes.d.ts","sourceRoot":"","sources":["../../lib/2bytes.js"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,yCANW,UAAU,OACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAgBD;;;GAGG;AACH,oCAHW,UAAU,SACV,KAAK,QAMf;;IAED;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAKlB;IAED;;;;OAIG;IACH,6BAJW,KAAK,QACL,KAAK,GACH,MAAM,CAIlB;;AAED;;;;GAIG;AACH,iCAJW,UAAU,MACV,UAAU,GACR,MAAM,CAIlB;yBA9HY,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;sBAPxB,YAAY"}

@@ -42,6 +42,6 @@ /**

export const encodeString: typeof encodeBytes;
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
import { encodeBytes } from './2bytes.js';
//# sourceMappingURL=3string.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"3string.d.ts","sourceRoot":"","sources":["../../lib/3string.js"],"names":[],"mappings":"AA0DA;;;;;;GAMG;AACH,0CANW,UAAU,OACV,MAAM,SACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED,8CAAuC;yBA1G1B,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBAbrB,YAAY;4BAGZ,aAAa"}
{"version":3,"file":"3string.d.ts","sourceRoot":"","sources":["../../lib/3string.js"],"names":[],"mappings":"AA0DA;;;;;;GAMG;AACH,0CANW,UAAU,OACV,MAAM,SACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,qCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED,8CAAuC;yBA1G1B,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;sBAbxB,YAAY;4BAGZ,aAAa"}

@@ -62,5 +62,5 @@ /**

}
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=4array.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"4array.d.ts","sourceRoot":"","sources":["../../lib/4array.js"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,yCANW,UAAU,OACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED;;;;;;GAMG;AACH,4CANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAED;;;GAGG;AACH,oCAHW,UAAU,SACV,KAAK,QAIf;;;IAMD;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;;yBA3GY,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBANrB,YAAY"}
{"version":3,"file":"4array.d.ts","sourceRoot":"","sources":["../../lib/4array.js"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,yCANW,UAAU,OACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED;;;;;;GAMG;AACH,4CANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAED;;;GAGG;AACH,oCAHW,UAAU,SACV,KAAK,QAIf;;;IAMD;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;;yBA3GY,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;sBANxB,YAAY"}

@@ -62,5 +62,5 @@ /**

}
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=5map.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"5map.d.ts","sourceRoot":"","sources":["../../lib/5map.js"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,uCANW,UAAU,OACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,iCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED;;;;;;GAMG;AACH,0CANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAED;;;GAGG;AACH,kCAHW,UAAU,SACV,KAAK,QAIf;;;IAMD;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;;yBA3GY,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBANrB,YAAY"}
{"version":3,"file":"5map.d.ts","sourceRoot":"","sources":["../../lib/5map.js"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,uCANW,UAAU,OACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,iCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAGD;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAQjB;AAED;;;;;;GAMG;AACH,0CANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAED;;;GAGG;AACH,kCAHW,UAAU,SACV,KAAK,QAIf;;;IAMD;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;;yBA3GY,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;sBANxB,YAAY"}
/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
*/

@@ -58,5 +58,5 @@ /**

}
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=6tag.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"6tag.d.ts","sourceRoot":"","sources":["../../lib/6tag.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;;;;;;GAMG;AACH,wCANW,UAAU,QACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,iCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;GAGG;AACH,kCAHW,UAAU,SACV,KAAK,QAIf;;;IAID;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;;yBA3EY,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;sBALrB,YAAY"}
{"version":3,"file":"6tag.d.ts","sourceRoot":"","sources":["../../lib/6tag.js"],"names":[],"mappings":"AAGA;;;GAGG;AAEH;;;;;;GAMG;AACH,wCANW,UAAU,QACV,MAAM,SACN,MAAM,YACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,iCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,kCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;GAGG;AACH,kCAHW,UAAU,SACV,KAAK,QAIf;;;IAID;;;OAGG;IACH,4BAHW,KAAK,GACH,MAAM,CAIlB;;yBA3EY,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;sBALxB,YAAY"}

@@ -57,5 +57,5 @@ /**

/**
* @typedef {import('../interface').ByteWriter} ByteWriter
* @typedef {import('../interface').DecodeOptions} DecodeOptions
* @typedef {import('../interface').EncodeOptions} EncodeOptions
* @typedef {import('../interface.js').ByteWriter} ByteWriter
* @typedef {import('../interface.js').DecodeOptions} DecodeOptions
* @typedef {import('../interface.js').EncodeOptions} EncodeOptions
*/

@@ -66,6 +66,6 @@ export const MINOR_FALSE: 20;

export const MINOR_UNDEFINED: 23;
export type ByteWriter = import("../interface").ByteWriter;
export type DecodeOptions = import("../interface").DecodeOptions;
export type EncodeOptions = import("../interface").EncodeOptions;
export type ByteWriter = import("../interface.js").ByteWriter;
export type DecodeOptions = import("../interface.js").DecodeOptions;
export type EncodeOptions = import("../interface.js").EncodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=7float.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"7float.d.ts","sourceRoot":"","sources":["../../lib/7float.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,uCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CASjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAoBD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;GAIG;AACH,oCAJW,UAAU,SACV,KAAK,WACL,aAAa,QAwCvB;;IAED;;;;OAIG;IACH,4BAJW,KAAK,WACL,aAAa,GACX,MAAM,CAsBlB;;;AAlKD;;;;GAIG;AAEH,0BAA2B,EAAE,CAAA;AAC7B,yBAA0B,EAAE,CAAA;AAC5B,yBAA0B,EAAE,CAAA;AAC5B,8BAA+B,EAAE,CAAA;yBARpB,OAAO,cAAc,EAAE,UAAU;4BACjC,OAAO,cAAc,EAAE,aAAa;4BACpC,OAAO,cAAc,EAAE,aAAa;sBAPrB,YAAY"}
{"version":3,"file":"7float.d.ts","sourceRoot":"","sources":["../../lib/7float.js"],"names":[],"mappings":"AAkBA;;;;;;GAMG;AACH,uCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CASjB;AAED;;;;;;GAMG;AACH,mCANW,UAAU,QACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAOjB;AAoBD;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;;;GAMG;AACH,oCANW,UAAU,OACV,MAAM,UACN,MAAM,WACN,aAAa,GACX,KAAK,CAIjB;AAED;;;;GAIG;AACH,oCAJW,UAAU,SACV,KAAK,WACL,aAAa,QAwCvB;;IAED;;;;OAIG;IACH,4BAJW,KAAK,WACL,aAAa,GACX,MAAM,CAsBlB;;;AAlKD;;;;GAIG;AAEH,0BAA2B,EAAE,CAAA;AAC7B,yBAA0B,EAAE,CAAA;AAC5B,yBAA0B,EAAE,CAAA;AAC5B,8BAA+B,EAAE,CAAA;yBARpB,OAAO,iBAAiB,EAAE,UAAU;4BACpC,OAAO,iBAAiB,EAAE,aAAa;4BACvC,OAAO,iBAAiB,EAAE,aAAa;sBAPxB,YAAY"}

@@ -17,4 +17,7 @@ /**

export function decodeCodePointsArray(codePoints: number[]): string;
export const useBuffer: boolean;
export const fromString: ((string: string) => number[] | Buffer<ArrayBuffer>) | ((string: string) => number[] | Uint8Array<ArrayBuffer>);
export const useBuffer: any;
/**
* @param {string} string
*/
export function fromString(string: string): any;
export function fromArray(arr: number[]): Uint8Array;

@@ -21,0 +24,0 @@ /**

@@ -1,1 +0,1 @@

{"version":3,"file":"byte-utils.d.ts","sourceRoot":"","sources":["../../lib/byte-utils.js"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,2BAHW,UAAU,GAAC,MAAM,EAAE,GACjB,UAAU,CAQtB;AA0MD;;;;GAIG;AACH,4BAJW,UAAU,MACV,UAAU,GACR,MAAM,CAgBlB;AA6CD;;;GAGG;AACH,kDAHW,MAAM,EAAE,GACN,MAAM,CAkBlB;AA3TD,gCAMkD;AA+BlD,mCAGe,MAAM,iDAYN,MAAM,yCAIhB;AAOE,+BAHI,MAAM,EAAE,GACN,UAAU,CAItB;AAIG;;;;GAIG;AAEH,6BALW,UAAU,SACV,MAAM,OACN,MAAM,2BAQhB;AAcD;;;;GAIG;AACH,+BAJW,UAAU,EAAE,UACZ,MAAM,GACJ,UAAU,CActB;AAwBD;;;GAGG;AACH,4BAHW,MAAM,GACJ,UAAU,CAMtB;AAaD;;;GAGG;AACH,yBAHW,UAAU,GACR,MAAM,CAQlB;AAiBH;;;GAGG;AACD,6BAHS,MAAM,GAAC,UAAU,GACf,UAAU,CAQpB"}
{"version":3,"file":"byte-utils.d.ts","sourceRoot":"","sources":["../../lib/byte-utils.js"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,2BAHW,UAAU,GAAC,MAAM,EAAE,GACjB,UAAU,CAQtB;AA0MD;;;;GAIG;AACH,4BAJW,UAAU,MACV,UAAU,GACR,MAAM,CAgBlB;AA6CD;;;GAGG;AACH,kDAHW,MAAM,EAAE,GACN,MAAM,CAkBlB;AA3TD,4BAMkD;AAiC9C;;GAEG;AACH,mCAFW,MAAM,OAQhB;AAeE,+BAHI,MAAM,EAAE,GACN,UAAU,CAItB;AAIG;;;;GAIG;AAEH,6BALW,UAAU,SACV,MAAM,OACN,MAAM,2BAQhB;AAcD;;;;GAIG;AACH,+BAJW,UAAU,EAAE,UACZ,MAAM,GACJ,UAAU,CActB;AAwBD;;;GAGG;AACH,4BAHW,MAAM,GACJ,UAAU,CAMtB;AAaD;;;GAGG;AACH,yBAHW,UAAU,GACR,MAAM,CAQlB;AAiBH;;;GAGG;AACD,6BAHS,MAAM,GAAC,UAAU,GACf,UAAU,CAQpB"}
export type Token = import("./token.js").Token;
export type DecodeOptions = import("../interface").DecodeOptions;
export type DecodeTokenizer = import("../interface").DecodeTokenizer;
export type DecodeOptions = import("../interface.js").DecodeOptions;
export type DecodeTokenizer = import("../interface.js").DecodeTokenizer;
export type TagDecodeControl = import("../interface.js").TagDecodeControl;
/**

@@ -15,3 +16,3 @@ * @implements {DecodeTokenizer}

data: Uint8Array<ArrayBufferLike>;
options: import("../interface").DecodeOptions;
options: import("../interface.js").DecodeOptions;
pos(): number;

@@ -18,0 +19,0 @@ done(): boolean;

@@ -1,1 +0,1 @@

{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../lib/decode.js"],"names":[],"mappings":"oBAMa,OAAO,YAAY,EAAE,KAAK;4BAC1B,OAAO,cAAc,EAAE,aAAa;8BACpC,OAAO,cAAc,EAAE,eAAe;AAUnD;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,YACV,aAAa,EAMvB;IAHC,aAAa;IACb,kCAAgB;IAChB,8CAAsB;IAGxB,cAEC;IAED,gBAEC;IAED,mCAgBC;CACF;AA8ED;;;;GAIG;AACH,0CAJW,eAAe,WACf,aAAa,GACX,GAAG,6BAAW,CAoC1B;AAyBD;;;;GAIG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CAQf;AAlCD;;;;GAIG;AACH,kCAJW,UAAU,YACV,aAAa,GACX,CAAC,GAAG,EAAE,UAAU,CAAC,CAkB7B;AAzID,mCAAiC;AADjC,kCAA+B"}
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../lib/decode.js"],"names":[],"mappings":"oBAMa,OAAO,YAAY,EAAE,KAAK;4BAC1B,OAAO,iBAAiB,EAAE,aAAa;8BACvC,OAAO,iBAAiB,EAAE,eAAe;+BACzC,OAAO,iBAAiB,EAAE,gBAAgB;AAUvD;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,YACV,aAAa,EAMvB;IAHC,aAAa;IACb,kCAAgB;IAChB,iDAAsB;IAGxB,cAEC;IAED,gBAEC;IAED,mCAgBC;CACF;AAmKD;;;;GAIG;AACH,0CAJW,eAAe,WACf,aAAa,GACX,GAAG,6BAAW,CAwC1B;AAyBD;;;;GAIG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CAQf;AAlCD;;;;GAIG;AACH,kCAJW,UAAU,YACV,aAAa,GACX,CAAC,GAAG,EAAE,UAAU,CAAC,CAkB7B;AAlOD,mCAAiC;AADjC,kCAA+B"}

@@ -8,9 +8,9 @@ /** @returns {TokenTypeEncoder[]} */

};
export type EncodeOptions = import("../interface").EncodeOptions;
export type OptionalTypeEncoder = import("../interface").OptionalTypeEncoder;
export type Reference = import("../interface").Reference;
export type StrictTypeEncoder = import("../interface").StrictTypeEncoder;
export type TokenTypeEncoder = import("../interface").TokenTypeEncoder;
export type TokenOrNestedTokens = import("../interface").TokenOrNestedTokens;
export type ByteWriter = import("../interface").ByteWriter;
export type EncodeOptions = import("../interface.js").EncodeOptions;
export type OptionalTypeEncoder = import("../interface.js").OptionalTypeEncoder;
export type Reference = import("../interface.js").Reference;
export type StrictTypeEncoder = import("../interface.js").StrictTypeEncoder;
export type TokenTypeEncoder = import("../interface.js").TokenTypeEncoder;
export type TokenOrNestedTokens = import("../interface.js").TokenOrNestedTokens;
export type ByteWriter = import("../interface.js").ByteWriter;
/**

@@ -60,3 +60,3 @@ * @param {any} obj

obj: object | any[];
parent: import("../interface").Reference | undefined;
parent: import("../interface.js").Reference | undefined;
/**

@@ -63,0 +63,0 @@ * @param {object|any[]} obj

@@ -1,1 +0,1 @@

{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../lib/encode.js"],"names":[],"mappings":"AAwCA,oCAAoC;AACpC,oCADc,gBAAgB,EAAE,CAY/B;AAnBD,4BAA4B;AAC5B,mCADW,aAAa,CAKtB;sBA+XW,KAAK,GAAG;IAAE,SAAS,CAAC,EAAE,UAAU,CAAA;CAAE;4BApZlC,OAAO,cAAc,EAAE,aAAa;kCACpC,OAAO,cAAc,EAAE,mBAAmB;wBAC1C,OAAO,cAAc,EAAE,SAAS;gCAChC,OAAO,cAAc,EAAE,iBAAiB;+BACxC,OAAO,cAAc,EAAE,gBAAgB;kCACvC,OAAO,cAAc,EAAE,mBAAmB;yBAC1C,OAAO,cAAc,EAAE,UAAU;AA0R9C;;;;;GAKG;AACH,oCALW,GAAG,YACH,aAAa,aACb,SAAS,GACP,mBAAmB,CAgB/B;AAiUD;;;;GAIG;AACH,6BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAatB;AA3DD;;;;;;GAMG;AACH,mCANW,GAAG,YACH,gBAAgB,EAAE,WAClB,aAAa,gBACb,UAAU,GACR,UAAU,CAoCtB;AAoBD;;;;;GAKG;AACH,iCALW,GAAG,eACH,UAAU,YACV,aAAa,GACX;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAc/B;AAhnBD,8BAA8B;AAC9B,4BADiB,SAAS;IA0BxB;;;;OAIG;IACH,0BAJW,SAAS,GAAC,SAAS,OACnB,MAAM,GAAC,GAAG,EAAE,GACV,SAAS,CAOrB;IAlCD;;;OAGG;IACH,iBAHW,MAAM,GAAC,GAAG,EAAE,UACZ,SAAS,GAAC,SAAS,EAK7B;IAFC,oBAAc;IACd,qDAAoB;IAGtB;;;OAGG;IACH,cAHW,MAAM,GAAC,GAAG,EAAE,GACV,OAAO,CAWnB;CAaF;sBA9F2B,YAAY"}
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../lib/encode.js"],"names":[],"mappings":"AAwCA,oCAAoC;AACpC,oCADc,gBAAgB,EAAE,CAY/B;AAnBD,4BAA4B;AAC5B,mCADW,aAAa,CAKtB;sBA+XW,KAAK,GAAG;IAAE,SAAS,CAAC,EAAE,UAAU,CAAA;CAAE;4BApZlC,OAAO,iBAAiB,EAAE,aAAa;kCACvC,OAAO,iBAAiB,EAAE,mBAAmB;wBAC7C,OAAO,iBAAiB,EAAE,SAAS;gCACnC,OAAO,iBAAiB,EAAE,iBAAiB;+BAC3C,OAAO,iBAAiB,EAAE,gBAAgB;kCAC1C,OAAO,iBAAiB,EAAE,mBAAmB;yBAC7C,OAAO,iBAAiB,EAAE,UAAU;AA0RjD;;;;;GAKG;AACH,oCALW,GAAG,YACH,aAAa,aACb,SAAS,GACP,mBAAmB,CAgB/B;AAiUD;;;;GAIG;AACH,6BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAatB;AA3DD;;;;;;GAMG;AACH,mCANW,GAAG,YACH,gBAAgB,EAAE,WAClB,aAAa,gBACb,UAAU,GACR,UAAU,CAoCtB;AAoBD;;;;;GAKG;AACH,iCALW,GAAG,eACH,UAAU,YACV,aAAa,GACX;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAc/B;AAhnBD,8BAA8B;AAC9B,4BADiB,SAAS;IA0BxB;;;;OAIG;IACH,0BAJW,SAAS,GAAC,SAAS,OACnB,MAAM,GAAC,GAAG,EAAE,GACV,SAAS,CAOrB;IAlCD;;;OAGG;IACH,iBAHW,MAAM,GAAC,GAAG,EAAE,UACZ,SAAS,GAAC,SAAS,EAK7B;IAFC,oBAAc;IACd,wDAAoB;IAGtB;;;OAGG;IACH,cAHW,MAAM,GAAC,GAAG,EAAE,GACV,OAAO,CAWnB;CAaF;sBA9F2B,YAAY"}

@@ -1,3 +0,3 @@

export type DecodeOptions = import("../../interface").DecodeOptions;
export type DecodeTokenizer = import("../../interface").DecodeTokenizer;
export type DecodeOptions = import("../../interface.js").DecodeOptions;
export type DecodeTokenizer = import("../../interface.js").DecodeTokenizer;
/**

@@ -16,4 +16,4 @@ * @param {Uint8Array} data

/**
* @typedef {import('../../interface').DecodeOptions} DecodeOptions
* @typedef {import('../../interface').DecodeTokenizer} DecodeTokenizer
* @typedef {import('../../interface.js').DecodeOptions} DecodeOptions
* @typedef {import('../../interface.js').DecodeTokenizer} DecodeTokenizer
*/

@@ -31,3 +31,3 @@ /**

data: Uint8Array<ArrayBufferLike>;
options: import("../../interface").DecodeOptions;
options: import("../../interface.js").DecodeOptions;
/** @type {string[]} */

@@ -34,0 +34,0 @@ modeStack: string[];

@@ -1,1 +0,1 @@

{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../lib/json/decode.js"],"names":[],"mappings":"4BAMa,OAAO,iBAAiB,EAAE,aAAa;8BACvC,OAAO,iBAAiB,EAAE,eAAe;AAgbtD;;;;GAIG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CAKf;AAED;;;;GAIG;AACH,kCAJW,UAAU,YACV,aAAa,GACX,CAAC,GAAG,EAAE,UAAU,CAAC,CAK7B;AApcD;;;GAGG;AAEH;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,YACV,aAAa,EASvB;IANC,aAAa;IACb,kCAAgB;IAChB,iDAAsB;IACtB,uBAAuB;IACvB,WADW,MAAM,EAAE,CACO;IAC1B,kBAAmB;IAGrB,cAEC;IAED;;OAEG;IACH,QAFa,OAAO,CAInB;IAED;;OAEG;IACH,MAFa,MAAM,CAIlB;IAED;;OAEG;IACH,eAFa,MAAM,CAIlB;IAED,uBAMC;IAED;;OAEG;IACH,YAFW,MAAM,EAAE,QAWlB;IAED,qBA+DC;IAED;;OAEG;IACH,eAFa,KAAK,CAkLjB;IAED;;OAEG;IACH,cAFa,KAAK,CAuCjB;IAED;;OAEG;IACH,QAFa,KAAK,CAyEjB;CACF;sBApb2B,aAAa"}
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../lib/json/decode.js"],"names":[],"mappings":"4BAMa,OAAO,oBAAoB,EAAE,aAAa;8BAC1C,OAAO,oBAAoB,EAAE,eAAe;AAgbzD;;;;GAIG;AACH,6BAJW,UAAU,YACV,aAAa,GACX,GAAG,CAKf;AAED;;;;GAIG;AACH,kCAJW,UAAU,YACV,aAAa,GACX,CAAC,GAAG,EAAE,UAAU,CAAC,CAK7B;AApcD;;;GAGG;AAEH;;GAEG;AACH,kCAFgB,eAAe;IAG7B;;;OAGG;IACH,kBAHW,UAAU,YACV,aAAa,EASvB;IANC,aAAa;IACb,kCAAgB;IAChB,oDAAsB;IACtB,uBAAuB;IACvB,WADW,MAAM,EAAE,CACO;IAC1B,kBAAmB;IAGrB,cAEC;IAED;;OAEG;IACH,QAFa,OAAO,CAInB;IAED;;OAEG;IACH,MAFa,MAAM,CAIlB;IAED;;OAEG;IACH,eAFa,MAAM,CAIlB;IAED,uBAMC;IAED;;OAEG;IACH,YAFW,MAAM,EAAE,QAWlB;IAED,qBA+DC;IAED;;OAEG;IACH,eAFa,KAAK,CAkLjB;IAED;;OAEG;IACH,cAFa,KAAK,CAuCjB;IAED;;OAEG;IACH,QAFa,KAAK,CAyEjB;CACF;sBApb2B,aAAa"}

@@ -1,4 +0,4 @@

export type EncodeOptions = import("../../interface").EncodeOptions;
export type ByteWriter = import("../../interface").ByteWriter;
export type Token = import("../token").Token;
export type EncodeOptions = import("../../interface.js").EncodeOptions;
export type ByteWriter = import("../../interface.js").ByteWriter;
export type Token = import("../token.js").Token;
/**

@@ -5,0 +5,0 @@ * @param {any} data

@@ -1,1 +0,1 @@

{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../lib/json/encode.js"],"names":[],"mappings":"4BAMa,OAAO,iBAAiB,EAAE,aAAa;yBACvC,OAAO,iBAAiB,EAAE,UAAU;oBACpC,OAAO,UAAU,EAAE,KAAK;AAoSrC;;;;GAIG;AACH,6BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAMtB"}
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../lib/json/encode.js"],"names":[],"mappings":"4BAMa,OAAO,oBAAoB,EAAE,aAAa;yBAC1C,OAAO,oBAAoB,EAAE,UAAU;oBACvC,OAAO,aAAa,EAAE,KAAK;AAoSxC;;;;GAIG;AACH,6BAJW,GAAG,YACH,aAAa,GACX,UAAU,CAMtB"}

@@ -10,4 +10,4 @@ /**

export const quick: Token[];
export type DecodeOptions = import("../interface").DecodeOptions;
export type DecodeOptions = import("../interface.js").DecodeOptions;
import { Token } from './token.js';
//# sourceMappingURL=jump.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"jump.d.ts","sourceRoot":"","sources":["../../lib/jump.js"],"names":[],"mappings":"AAkKA;;;GAGG;AACH,wCAHW,KAAK,GACH,UAAU,GAAC,SAAS,CA4ChC;AA/KD,6FAA6F;AAC7F,mBADW,CAAC,CAAC,IAAI,EAAC,UAAU,EAAE,GAAG,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,OAAO,CAAC,EAAC,aAAa,KAAK,GAAG,CAAC,EAAE,CACnE;AAuGtB,sBAAsB;AACtB,oBADW,KAAK,EAAE,CACK;4BA7HV,OAAO,cAAc,EAAE,aAAa;sBAbrB,YAAY"}
{"version":3,"file":"jump.d.ts","sourceRoot":"","sources":["../../lib/jump.js"],"names":[],"mappings":"AAkKA;;;GAGG;AACH,wCAHW,KAAK,GACH,UAAU,GAAC,SAAS,CA4ChC;AA/KD,6FAA6F;AAC7F,mBADW,CAAC,CAAC,IAAI,EAAC,UAAU,EAAE,GAAG,EAAC,MAAM,EAAE,KAAK,EAAC,MAAM,EAAE,OAAO,CAAC,EAAC,aAAa,KAAK,GAAG,CAAC,EAAE,CACnE;AAuGtB,sBAAsB;AACtB,oBADW,KAAK,EAAE,CACK;4BA7HV,OAAO,iBAAiB,EAAE,aAAa;sBAbxB,YAAY"}

@@ -24,5 +24,5 @@ /**

export function tokensToLength(tokens: TokenOrNestedTokens, encoders?: TokenTypeEncoder[], options?: EncodeOptions): number;
export type EncodeOptions = import("../interface").EncodeOptions;
export type TokenTypeEncoder = import("../interface").TokenTypeEncoder;
export type TokenOrNestedTokens = import("../interface").TokenOrNestedTokens;
export type EncodeOptions = import("../interface.js").EncodeOptions;
export type TokenTypeEncoder = import("../interface.js").TokenTypeEncoder;
export type TokenOrNestedTokens = import("../interface.js").TokenOrNestedTokens;
//# sourceMappingURL=length.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"length.d.ts","sourceRoot":"","sources":["../../lib/length.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;GAUG;AACH,oCAJW,GAAG,YACH,aAAa,GACX,MAAM,CAOlB;AAED;;;;;;;;;GASG;AACH,uCAJW,mBAAmB,aACnB,gBAAgB,EAAE,YAClB,aAAa,UAiBvB;4BAxDY,OAAO,cAAc,EAAE,aAAa;+BACpC,OAAO,cAAc,EAAE,gBAAgB;kCACvC,OAAO,cAAc,EAAE,mBAAmB"}
{"version":3,"file":"length.d.ts","sourceRoot":"","sources":["../../lib/length.js"],"names":[],"mappings":"AAiBA;;;;;;;;;;GAUG;AACH,oCAJW,GAAG,YACH,aAAa,GACX,MAAM,CAOlB;AAED;;;;;;;;;GASG;AACH,uCAJW,mBAAmB,aACnB,gBAAgB,EAAE,YAClB,aAAa,UAiBvB;4BAxDY,OAAO,iBAAiB,EAAE,aAAa;+BACvC,OAAO,iBAAiB,EAAE,gBAAgB;kCAC1C,OAAO,iBAAiB,EAAE,mBAAmB"}
import { Token, Type } from './cborg.js'
/*
A collection of some standard CBOR tags.
There are no tags included by default in the cborg encoder or decoder, you have
to include them by passing options. `typeEncoders` for encode() and `tags` for
decode().
The encoders here can be included with these options (see the tests for how this
can be done), or as examples for writing additional tags. Additional standard
(and reasonable) tags may be added here by pull request.
*/
/* TAG(2) Bignums https://tools.ietf.org/html/rfc8949#section-3.4.3 */
const neg1b = BigInt(-1)
const pos1b = BigInt(1)
const zerob = BigInt(0)
// const twob = BigInt(2)
const eightb = BigInt(8)
/**
* @param {Uint8Array} bytes
* @returns {bigint}
*/
export function bigIntDecoder (bytes) {
// TODO: assert that `bytes` is a `Uint8Array`
let bi = zerob
for (let ii = 0; ii < bytes.length; ii++) {
bi = (bi << eightb) + BigInt(bytes[ii])
}
return bi
}
/**
* @param {bigint} bi
* @returns {Uint8Array}
*/
function fromBigInt (bi) {
const buf = []
while (bi > 0) {
buf.unshift(Number(bi) & 0xff)
bi >>= eightb
}
return Uint8Array.from(buf)
}
// assuming that we're receiving a BigInt here, it should be registered for
// type 'bigint' for this to work.
const maxSafeBigInt = BigInt('18446744073709551615') // (twob ** BigInt(64)) - pos1b
const minSafeBigInt = BigInt('-18446744073709551616') // neg1b * (twob ** BigInt(64))
/**
* @param {bigint} obj
* @returns {Token[]|null}
*/
export function bigIntEncoder (obj) {
if (obj >= minSafeBigInt && obj <= maxSafeBigInt) {
return null // null = do it the standard way
}
return [
new Token(Type.tag, obj >= zerob ? 2 : 3),
new Token(Type.bytes, fromBigInt(obj >= zerob ? obj : obj * neg1b - pos1b))
]
}
/**
* TAG(3) Negative Bignums https://tools.ietf.org/html/rfc8949#section-3.4.3
* @param {Uint8Array} bytes
* @returns {bigint}
*/
export function bigNegIntDecoder (bytes) {
return neg1b - bigIntDecoder(bytes)
}
/**
* @param {Uint8Array} bytes
* @returns {bigint}
*/
export function bigIntDecoder(bytes: Uint8Array): bigint;
/**
* @param {bigint} obj
* @returns {Token[]|null}
*/
export function bigIntEncoder(obj: bigint): Token[] | null;
/**
* TAG(3) Negative Bignums https://tools.ietf.org/html/rfc8949#section-3.4.3
* @param {Uint8Array} bytes
* @returns {bigint}
*/
export function bigNegIntDecoder(bytes: Uint8Array): bigint;
import { Token } from './cborg.js';
//# sourceMappingURL=taglib.d.ts.map
{"version":3,"file":"taglib.d.ts","sourceRoot":"","sources":["../taglib.js"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,qCAHW,UAAU,GACR,MAAM,CASlB;AAmBD;;;GAGG;AACH,mCAHW,MAAM,GACJ,KAAK,EAAE,GAAC,IAAI,CAUxB;AAED;;;;GAIG;AACH,wCAHW,UAAU,GACR,MAAM,CAIlB;sBAxE2B,YAAY"}

Sorry, the diff of this file is not supported yet