@cbortech/cbor 0.25.9 → 0.25.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +34 -5
- package/README.md +36 -5
- package/dist/ast/CborByteString.d.ts +9 -0
- package/dist/ast/CborFloat.d.ts +9 -0
- package/dist/ast/CborTextString.d.ts +3 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor/encode.d.ts +11 -0
- package/dist/cbor.d.ts +8 -1
- package/dist/cdn/index.cjs +2 -2
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/serialize-utils.d.ts +36 -0
- package/dist/cdn/tokenizer.d.ts +37 -2
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +83 -75
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-I8f0WuwK.js → mapEntries-CYvdsAfP.js} +1047 -872
- package/dist/mapEntries-CYvdsAfP.js.map +1 -0
- package/dist/mapEntries-vOYb5Q1s.cjs +11 -0
- package/dist/mapEntries-vOYb5Q1s.cjs.map +1 -0
- package/dist/tokenizer-CVcIyZZa.cjs +30 -0
- package/dist/tokenizer-CVcIyZZa.cjs.map +1 -0
- package/dist/{tokenizer-CETZf2NR.js → tokenizer-DkLlZ1gc.js} +161 -349
- package/dist/tokenizer-DkLlZ1gc.js.map +1 -0
- package/dist/types.d.ts +66 -1
- package/dist/utils/hex.d.ts +5 -0
- package/package.json +3 -3
- package/dist/mapEntries-BkcJsv3C.cjs +0 -12
- package/dist/mapEntries-BkcJsv3C.cjs.map +0 -1
- package/dist/mapEntries-I8f0WuwK.js.map +0 -1
- package/dist/tokenizer-CETZf2NR.js.map +0 -1
- package/dist/tokenizer-CMK8MtYl.cjs +0 -30
- package/dist/tokenizer-CMK8MtYl.cjs.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/utils/strip-comments.ts","../src/extensions/b32.ts","../src/extensions/float.ts","../src/extensions/same.ts","../src/cbor.ts"],"sourcesContent":["/**\n * Strip whitespace and EDN §2.2 comments from app-string content.\n *\n * Used by extensions whose content allows the same comment syntax as byte\n * string literals (b32, h32, float, …):\n * SP / LF / CR — whitespace, skipped\n * # … LF — line comment\n * // … LF — line comment\n * /* … *\\/ — block comment (unterminated → SyntaxError)\n * / … / — block comment (unterminated → SyntaxError)\n */\nexport function stripComments(str: string): string {\n let out = '';\n let i = 0;\n while (i < str.length) {\n const ch = str[i];\n if (ch === ' ' || ch === '\\n' || ch === '\\r') {\n i++;\n continue;\n }\n if (ch === '#') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (ch === '/') {\n const next = str[i + 1] ?? '';\n if (next === '/') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (next === '*') {\n i += 2;\n while (\n i < str.length &&\n !(str[i] === '*' && (str[i + 1] ?? '') === '/')\n )\n i++;\n if (i >= str.length)\n throw new SyntaxError('unterminated block comment');\n i += 2; // consume */\n continue;\n }\n // / … / block comment\n i++;\n while (i < str.length && str[i] !== '/') i++;\n if (i >= str.length) throw new SyntaxError('unterminated block comment');\n i++; // consume closing /\n continue;\n }\n out += ch;\n i++;\n }\n return out;\n}\n","import type { CborExtension } from './types';\nimport { CborByteString } from '../ast/CborByteString';\nimport { stripComments } from '../utils/strip-comments';\n\nconst B32_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';\nconst H32_ALPHA = '0123456789ABCDEFGHIJKLMNOPQRSTUV';\n\nfunction stripBase32Padding(str: string): string {\n let end = str.length;\n while (end > 0 && str.charCodeAt(end - 1) === 0x3d) end--;\n return str.slice(0, end);\n}\n\nfunction base32Decode(\n str: string,\n alpha: string,\n onError?: (msg: string) => void\n): Uint8Array {\n // Padding is optional; strip it before decoding.\n const s = stripBase32Padding(str).toUpperCase();\n // RFC 4648 §6: valid unpadded lengths mod 8 are 0, 2, 4, 5, 7.\n // Lengths 1, 3, 6 can never result from any valid byte sequence.\n const rem = s.length % 8;\n if (rem === 1 || rem === 3 || rem === 6)\n throw new SyntaxError(`invalid base32 length: ${s.length} characters`);\n const lookup = new Uint8Array(128).fill(0xff);\n for (let i = 0; i < alpha.length; i++) lookup[alpha.charCodeAt(i)] = i;\n const out = new Uint8Array(Math.floor((s.length * 5) / 8));\n let buf = 0,\n bufBits = 0,\n outIdx = 0;\n for (const ch of s) {\n const code = ch.charCodeAt(0);\n const val = code < 128 ? lookup[code] : 0xff;\n if (val === 0xff)\n throw new SyntaxError(\n `invalid character in byte string: ${JSON.stringify(ch)}`\n );\n buf = (buf << 5) | val;\n bufBits += 5;\n if (bufBits >= 8) {\n bufBits -= 8;\n out[outIdx++] = (buf >> bufBits) & 0xff;\n }\n }\n // RFC 4648 §3.5: trailing bits in the final quantum must be zero.\n if (bufBits > 0 && (buf & ((1 << bufBits) - 1)) !== 0) {\n const msg = 'non-zero trailing bits in base32 input';\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n return out;\n}\n\n/** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */\nexport const b32: CborExtension = {\n appStringPrefixes: ['b32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), B32_ALPHA, onError),\n {\n ednEncoding: 'base32',\n }\n );\n },\n};\n\n/** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */\nexport const h32: CborExtension = {\n appStringPrefixes: ['h32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), H32_ALPHA, onError),\n {\n ednEncoding: 'base32hex',\n }\n );\n },\n};\n","/**\n * `float'...'` / `float<<...>>` app-string extension.\n *\n * Interprets a hex bit-pattern as an IEEE 754 floating-point value:\n * - 4 hex digits (2 bytes) → float16 (CBOR major-7, additional 25 / 0xf9)\n * - 8 hex digits (4 bytes) → float32 (CBOR major-7, additional 26 / 0xfa)\n * - 16 hex digits (8 bytes) → float64 (CBOR major-7, additional 27 / 0xfb)\n *\n * The string form `float'...'` supports the same comment syntax as `h'...'`:\n * slash-delimited block comments, C-style block comments, line comments (`//`\n * and `#`). The extension strips comments from the raw content itself.\n *\n * The sequence form `float<<byteStr>>` accepts a single byte-string expression\n * (e.g. `float<<h'7ef0'>>`) and interprets its bytes as float bits.\n *\n * Defined in draft-ietf-cbor-edn-literals §3.7. Not included in the default\n * extension set (must be added explicitly):\n *\n * @example\n * import { float } from '@cbortech/cbor';\n * parseCDN(\"float'7ef0'\", { extensions: [float] }); // NaN as float16\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\nimport { CborFloat } from '../ast/CborFloat';\nimport { CborByteString } from '../ast/CborByteString';\nimport { float16BitsToFloat64, float64ToFloat16Bits } from '../utils/float16';\nimport { stripComments } from '../utils/strip-comments';\nimport { hexToBytes } from '../utils/hex';\nimport type { EncodingWidth } from '../cbor/encode';\n\n// ── Bit-preserving CborFloat subclasses ───────────────────────────────────────\n// CborFloat stores a JS `number`, which loses NaN payloads. These subclasses\n// override _toCBOR() to emit the original bit pattern verbatim.\n\nclass CborFloat16Bits extends CborFloat {\n private readonly _bits: number;\n constructor(bits: number) {\n super(float16BitsToFloat64(bits), { precision: 'half' });\n this._bits = bits & 0xffff;\n }\n override _toCBOR(): Uint8Array {\n return new Uint8Array([0xf9, (this._bits >> 8) & 0xff, this._bits & 0xff]);\n }\n}\n\nclass CborFloat32Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat32(0, false), {\n precision: 'single',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(5);\n out[0] = 0xfa;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nclass CborFloat64Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat64(0, false), {\n precision: 'double',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(9);\n out[0] = 0xfb;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nfunction floatFromBytes(bytes: Uint8Array): CborFloat {\n if (bytes.length === 2) {\n const bits = (bytes[0]! << 8) | bytes[1]!;\n return new CborFloat16Bits(bits);\n }\n if (bytes.length === 4) return new CborFloat32Bits(bytes);\n if (bytes.length === 8) return new CborFloat64Bits(bytes);\n throw new SyntaxError(\n `float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${bytes.length} bytes`\n );\n}\n\n/** Expand float16 bit pattern to 4-byte float32 (bit-exact, preserves NaN payloads). */\nfunction float16BitsToFloat32Bytes(bits16: number): Uint8Array {\n const sign = (bits16 >>> 15) & 1;\n const exp16 = (bits16 >>> 10) & 0x1f;\n const mant16 = bits16 & 0x3ff;\n let bits32: number;\n if (exp16 === 0x1f) {\n bits32 = (sign << 31) | 0x7f800000 | (mant16 << 13);\n } else if (exp16 === 0 && mant16 === 0) {\n bits32 = sign << 31;\n } else if (exp16 === 0) {\n // Denormal float16 → normal float32\n let m = mant16;\n let shifts = 0;\n while ((m & 0x200) === 0) {\n m <<= 1;\n shifts++;\n }\n bits32 = (sign << 31) | ((112 - shifts) << 23) | ((m & 0x1ff) << 14);\n } else {\n bits32 = (sign << 31) | ((exp16 + 112) << 23) | (mant16 << 13);\n }\n const out = new Uint8Array(4);\n new DataView(out.buffer).setUint32(0, bits32 >>> 0, false);\n return out;\n}\n\n/** Expand float16 bit pattern to 8-byte float64 (bit-exact, preserves NaN payloads). */\nfunction float16BitsToFloat64Bytes(bits16: number): Uint8Array {\n const sign = (bits16 >>> 15) & 1;\n const exp16 = (bits16 >>> 10) & 0x1f;\n const mant16 = bits16 & 0x3ff;\n const out = new Uint8Array(8);\n const dv = new DataView(out.buffer);\n if (exp16 === 0x1f) {\n dv.setUint32(0, ((sign << 31) | 0x7ff00000 | (mant16 << 10)) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else if (exp16 === 0 && mant16 === 0) {\n dv.setUint32(0, (sign << 31) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else if (exp16 === 0) {\n // Denormal float16 → normal float64\n let m = mant16;\n let shifts = 0;\n while ((m & 0x200) === 0) {\n m <<= 1;\n shifts++;\n }\n dv.setUint32(\n 0,\n ((sign << 31) | ((1008 - shifts) << 20) | ((m & 0x1ff) << 11)) >>> 0,\n false\n );\n dv.setUint32(4, 0, false);\n } else {\n dv.setUint32(\n 0,\n ((sign << 31) | ((exp16 + 1008) << 20) | (mant16 << 10)) >>> 0,\n false\n );\n dv.setUint32(4, 0, false);\n }\n return out;\n}\n\n/** Expand float32 bit pattern to 8-byte float64 (bit-exact, preserves NaN payloads). */\nfunction float32BitsToFloat64Bytes(bytes4: Uint8Array): Uint8Array {\n const bits32 = new DataView(bytes4.buffer, bytes4.byteOffset).getUint32(\n 0,\n false\n );\n const sign = (bits32 >>> 31) & 1;\n const exp32 = (bits32 >>> 23) & 0xff;\n const mant32 = bits32 & 0x7fffff;\n const out = new Uint8Array(8);\n const dv = new DataView(out.buffer);\n if (exp32 === 0xff) {\n dv.setUint32(0, ((sign << 31) | 0x7ff00000 | (mant32 >>> 3)) >>> 0, false);\n dv.setUint32(4, (mant32 & 7) << 29, false);\n } else if (exp32 === 0 && mant32 === 0) {\n dv.setUint32(0, (sign << 31) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else {\n // Normal or denormal: JS arithmetic is exact (float32 ⊂ float64), NaN handled above.\n const f64 = new DataView(bytes4.buffer, bytes4.byteOffset).getFloat32(\n 0,\n false\n );\n dv.setFloat64(0, f64, false);\n }\n return out;\n}\n\n/**\n * Re-encode float bytes at a target precision (_1=half, _2=single, _3=double).\n * Returns undefined if the conversion is lossy (caller should warn).\n */\nfunction reencodeFloat(\n bytes: Uint8Array,\n targetWidth: 1 | 2 | 3,\n onError: (msg: string) => void\n): CborFloat {\n const naturalWidth = bytes.length === 2 ? 1 : bytes.length === 4 ? 2 : 3;\n\n if (naturalWidth === 1) {\n const bits16 = (bytes[0]! << 8) | bytes[1]!;\n if (targetWidth === 2)\n return new CborFloat32Bits(float16BitsToFloat32Bytes(bits16));\n if (targetWidth === 3)\n return new CborFloat64Bits(float16BitsToFloat64Bytes(bits16));\n }\n\n if (naturalWidth === 2) {\n if (targetWidth === 3)\n return new CborFloat64Bits(float32BitsToFloat64Bytes(bytes));\n if (targetWidth === 1) {\n const f32 = new DataView(bytes.buffer, bytes.byteOffset).getFloat32(\n 0,\n false\n );\n const bits16 = float64ToFloat16Bits(f32);\n if (!Object.is(float16BitsToFloat64(bits16), f32) && !isNaN(f32)) {\n onError(\n `float'...' value cannot be exactly represented as float16 (_1)`\n );\n }\n return new CborFloat16Bits(bits16);\n }\n }\n\n if (naturalWidth === 3) {\n const f64 = new DataView(bytes.buffer, bytes.byteOffset).getFloat64(\n 0,\n false\n );\n if (targetWidth === 1) {\n const bits16 = float64ToFloat16Bits(f64);\n if (!Object.is(float16BitsToFloat64(bits16), f64) && !isNaN(f64)) {\n onError(\n `float'...' value cannot be exactly represented as float16 (_1)`\n );\n }\n return new CborFloat16Bits(bits16);\n }\n if (targetWidth === 2) {\n const f32 = Math.fround(f64);\n if (!Object.is(f32, f64) && !isNaN(f64)) {\n onError(\n `float'...' value cannot be exactly represented as float32 (_2)`\n );\n }\n const out = new Uint8Array(4);\n new DataView(out.buffer).setFloat32(0, f32, false);\n return new CborFloat32Bits(out);\n }\n }\n\n // naturalWidth === targetWidth: identity (already handled by caller)\n return floatFromBytes(bytes);\n}\n\n/**\n * Extension object for `float'...'` / `float<<...>>`.\n * Pass to `parseCDN(..., { extensions: [float] })`.\n */\nexport const float: CborExtension = {\n appStringPrefixes: ['float'],\n\n parseAppString(\n _prefix: string,\n content: string,\n onError?: (msg: string) => void,\n options?: { encodingWidth?: EncodingWidth }\n ): CborItem {\n const hex = stripComments(content);\n if (!/^[0-9a-fA-F]*$/.test(hex))\n throw new SyntaxError(`float'...' contains non-hex characters`);\n if (hex.length % 2 !== 0)\n throw new SyntaxError(\n `float'...' hex content has odd length (${hex.length} digits)`\n );\n const bytes = hexToBytes(hex);\n const ew = options?.encodingWidth;\n if (ew === undefined) return floatFromBytes(bytes);\n if (ew !== 1 && ew !== 2 && ew !== 3) {\n const msg = `float'...' encoding indicator _${ew} is not valid; use _1, _2, or _3`;\n if (onError) {\n onError(msg);\n return floatFromBytes(bytes);\n }\n throw new SyntaxError(msg);\n }\n const naturalWidth = bytes.length === 2 ? 1 : bytes.length === 4 ? 2 : 3;\n if (ew === naturalWidth) return floatFromBytes(bytes);\n const fallbackOnError =\n onError ??\n ((msg: string) => {\n throw new SyntaxError(msg);\n });\n return reencodeFloat(bytes, ew, fallbackOnError);\n },\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(\n `float<<...>> requires exactly one byte-string item`\n );\n if (items.length > 1) {\n const msg = `float<<...>> expects 1 item; got ${items.length} — using first`;\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n if (!(items[0] instanceof CborByteString))\n throw new SyntaxError(`float<<...>> item must be a byte string`);\n return floatFromBytes(items[0].value);\n },\n};\n\nexport default float;\n","/**\n * `same<<expr, expr, ...>>` app-sequence extension.\n *\n * Evaluates every item in the sequence to CBOR bytes and asserts that all\n * produce identical bytes. Returns the first item if all match.\n *\n * In strict mode a mismatch throws a `SyntaxError`. In lenient mode\n * (`strict: false`) a mismatch emits a `ParseWarning` and returns the first\n * item so parsing can continue.\n *\n * `same<<x>>` (single item) is a no-op assertion that always passes.\n *\n * The parsed result is wrapped in `CborAppSeqResult` so that `toCDN()` round-trips\n * the original `same<<...>>` notation. `toCBOR()` and `toJS()` delegate\n * transparently to the inner item; `appStrings: false` produces the resolved value.\n * The result is not directly `instanceof` the inner item's class.\n *\n * This extension is a testing/validation construct from the cabo/edn-abnf\n * corpus and is NOT part of draft-ietf-cbor-edn-literals. It is not included\n * in the default extension set. Add it explicitly:\n *\n * @example\n * import { same } from '@cbortech/cbor';\n * parseCDN(\"same<<b64'AA',h'00'>>\", { extensions: [same] }); // h'00'\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Extension object for `same<<...>>`.\n * Pass to `parseCDN(..., { extensions: [same] })`.\n */\nexport const same: CborExtension = {\n appStringPrefixes: ['same'],\n preserveAppSeqSource: true,\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(`same<<...>> requires at least one item`);\n const first = items[0]!;\n const firstCbor = first.toCBOR();\n for (let i = 1; i < items.length; i++) {\n const otherCbor = items[i]!.toCBOR();\n if (!bytesEqual(firstCbor, otherCbor)) {\n const msg = `same<<...>>: item ${i} produces different CBOR bytes than item 0`;\n if (onError)\n onError(msg); // lenient: warn + return first item\n else throw new SyntaxError(msg);\n }\n }\n return first;\n },\n};\n\nexport default same;\n","import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromCBORSeqOptions,\n FromCDNOptions,\n FromCDNSeqOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ParseWarning,\n ToCBOROptions,\n ToCDNOptions,\n ToHexDumpOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromCBORSeq(input, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromCDNSeq(text: string, options?: FromCDNSeqOptions): Generator<CborItem> {\n for (const item of CBOR.fromCDNSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromHexDumpSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.decodeSeq(input, this.#merge(options));\n }\n\n *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.parseSeq(text, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.compile(text, this.#merge(options));\n }\n\n decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return CBOR.decompile(input, this.#merge(options));\n }\n\n toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return CBOR.toHex(input, this.#merge(options));\n }\n\n fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromHex(text, this.#merge(options));\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n const merged = this.#merge(options);\n const node = CBOR.fromCBOR(input, merged);\n node._defaults = this.#defaults;\n return node.toCDN(merged);\n }\n\n /** @deprecated Use `compile()` instead. */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n /** @deprecated Use `compile()` instead. */\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n const merged = this.#merge(options);\n return CBOR.fromCDN(text, merged).toCBOR(merged);\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** アノテーション付き hex dump テキストから CBOR Sequence を item ごとにデコードするジェネレータ。 */\n static *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n yield* CBOR.fromCBORSeq(new Uint8Array(bytes), options);\n }\n\n /** CBOR Sequence (RFC 8742) を item ごとにデコードするジェネレータ。 */\n static *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n const bytes =\n input instanceof ArrayBuffer ||\n (typeof SharedArrayBuffer !== 'undefined' &&\n input instanceof SharedArrayBuffer)\n ? new Uint8Array(input)\n : new Uint8Array(\n (input as ArrayBufferView).buffer,\n (input as ArrayBufferView).byteOffset,\n (input as ArrayBufferView).byteLength\n );\n let offset = 0;\n while (offset < bytes.byteLength) {\n const item = decodeCBOR(bytes, {\n ...options,\n offset,\n allowTrailing: true,\n });\n yield item;\n offset = item.end!;\n }\n }\n\n /** CDN テキストの複数 item を 1 つずつパースするジェネレータ。 */\n static *fromCDNSeq(\n text: string,\n options?: FromCDNSeqOptions\n ): Generator<CborItem> {\n let offset = 0;\n let isFirst = true;\n while (true) {\n const {\n offset: next,\n hadSeparator,\n commaOffset,\n } = skipCDNSeparator(text, offset, options);\n // Leading comma: comma before the first item (including comma-only input).\n // Checked before the EOF break so that \",\" alone is also caught.\n // Trailing comma is valid per ABNF SOC = S [\",\" S] and is silently accepted.\n if (isFirst && commaOffset >= 0) {\n const msg = 'leading comma in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, commaOffset, options);\n }\n if (next >= text.length) break;\n if (!isFirst && !hadSeparator) {\n const msg =\n 'CDN sequence items must be separated by whitespace, comma, or comment';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, next, options);\n }\n offset = next;\n let item: CborItem;\n try {\n // _skipRS: true causes the tokenizer to treat RS (U+001E, RFC 7464) as\n // whitespace, preventing it from corrupting string-literal contents via\n // a global text replacement.\n item = parseCDN(text, {\n ...options,\n offset,\n allowTrailing: true,\n _skipRS: true,\n } as FromCDNOptions);\n } catch (e) {\n if (options?.strict !== false) throw e;\n emitCDNSeqWarning(\n e instanceof Error ? e.message : String(e),\n offset,\n options\n );\n break;\n }\n yield item;\n offset = item.end!;\n isFirst = false;\n }\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Decode a CBOR Sequence (RFC 8742), yielding each item as a JavaScript value. */\n static *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCBORSeq(input, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Parse a CDN Sequence text string, yielding each item as a JavaScript value. */\n static *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCDNSeq(text, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Compile a CDN text string to CBOR binary data.\n * Multi-item CDN Sequences produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromCDNSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Decompile CBOR binary data to a CDN text string.\n * CBOR Sequences (RFC 8742) produce multi-item CDN output, with items separated by newlines.\n */\n static decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toCDN(options))\n .join('\\n');\n }\n\n /**\n * Convert CBOR binary data to an annotated hex dump string.\n * CBOR Sequences (RFC 8742) produce one dump per item, separated by newlines.\n */\n static toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toHexDump(options))\n .join('\\n');\n }\n\n /**\n * Parse an annotated hex dump string to CBOR binary data.\n * Multi-item dumps produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromHexDumpSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.decompile()` instead.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /** @deprecated Use `CBOR.decompile()` instead. */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.compile()` instead.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /** @deprecated Use `CBOR.compile()` instead. */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '—') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\nfunction emitCDNSeqWarning(\n msg: string,\n offset: number,\n options: FromCDNSeqOptions | undefined\n): void {\n const w: ParseWarning = { message: msg, offset };\n if (options?.onWarning) options.onWarning(w);\n else if (!options?.silent)\n console.warn(`CDN sequence warning at offset ${offset}: ${msg}`);\n}\n\n/**\n * CDN sequence の item 間にある空白・コメント・省略可能なカンマを読み飛ばし、\n * 次の item が始まる文字位置と、何らかの separator が存在したかどうかを返す。\n * 未終端のブロックコメントは strict モードでは throw し、\n * strict: false の場合は警告を emit して末尾まで読み飛ばす。\n */\nfunction skipCDNSeparator(\n text: string,\n from: number,\n options: FromCDNSeqOptions | undefined\n): { offset: number; hadSeparator: boolean; commaOffset: number } {\n let i = from;\n let hadSeparator = false;\n let seenComma = false;\n let commaOffset = -1;\n while (i < text.length) {\n const ch = text[i];\n if (\n ch === ' ' ||\n ch === '\\t' ||\n ch === '\\r' ||\n ch === '\\n' ||\n ch === '\\x1e'\n ) {\n hadSeparator = true;\n i++;\n continue;\n }\n if (ch === '#') {\n hadSeparator = true;\n const nl = text.indexOf('\\n', i + 1);\n i = nl < 0 ? text.length : nl + 1;\n continue;\n }\n if (ch === '/' && text[i + 1] === '/') {\n hadSeparator = true;\n const nl = text.indexOf('\\n', i + 2);\n i = nl < 0 ? text.length : nl + 1;\n continue;\n }\n if (ch === '/' && text[i + 1] === '*') {\n hadSeparator = true;\n const end = text.indexOf('*/', i + 2);\n if (end < 0) {\n const msg = 'unterminated /* comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options);\n i = text.length;\n } else {\n i = end + 2;\n }\n continue;\n }\n if (ch === '/' && text[i + 1] !== '/') {\n hadSeparator = true;\n const end = text.indexOf('/', i + 1);\n if (end < 0) {\n const msg = 'unterminated / comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options);\n i = text.length;\n } else {\n i = end + 1;\n }\n continue;\n }\n if (ch === ',' && !seenComma) {\n hadSeparator = true;\n seenComma = true;\n commaOffset = i;\n i++;\n continue;\n }\n break;\n }\n return { offset: i, hadSeparator, commaOffset };\n}\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":"kLAWA,SAAgB,EAAc,EAAqB,CACjD,IAAI,EAAM,GACN,EAAI,EACR,KAAO,EAAI,EAAI,QAAQ,CACrB,IAAM,EAAK,EAAI,GACf,GAAI,IAAO,KAAO,IAAO;GAAQ,IAAO,KAAM,CAC5C,IACA,QACF,CACA,GAAI,IAAO,IAAK,CACd,KAAO,EAAI,EAAI,QAAU,EAAI,KAAO;GAAM,IAC1C,QACF,CACA,GAAI,IAAO,IAAK,CACd,IAAM,EAAO,EAAI,EAAI,IAAM,GAC3B,GAAI,IAAS,IAAK,CAChB,KAAO,EAAI,EAAI,QAAU,EAAI,KAAO;GAAM,IAC1C,QACF,CACA,GAAI,IAAS,IAAK,CAEhB,IADA,GAAK,EAEH,EAAI,EAAI,QACR,EAAE,EAAI,KAAO,MAAQ,EAAI,EAAI,IAAM,MAAQ,MAE3C,IACF,GAAI,GAAK,EAAI,OACX,MAAU,YAAY,4BAA4B,EACpD,GAAK,EACL,QACF,CAGA,IADA,IACO,EAAI,EAAI,QAAU,EAAI,KAAO,KAAK,IACzC,GAAI,GAAK,EAAI,OAAQ,MAAU,YAAY,4BAA4B,EACvE,IACA,QACF,CACA,GAAO,EACP,GACF,CACA,OAAO,CACT,CCjDA,IAAM,EAAY,mCACZ,EAAY,mCAElB,SAAS,EAAmB,EAAqB,CAC/C,IAAI,EAAM,EAAI,OACd,KAAO,EAAM,GA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,eAAc,aAAY,CAChD,CAGA,SAAS,EACP,EAC6B,CAC7B,GAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAI,KAAK,MAAM,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,CAAK,CAAC,CAAC,EACrD,OAAO,IAAM,EAAI,IAAA,GAAY,CAC/B,CACA,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,EAClB,GAAK,IAAA,EAGhB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/utils/strip-comments.ts","../src/extensions/b32.ts","../src/extensions/float.ts","../src/extensions/same.ts","../src/cbor.ts"],"sourcesContent":["/**\n * Strip whitespace and EDN §2.2 comments from app-string content.\n *\n * Used by extensions whose content allows the same comment syntax as byte\n * string literals (b32, h32, float, …):\n * SP / LF / CR — whitespace, skipped\n * # … LF — line comment\n * // … LF — line comment\n * /* … *\\/ — block comment (unterminated → SyntaxError)\n * / … / — block comment (unterminated → SyntaxError)\n */\nexport function stripComments(str: string): string {\n let out = '';\n let i = 0;\n while (i < str.length) {\n const ch = str[i];\n if (ch === ' ' || ch === '\\n' || ch === '\\r') {\n i++;\n continue;\n }\n if (ch === '#') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (ch === '/') {\n const next = str[i + 1] ?? '';\n if (next === '/') {\n while (i < str.length && str[i] !== '\\n') i++;\n continue;\n }\n if (next === '*') {\n i += 2;\n while (\n i < str.length &&\n !(str[i] === '*' && (str[i + 1] ?? '') === '/')\n )\n i++;\n if (i >= str.length)\n throw new SyntaxError('unterminated block comment');\n i += 2; // consume */\n continue;\n }\n // / … / block comment\n i++;\n while (i < str.length && str[i] !== '/') i++;\n if (i >= str.length) throw new SyntaxError('unterminated block comment');\n i++; // consume closing /\n continue;\n }\n out += ch;\n i++;\n }\n return out;\n}\n","import type { CborExtension } from './types';\nimport { CborByteString } from '../ast/CborByteString';\nimport { stripComments } from '../utils/strip-comments';\n\nconst B32_ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';\nconst H32_ALPHA = '0123456789ABCDEFGHIJKLMNOPQRSTUV';\n\nfunction stripBase32Padding(str: string): string {\n let end = str.length;\n while (end > 0 && str.charCodeAt(end - 1) === 0x3d) end--;\n return str.slice(0, end);\n}\n\nfunction base32Decode(\n str: string,\n alpha: string,\n onError?: (msg: string) => void\n): Uint8Array {\n // Padding is optional; strip it before decoding.\n const s = stripBase32Padding(str).toUpperCase();\n // RFC 4648 §6: valid unpadded lengths mod 8 are 0, 2, 4, 5, 7.\n // Lengths 1, 3, 6 can never result from any valid byte sequence.\n const rem = s.length % 8;\n if (rem === 1 || rem === 3 || rem === 6)\n throw new SyntaxError(`invalid base32 length: ${s.length} characters`);\n const lookup = new Uint8Array(128).fill(0xff);\n for (let i = 0; i < alpha.length; i++) lookup[alpha.charCodeAt(i)] = i;\n const out = new Uint8Array(Math.floor((s.length * 5) / 8));\n let buf = 0,\n bufBits = 0,\n outIdx = 0;\n for (const ch of s) {\n const code = ch.charCodeAt(0);\n const val = code < 128 ? lookup[code] : 0xff;\n if (val === 0xff)\n throw new SyntaxError(\n `invalid character in byte string: ${JSON.stringify(ch)}`\n );\n buf = (buf << 5) | val;\n bufBits += 5;\n if (bufBits >= 8) {\n bufBits -= 8;\n out[outIdx++] = (buf >> bufBits) & 0xff;\n }\n }\n // RFC 4648 §3.5: trailing bits in the final quantum must be zero.\n if (bufBits > 0 && (buf & ((1 << bufBits) - 1)) !== 0) {\n const msg = 'non-zero trailing bits in base32 input';\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n return out;\n}\n\n/** RFC 4648 §6 Base32 (A–Z 2–7) app-string extension. */\nexport const b32: CborExtension = {\n appStringPrefixes: ['b32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), B32_ALPHA, onError),\n {\n ednEncoding: 'base32',\n }\n );\n },\n};\n\n/** RFC 4648 §7 Base32Hex (0–9 A–V) app-string extension. */\nexport const h32: CborExtension = {\n appStringPrefixes: ['h32'],\n parseAppString(_prefix, content, onError) {\n return new CborByteString(\n base32Decode(stripComments(content), H32_ALPHA, onError),\n {\n ednEncoding: 'base32hex',\n }\n );\n },\n};\n","/**\n * `float'...'` / `float<<...>>` app-string extension.\n *\n * Interprets a hex bit-pattern as an IEEE 754 floating-point value:\n * - 4 hex digits (2 bytes) → float16 (CBOR major-7, additional 25 / 0xf9)\n * - 8 hex digits (4 bytes) → float32 (CBOR major-7, additional 26 / 0xfa)\n * - 16 hex digits (8 bytes) → float64 (CBOR major-7, additional 27 / 0xfb)\n *\n * The string form `float'...'` supports the same comment syntax as `h'...'`:\n * slash-delimited block comments, C-style block comments, line comments (`//`\n * and `#`). The extension strips comments from the raw content itself.\n *\n * The sequence form `float<<byteStr>>` accepts a single byte-string expression\n * (e.g. `float<<h'7ef0'>>`) and interprets its bytes as float bits.\n *\n * Defined in draft-ietf-cbor-edn-literals §3.7. Not included in the default\n * extension set (must be added explicitly):\n *\n * @example\n * import { float } from '@cbortech/cbor';\n * parseCDN(\"float'7ef0'\", { extensions: [float] }); // NaN as float16\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\nimport { CborFloat } from '../ast/CborFloat';\nimport { CborByteString } from '../ast/CborByteString';\nimport { float16BitsToFloat64, float64ToFloat16Bits } from '../utils/float16';\nimport { stripComments } from '../utils/strip-comments';\nimport { hexToBytes } from '../utils/hex';\nimport type { EncodingWidth } from '../cbor/encode';\n\n// ── Bit-preserving CborFloat subclasses ───────────────────────────────────────\n// CborFloat stores a JS `number`, which loses NaN payloads. These subclasses\n// override _toCBOR() to emit the original bit pattern verbatim.\n\nclass CborFloat16Bits extends CborFloat {\n private readonly _bits: number;\n constructor(bits: number) {\n super(float16BitsToFloat64(bits), { precision: 'half' });\n this._bits = bits & 0xffff;\n }\n override _toCBOR(): Uint8Array {\n return new Uint8Array([0xf9, (this._bits >> 8) & 0xff, this._bits & 0xff]);\n }\n}\n\nclass CborFloat32Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat32(0, false), {\n precision: 'single',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(5);\n out[0] = 0xfa;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nclass CborFloat64Bits extends CborFloat {\n private readonly _raw: Uint8Array;\n constructor(bytes: Uint8Array) {\n super(new DataView(bytes.buffer, bytes.byteOffset).getFloat64(0, false), {\n precision: 'double',\n });\n this._raw = bytes.slice();\n }\n override _toCBOR(): Uint8Array {\n const out = new Uint8Array(9);\n out[0] = 0xfb;\n out.set(this._raw, 1);\n return out;\n }\n}\n\nfunction floatFromBytes(bytes: Uint8Array): CborFloat {\n if (bytes.length === 2) {\n const bits = (bytes[0]! << 8) | bytes[1]!;\n return new CborFloat16Bits(bits);\n }\n if (bytes.length === 4) return new CborFloat32Bits(bytes);\n if (bytes.length === 8) return new CborFloat64Bits(bytes);\n throw new SyntaxError(\n `float'...' requires 4, 8, or 16 hex digits (2, 4, or 8 bytes); got ${bytes.length} bytes`\n );\n}\n\n/** Expand float16 bit pattern to 4-byte float32 (bit-exact, preserves NaN payloads). */\nfunction float16BitsToFloat32Bytes(bits16: number): Uint8Array {\n const sign = (bits16 >>> 15) & 1;\n const exp16 = (bits16 >>> 10) & 0x1f;\n const mant16 = bits16 & 0x3ff;\n let bits32: number;\n if (exp16 === 0x1f) {\n bits32 = (sign << 31) | 0x7f800000 | (mant16 << 13);\n } else if (exp16 === 0 && mant16 === 0) {\n bits32 = sign << 31;\n } else if (exp16 === 0) {\n // Denormal float16 → normal float32\n let m = mant16;\n let shifts = 0;\n while ((m & 0x200) === 0) {\n m <<= 1;\n shifts++;\n }\n bits32 = (sign << 31) | ((112 - shifts) << 23) | ((m & 0x1ff) << 14);\n } else {\n bits32 = (sign << 31) | ((exp16 + 112) << 23) | (mant16 << 13);\n }\n const out = new Uint8Array(4);\n new DataView(out.buffer).setUint32(0, bits32 >>> 0, false);\n return out;\n}\n\n/** Expand float16 bit pattern to 8-byte float64 (bit-exact, preserves NaN payloads). */\nfunction float16BitsToFloat64Bytes(bits16: number): Uint8Array {\n const sign = (bits16 >>> 15) & 1;\n const exp16 = (bits16 >>> 10) & 0x1f;\n const mant16 = bits16 & 0x3ff;\n const out = new Uint8Array(8);\n const dv = new DataView(out.buffer);\n if (exp16 === 0x1f) {\n dv.setUint32(0, ((sign << 31) | 0x7ff00000 | (mant16 << 10)) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else if (exp16 === 0 && mant16 === 0) {\n dv.setUint32(0, (sign << 31) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else if (exp16 === 0) {\n // Denormal float16 → normal float64\n let m = mant16;\n let shifts = 0;\n while ((m & 0x200) === 0) {\n m <<= 1;\n shifts++;\n }\n dv.setUint32(\n 0,\n ((sign << 31) | ((1008 - shifts) << 20) | ((m & 0x1ff) << 11)) >>> 0,\n false\n );\n dv.setUint32(4, 0, false);\n } else {\n dv.setUint32(\n 0,\n ((sign << 31) | ((exp16 + 1008) << 20) | (mant16 << 10)) >>> 0,\n false\n );\n dv.setUint32(4, 0, false);\n }\n return out;\n}\n\n/** Expand float32 bit pattern to 8-byte float64 (bit-exact, preserves NaN payloads). */\nfunction float32BitsToFloat64Bytes(bytes4: Uint8Array): Uint8Array {\n const bits32 = new DataView(bytes4.buffer, bytes4.byteOffset).getUint32(\n 0,\n false\n );\n const sign = (bits32 >>> 31) & 1;\n const exp32 = (bits32 >>> 23) & 0xff;\n const mant32 = bits32 & 0x7fffff;\n const out = new Uint8Array(8);\n const dv = new DataView(out.buffer);\n if (exp32 === 0xff) {\n dv.setUint32(0, ((sign << 31) | 0x7ff00000 | (mant32 >>> 3)) >>> 0, false);\n dv.setUint32(4, (mant32 & 7) << 29, false);\n } else if (exp32 === 0 && mant32 === 0) {\n dv.setUint32(0, (sign << 31) >>> 0, false);\n dv.setUint32(4, 0, false);\n } else {\n // Normal or denormal: JS arithmetic is exact (float32 ⊂ float64), NaN handled above.\n const f64 = new DataView(bytes4.buffer, bytes4.byteOffset).getFloat32(\n 0,\n false\n );\n dv.setFloat64(0, f64, false);\n }\n return out;\n}\n\n/**\n * Re-encode float bytes at a target precision (_1=half, _2=single, _3=double).\n * Returns undefined if the conversion is lossy (caller should warn).\n */\nfunction reencodeFloat(\n bytes: Uint8Array,\n targetWidth: 1 | 2 | 3,\n onError: (msg: string) => void\n): CborFloat {\n const naturalWidth = bytes.length === 2 ? 1 : bytes.length === 4 ? 2 : 3;\n\n if (naturalWidth === 1) {\n const bits16 = (bytes[0]! << 8) | bytes[1]!;\n if (targetWidth === 2)\n return new CborFloat32Bits(float16BitsToFloat32Bytes(bits16));\n if (targetWidth === 3)\n return new CborFloat64Bits(float16BitsToFloat64Bytes(bits16));\n }\n\n if (naturalWidth === 2) {\n if (targetWidth === 3)\n return new CborFloat64Bits(float32BitsToFloat64Bytes(bytes));\n if (targetWidth === 1) {\n const f32 = new DataView(bytes.buffer, bytes.byteOffset).getFloat32(\n 0,\n false\n );\n const bits16 = float64ToFloat16Bits(f32);\n if (!Object.is(float16BitsToFloat64(bits16), f32) && !isNaN(f32)) {\n onError(\n `float'...' value cannot be exactly represented as float16 (_1)`\n );\n }\n return new CborFloat16Bits(bits16);\n }\n }\n\n if (naturalWidth === 3) {\n const f64 = new DataView(bytes.buffer, bytes.byteOffset).getFloat64(\n 0,\n false\n );\n if (targetWidth === 1) {\n const bits16 = float64ToFloat16Bits(f64);\n if (!Object.is(float16BitsToFloat64(bits16), f64) && !isNaN(f64)) {\n onError(\n `float'...' value cannot be exactly represented as float16 (_1)`\n );\n }\n return new CborFloat16Bits(bits16);\n }\n if (targetWidth === 2) {\n const f32 = Math.fround(f64);\n if (!Object.is(f32, f64) && !isNaN(f64)) {\n onError(\n `float'...' value cannot be exactly represented as float32 (_2)`\n );\n }\n const out = new Uint8Array(4);\n new DataView(out.buffer).setFloat32(0, f32, false);\n return new CborFloat32Bits(out);\n }\n }\n\n // naturalWidth === targetWidth: identity (already handled by caller)\n return floatFromBytes(bytes);\n}\n\n/**\n * Extension object for `float'...'` / `float<<...>>`.\n * Pass to `parseCDN(..., { extensions: [float] })`.\n */\nexport const float: CborExtension = {\n appStringPrefixes: ['float'],\n\n parseAppString(\n _prefix: string,\n content: string,\n onError?: (msg: string) => void,\n options?: { encodingWidth?: EncodingWidth }\n ): CborItem {\n const hex = stripComments(content);\n if (!/^[0-9a-fA-F]*$/.test(hex))\n throw new SyntaxError(`float'...' contains non-hex characters`);\n if (hex.length % 2 !== 0)\n throw new SyntaxError(\n `float'...' hex content has odd length (${hex.length} digits)`\n );\n const bytes = hexToBytes(hex);\n const ew = options?.encodingWidth;\n if (ew === undefined) return floatFromBytes(bytes);\n if (ew !== 1 && ew !== 2 && ew !== 3) {\n const msg = `float'...' encoding indicator _${ew} is not valid; use _1, _2, or _3`;\n if (onError) {\n onError(msg);\n return floatFromBytes(bytes);\n }\n throw new SyntaxError(msg);\n }\n const naturalWidth = bytes.length === 2 ? 1 : bytes.length === 4 ? 2 : 3;\n if (ew === naturalWidth) return floatFromBytes(bytes);\n const fallbackOnError =\n onError ??\n ((msg: string) => {\n throw new SyntaxError(msg);\n });\n return reencodeFloat(bytes, ew, fallbackOnError);\n },\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(\n `float<<...>> requires exactly one byte-string item`\n );\n if (items.length > 1) {\n const msg = `float<<...>> expects 1 item; got ${items.length} — using first`;\n if (onError) onError(msg);\n else throw new SyntaxError(msg);\n }\n if (!(items[0] instanceof CborByteString))\n throw new SyntaxError(`float<<...>> item must be a byte string`);\n return floatFromBytes(items[0].value);\n },\n};\n\nexport default float;\n","/**\n * `same<<expr, expr, ...>>` app-sequence extension.\n *\n * Evaluates every item in the sequence to CBOR bytes and asserts that all\n * produce identical bytes. Returns the first item if all match.\n *\n * In strict mode a mismatch throws a `SyntaxError`. In lenient mode\n * (`strict: false`) a mismatch emits a `ParseWarning` and returns the first\n * item so parsing can continue.\n *\n * `same<<x>>` (single item) is a no-op assertion that always passes.\n *\n * The parsed result is wrapped in `CborAppSeqResult` so that `toCDN()` round-trips\n * the original `same<<...>>` notation. `toCBOR()` and `toJS()` delegate\n * transparently to the inner item; `appStrings: false` produces the resolved value.\n * The result is not directly `instanceof` the inner item's class.\n *\n * This extension is a testing/validation construct from the cabo/edn-abnf\n * corpus and is NOT part of draft-ietf-cbor-edn-literals. It is not included\n * in the default extension set. Add it explicitly:\n *\n * @example\n * import { same } from '@cbortech/cbor';\n * parseCDN(\"same<<b64'AA',h'00'>>\", { extensions: [same] }); // h'00'\n */\n\nimport type { CborExtension } from './types';\nimport type { CborItem } from '../ast/CborItem';\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * Extension object for `same<<...>>`.\n * Pass to `parseCDN(..., { extensions: [same] })`.\n */\nexport const same: CborExtension = {\n appStringPrefixes: ['same'],\n preserveAppSeqSource: true,\n\n parseAppSequence(\n _prefix: string,\n items: CborItem[],\n onError?: (msg: string) => void\n ): CborItem {\n if (items.length === 0)\n throw new SyntaxError(`same<<...>> requires at least one item`);\n const first = items[0]!;\n const firstCbor = first.toCBOR();\n for (let i = 1; i < items.length; i++) {\n const otherCbor = items[i]!.toCBOR();\n if (!bytesEqual(firstCbor, otherCbor)) {\n const msg = `same<<...>>: item ${i} produces different CBOR bytes than item 0`;\n if (onError)\n onError(msg); // lenient: warn + return first item\n else throw new SyntaxError(msg);\n }\n }\n return first;\n },\n};\n\nexport default same;\n","import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromCBORSeqOptions,\n FromCDNOptions,\n FromCDNSeqOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ParseWarning,\n ToCBOROptions,\n ToCDNOptions,\n ToHexDumpOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { CdnSyntaxError } from './cdn/errors';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromCBORSeq(input, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromCDNSeq(text: string, options?: FromCDNSeqOptions): Generator<CborItem> {\n for (const item of CBOR.fromCDNSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n for (const item of CBOR.fromHexDumpSeq(text, this.#merge(options))) {\n item._defaults = this.#defaults;\n yield item;\n }\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.decodeSeq(input, this.#merge(options));\n }\n\n *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n yield* CBOR.parseSeq(text, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.compile(text, this.#merge(options));\n }\n\n decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return CBOR.decompile(input, this.#merge(options));\n }\n\n toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return CBOR.toHex(input, this.#merge(options));\n }\n\n fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromHex(text, this.#merge(options));\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n /** @deprecated Use `decompile()` instead. */\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n const merged = this.#merge(options);\n const node = CBOR.fromCBOR(input, merged);\n node._defaults = this.#defaults;\n return node.toCDN(merged);\n }\n\n /** @deprecated Use `compile()` instead. */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n /** @deprecated Use `compile()` instead. */\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n const merged = this.#merge(options);\n return CBOR.fromCDN(text, merged).toCBOR(merged);\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** アノテーション付き hex dump テキストから CBOR Sequence を item ごとにデコードするジェネレータ。 */\n static *fromHexDumpSeq(\n text: string,\n options?: FromHexDumpOptions\n ): Generator<CborItem> {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n yield* CBOR.fromCBORSeq(new Uint8Array(bytes), options);\n }\n\n /** CBOR Sequence (RFC 8742) を item ごとにデコードするジェネレータ。 */\n static *fromCBORSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions\n ): Generator<CborItem> {\n const bytes =\n input instanceof ArrayBuffer ||\n (typeof SharedArrayBuffer !== 'undefined' &&\n input instanceof SharedArrayBuffer)\n ? new Uint8Array(input)\n : new Uint8Array(\n (input as ArrayBufferView).buffer,\n (input as ArrayBufferView).byteOffset,\n (input as ArrayBufferView).byteLength\n );\n let offset = 0;\n while (offset < bytes.byteLength) {\n const item = decodeCBOR(bytes, {\n ...options,\n offset,\n allowTrailing: true,\n });\n yield item;\n offset = item.end!;\n }\n }\n\n /**\n * CDN テキストの複数 item を 1 つずつパースするジェネレータ。\n *\n * `preserveComments` が有効な場合、item 間のコメントは次の item の\n * leading コメントとして、item と同じ行にあるコメントはその item の\n * trailing コメントとして付与される。最後の item の後の行にだけ\n * コメントが残る場合、そのコメントはどの item にも属さず破棄される。\n */\n static *fromCDNSeq(\n text: string,\n options?: FromCDNSeqOptions\n ): Generator<CborItem> {\n const preserve = !!options?.preserveComments;\n let offset = 0;\n let isFirst = true;\n while (true) {\n const {\n offset: next,\n hadSeparator,\n commaOffset,\n } = skipCDNSeparator(\n text,\n offset,\n options,\n preserve ? (isFirst ? 'all' : 'after-newline') : 'none'\n );\n // Leading comma: comma before the first item (including comma-only input).\n // Checked before the EOF break so that \",\" alone is also caught.\n // Trailing comma is valid per ABNF SOC = S [\",\" S] and is silently accepted.\n if (isFirst && commaOffset >= 0) {\n const msg = 'leading comma in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, commaOffset, options);\n }\n if (next >= text.length) break;\n // Stopped at a comment that should lead the next item: make sure an\n // item actually follows. If only comments remain, we are done (the\n // remaining comments belong to no item and are dropped, matching the\n // behaviour of `preserveComments: false`).\n if (preserve && isCDNCommentStart(text, next)) {\n const lookahead = skipCDNSeparator(text, next, options);\n if (lookahead.offset >= text.length) break;\n }\n if (!isFirst && !hadSeparator) {\n const msg =\n 'CDN sequence items must be separated by whitespace, comma, or comment';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, next, options);\n }\n offset = next;\n let item: CborItem;\n try {\n // _skipRS: true causes the tokenizer to treat RS (U+001E, RFC 7464) as\n // whitespace, preventing it from corrupting string-literal contents via\n // a global text replacement.\n item = parseCDN(text, {\n ...options,\n offset,\n allowTrailing: true,\n _skipRS: true,\n } as FromCDNOptions);\n } catch (e) {\n if (options?.strict !== false) throw e;\n emitCDNSeqWarning(\n e instanceof Error ? e.message : String(e),\n offset,\n options,\n true,\n e instanceof CdnSyntaxError ? e : undefined\n );\n break;\n }\n yield item;\n offset = item.end!;\n isFirst = false;\n }\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (/^[0-9A-Fa-f]{2}$/.test(token)) {\n bytes.push(parseInt(token, 16));\n } else if (/^[0-9A-Fa-f]+$/.test(token) && token.length % 2 === 0) {\n for (let i = 0; i < token.length; i += 2)\n bytes.push(parseInt(token.slice(i, i + 2), 16));\n } else {\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n }\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Decode a CBOR Sequence (RFC 8742), yielding each item as a JavaScript value. */\n static *decodeSeq(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCBORSeq(input, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Parse a CDN Sequence text string, yielding each item as a JavaScript value. */\n static *parseSeq(\n text: string,\n options?: FromCDNSeqOptions & ToJSOptions\n ): Generator<unknown> {\n for (const item of CBOR.fromCDNSeq(text, options)) {\n yield item.toJS(options);\n }\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Compile a CDN text string to CBOR binary data.\n * Multi-item CDN Sequences produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static compile(\n text: string,\n options?: FromCDNSeqOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromCDNSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Decompile CBOR binary data to a CDN text string.\n * CBOR Sequences (RFC 8742) produce multi-item CDN output, with items separated by newlines.\n */\n static decompile(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToCDNOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toCDN(options))\n .join('\\n');\n }\n\n /**\n * Convert CBOR binary data to an annotated hex dump string.\n * CBOR Sequences (RFC 8742) produce one dump per item, separated by newlines.\n */\n static toHex(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBORSeqOptions & ToHexDumpOptions\n ): string {\n return [...CBOR.fromCBORSeq(input, options)]\n .map((item) => item.toHexDump(options))\n .join('\\n');\n }\n\n /**\n * Parse an annotated hex dump string to CBOR binary data.\n * Multi-item dumps produce a CBOR Sequence (RFC 8742): concatenated items.\n */\n static fromHex(\n text: string,\n options?: FromHexDumpOptions & ToCBOROptions\n ): Uint8Array {\n const byteArrays = [...CBOR.fromHexDumpSeq(text, options)].map((item) =>\n item.toCBOR(options)\n );\n const total = byteArrays.reduce((s, b) => s + b.length, 0);\n const result = new Uint8Array(total);\n let off = 0;\n for (const b of byteArrays) {\n result.set(b, off);\n off += b.length;\n }\n return result;\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.decompile()` instead.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /** @deprecated Use `CBOR.decompile()` instead. */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.compile()` instead.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /** @deprecated Use `CBOR.compile()` instead. */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '—') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\nfunction emitCDNSeqWarning(\n msg: string,\n fallbackOffset: number,\n options: FromCDNSeqOptions | undefined,\n fatal?: boolean,\n cause?: CdnSyntaxError\n): void {\n const offset = cause?.offset ?? fallbackOffset;\n const w: ParseWarning = { message: msg, offset };\n if (fatal) w.fatal = true;\n if (cause?.offset !== undefined) {\n w.line = cause.line;\n w.column = cause.column;\n w.endOffset = cause.endOffset;\n }\n if (options?.onWarning) options.onWarning(w);\n else if (!options?.silent)\n console.warn(`CDN sequence warning at offset ${offset}: ${msg}`);\n}\n\n/** Whether `text[i]` starts a CDN comment (`#`, `//`, `/* … *\\/`, or `/ … /`). */\nfunction isCDNCommentStart(text: string, i: number): boolean {\n const ch = text[i];\n return ch === '#' || ch === '/';\n}\n\n/**\n * CDN sequence の item 間にある空白・コメント・省略可能なカンマを読み飛ばし、\n * 次の item が始まる文字位置と、何らかの separator が存在したかどうかを返す。\n * 未終端のブロックコメントは strict モードでは throw し、\n * strict: false の場合は警告を emit して末尾まで読み飛ばす。\n *\n * `stopAtComments` は `preserveComments` 有効時にコメントを次の item の\n * leading コメントとして残すためのモード:\n * - `'none'`: コメントも読み飛ばす(従来動作)\n * - `'all'`: 最初のコメントで停止する(先頭 item 用)\n * - `'after-newline'`: 改行より後のコメントで停止する。直前 item と同じ行の\n * コメントはその item の trailing コメントとして既に付与されているため読み飛ばす。\n */\nfunction skipCDNSeparator(\n text: string,\n from: number,\n options: FromCDNSeqOptions | undefined,\n stopAtComments: 'none' | 'after-newline' | 'all' = 'none'\n): { offset: number; hadSeparator: boolean; commaOffset: number } {\n let i = from;\n let hadSeparator = false;\n let seenComma = false;\n let seenNewline = false;\n let commaOffset = -1;\n const stopHere = (): boolean =>\n stopAtComments === 'all' ||\n (stopAtComments === 'after-newline' && seenNewline);\n while (i < text.length) {\n const ch = text[i];\n if (ch === ' ' || ch === '\\t' || ch === '\\r' || ch === '\\x1e') {\n hadSeparator = true;\n i++;\n continue;\n }\n if (ch === '\\n') {\n hadSeparator = true;\n seenNewline = true;\n i++;\n continue;\n }\n if (ch === '#') {\n hadSeparator = true;\n if (stopHere()) break;\n const nl = text.indexOf('\\n', i + 1);\n i = nl < 0 ? text.length : nl + 1;\n seenNewline = true;\n continue;\n }\n if (ch === '/' && text[i + 1] === '/') {\n hadSeparator = true;\n if (stopHere()) break;\n const nl = text.indexOf('\\n', i + 2);\n i = nl < 0 ? text.length : nl + 1;\n seenNewline = true;\n continue;\n }\n if (ch === '/' && text[i + 1] === '*') {\n hadSeparator = true;\n if (stopHere()) break;\n const end = text.indexOf('*/', i + 2);\n if (end < 0) {\n const msg = 'unterminated /* comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options, true);\n i = text.length;\n } else {\n if (text.slice(i, end).includes('\\n')) seenNewline = true;\n i = end + 2;\n }\n continue;\n }\n if (ch === '/' && text[i + 1] !== '/') {\n hadSeparator = true;\n if (stopHere()) break;\n const end = text.indexOf('/', i + 1);\n if (end < 0) {\n const msg = 'unterminated / comment in CDN sequence';\n if (options?.strict !== false) throw new SyntaxError(msg);\n emitCDNSeqWarning(msg, i, options, true);\n i = text.length;\n } else {\n if (text.slice(i, end).includes('\\n')) seenNewline = true;\n i = end + 1;\n }\n continue;\n }\n if (ch === ',' && !seenComma) {\n hadSeparator = true;\n seenComma = true;\n commaOffset = i;\n i++;\n continue;\n }\n break;\n }\n return { offset: i, hadSeparator, commaOffset };\n}\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":"kLAWA,SAAgB,EAAc,EAAqB,CACjD,IAAI,EAAM,GACN,EAAI,EACR,KAAO,EAAI,EAAI,QAAQ,CACrB,IAAM,EAAK,EAAI,GACf,GAAI,IAAO,KAAO,IAAO;GAAQ,IAAO,KAAM,CAC5C,IACA,QACF,CACA,GAAI,IAAO,IAAK,CACd,KAAO,EAAI,EAAI,QAAU,EAAI,KAAO;GAAM,IAC1C,QACF,CACA,GAAI,IAAO,IAAK,CACd,IAAM,EAAO,EAAI,EAAI,IAAM,GAC3B,GAAI,IAAS,IAAK,CAChB,KAAO,EAAI,EAAI,QAAU,EAAI,KAAO;GAAM,IAC1C,QACF,CACA,GAAI,IAAS,IAAK,CAEhB,IADA,GAAK,EAEH,EAAI,EAAI,QACR,EAAE,EAAI,KAAO,MAAQ,EAAI,E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AO,GAAU,SAAU,CAC7B,IAAM,EAAI,KAAK,MAAM,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,CAAK,CAAC,CAAC,EACrD,OAAO,IAAM,EAAI,IAAA,GAAY,CAC/B,CACA,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,EAClB,GAAK,IAAA,EAGhB"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as e, o as t } from "./tokenizer-DkLlZ1gc.js";
|
|
2
|
+
import { C as n, D as r, E as i, O as a, S as o, T as s, a as c, g as l, i as u, k as d, n as f, r as p, s as m, t as h, v as g, w as _ } from "./mapEntries-CYvdsAfP.js";
|
|
3
3
|
//#region src/utils/strip-comments.ts
|
|
4
4
|
function v(e) {
|
|
5
5
|
let t = "", n = 0;
|
|
@@ -171,18 +171,18 @@ function M(e, t, r) {
|
|
|
171
171
|
}
|
|
172
172
|
var N = {
|
|
173
173
|
appStringPrefixes: ["float"],
|
|
174
|
-
parseAppString(
|
|
175
|
-
let
|
|
176
|
-
if (!/^[0-9a-fA-F]*$/.test(
|
|
177
|
-
if (
|
|
178
|
-
let
|
|
179
|
-
if (
|
|
180
|
-
if (
|
|
181
|
-
let e = `float'...' encoding indicator _${
|
|
182
|
-
if (
|
|
174
|
+
parseAppString(t, n, r, i) {
|
|
175
|
+
let a = v(n);
|
|
176
|
+
if (!/^[0-9a-fA-F]*$/.test(a)) throw SyntaxError("float'...' contains non-hex characters");
|
|
177
|
+
if (a.length % 2 != 0) throw SyntaxError(`float'...' hex content has odd length (${a.length} digits)`);
|
|
178
|
+
let o = e(a), s = i?.encodingWidth;
|
|
179
|
+
if (s === void 0) return O(o);
|
|
180
|
+
if (s !== 1 && s !== 2 && s !== 3) {
|
|
181
|
+
let e = `float'...' encoding indicator _${s} is not valid; use _1, _2, or _3`;
|
|
182
|
+
if (r) return r(e), O(o);
|
|
183
183
|
throw SyntaxError(e);
|
|
184
184
|
}
|
|
185
|
-
return
|
|
185
|
+
return s === (o.length === 2 ? 1 : o.length === 4 ? 2 : 3) ? O(o) : M(o, s, r ?? ((e) => {
|
|
186
186
|
throw SyntaxError(e);
|
|
187
187
|
}));
|
|
188
188
|
},
|
|
@@ -218,10 +218,10 @@ var F = {
|
|
|
218
218
|
return r;
|
|
219
219
|
}
|
|
220
220
|
}, I = class e {
|
|
221
|
-
static OMIT =
|
|
222
|
-
static TAG =
|
|
223
|
-
static Tag =
|
|
224
|
-
static Simple =
|
|
221
|
+
static OMIT = s;
|
|
222
|
+
static TAG = i;
|
|
223
|
+
static Tag = a;
|
|
224
|
+
static Simple = _;
|
|
225
225
|
static MapEntries = h;
|
|
226
226
|
static dt_as_Date = c;
|
|
227
227
|
#e;
|
|
@@ -311,7 +311,7 @@ var F = {
|
|
|
311
311
|
stringify(t, n, r) {
|
|
312
312
|
if (typeof n == "function" || Array.isArray(n) || n === null || n === void 0 && r !== void 0) {
|
|
313
313
|
let i = { ...this.#e };
|
|
314
|
-
return n === null ? i.replacer = void 0 : (typeof n == "function" || Array.isArray(n)) && (i.replacer = n), r !== void 0 && (i.indent =
|
|
314
|
+
return n === null ? i.replacer = void 0 : (typeof n == "function" || Array.isArray(n)) && (i.replacer = n), r !== void 0 && (i.indent = U(r)), e.stringify(t, i);
|
|
315
315
|
}
|
|
316
316
|
return e.stringify(t, this.#t(n ?? void 0));
|
|
317
317
|
}
|
|
@@ -345,36 +345,36 @@ var F = {
|
|
|
345
345
|
yield e, r = e.end;
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
|
-
static *fromCDNSeq(e,
|
|
349
|
-
let n = 0,
|
|
348
|
+
static *fromCDNSeq(e, n) {
|
|
349
|
+
let r = !!n?.preserveComments, i = 0, a = !0;
|
|
350
350
|
for (;;) {
|
|
351
|
-
let { offset:
|
|
352
|
-
if (
|
|
351
|
+
let { offset: o, hadSeparator: s, commaOffset: c } = H(e, i, n, r ? a ? "all" : "after-newline" : "none");
|
|
352
|
+
if (a && c >= 0) {
|
|
353
353
|
let e = "leading comma in CDN sequence";
|
|
354
|
-
if (
|
|
355
|
-
B(e,
|
|
354
|
+
if (n?.strict !== !1) throw SyntaxError(e);
|
|
355
|
+
B(e, c, n);
|
|
356
356
|
}
|
|
357
|
-
if (
|
|
358
|
-
if (!
|
|
357
|
+
if (o >= e.length || r && V(e, o) && H(e, o, n).offset >= e.length) break;
|
|
358
|
+
if (!a && !s) {
|
|
359
359
|
let e = "CDN sequence items must be separated by whitespace, comma, or comment";
|
|
360
|
-
if (
|
|
361
|
-
B(e,
|
|
360
|
+
if (n?.strict !== !1) throw SyntaxError(e);
|
|
361
|
+
B(e, o, n);
|
|
362
362
|
}
|
|
363
|
-
|
|
364
|
-
let
|
|
363
|
+
i = o;
|
|
364
|
+
let l;
|
|
365
365
|
try {
|
|
366
|
-
|
|
367
|
-
...
|
|
368
|
-
offset:
|
|
366
|
+
l = m(e, {
|
|
367
|
+
...n,
|
|
368
|
+
offset: i,
|
|
369
369
|
allowTrailing: !0,
|
|
370
370
|
_skipRS: !0
|
|
371
371
|
});
|
|
372
372
|
} catch (e) {
|
|
373
|
-
if (
|
|
374
|
-
B(e instanceof Error ? e.message : String(e), n, t);
|
|
373
|
+
if (n?.strict !== !1) throw e;
|
|
374
|
+
B(e instanceof Error ? e.message : String(e), i, n, !0, e instanceof t ? e : void 0);
|
|
375
375
|
break;
|
|
376
376
|
}
|
|
377
|
-
yield
|
|
377
|
+
yield l, i = l.end, a = !1;
|
|
378
378
|
}
|
|
379
379
|
}
|
|
380
380
|
static fromJS(e, t) {
|
|
@@ -432,19 +432,19 @@ var F = {
|
|
|
432
432
|
}
|
|
433
433
|
static stringify(e, t, n) {
|
|
434
434
|
if (typeof t == "function" || Array.isArray(t) || t === null || t === void 0 && n !== void 0) {
|
|
435
|
-
let r = typeof t == "function" || Array.isArray(t) ? t : void 0,
|
|
435
|
+
let r = typeof t == "function" || Array.isArray(t) ? t : void 0, i = U(n);
|
|
436
436
|
if (r) {
|
|
437
437
|
let t = f(e, r);
|
|
438
|
-
return t === void 0 || t ===
|
|
438
|
+
return t === void 0 || t === s ? void 0 : p(t).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
439
439
|
}
|
|
440
|
-
return p(e).toCDN(
|
|
440
|
+
return p(e).toCDN(i === void 0 ? void 0 : { indent: i });
|
|
441
441
|
}
|
|
442
442
|
let r = t;
|
|
443
443
|
if (r?.replacer) {
|
|
444
444
|
let t = f(e, r.replacer, r.extensions, r.undefinedOmits);
|
|
445
|
-
if (t === void 0 || t ===
|
|
446
|
-
let { replacer: n, ...
|
|
447
|
-
return p(t, Object.keys(
|
|
445
|
+
if (t === void 0 || t === s) return;
|
|
446
|
+
let { replacer: n, ...i } = r;
|
|
447
|
+
return p(t, Object.keys(i).length > 0 ? i : void 0).toCDN(r);
|
|
448
448
|
}
|
|
449
449
|
return p(e, r).toCDN(r);
|
|
450
450
|
}
|
|
@@ -495,66 +495,74 @@ function R(e, t) {
|
|
|
495
495
|
function z(e) {
|
|
496
496
|
return e.replace(/[^\r\n]/g, " ");
|
|
497
497
|
}
|
|
498
|
-
function B(e, t, n) {
|
|
499
|
-
let
|
|
498
|
+
function B(e, t, n, r, i) {
|
|
499
|
+
let a = i?.offset ?? t, o = {
|
|
500
500
|
message: e,
|
|
501
|
-
offset:
|
|
501
|
+
offset: a
|
|
502
502
|
};
|
|
503
|
-
n?.onWarning ? n.onWarning(
|
|
503
|
+
r && (o.fatal = !0), i?.offset !== void 0 && (o.line = i.line, o.column = i.column, o.endOffset = i.endOffset), n?.onWarning ? n.onWarning(o) : n?.silent || console.warn(`CDN sequence warning at offset ${a}: ${e}`);
|
|
504
504
|
}
|
|
505
|
-
function V(e, t
|
|
506
|
-
let
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
505
|
+
function V(e, t) {
|
|
506
|
+
let n = e[t];
|
|
507
|
+
return n === "#" || n === "/";
|
|
508
|
+
}
|
|
509
|
+
function H(e, t, n, r = "none") {
|
|
510
|
+
let i = t, a = !1, o = !1, s = !1, c = -1, l = () => r === "all" || r === "after-newline" && s;
|
|
511
|
+
for (; i < e.length;) {
|
|
512
|
+
let t = e[i];
|
|
513
|
+
if (t === " " || t === " " || t === "\r" || t === "") {
|
|
514
|
+
a = !0, i++;
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (t === "\n") {
|
|
518
|
+
a = !0, s = !0, i++;
|
|
511
519
|
continue;
|
|
512
520
|
}
|
|
513
521
|
if (t === "#") {
|
|
514
|
-
|
|
515
|
-
let t = e.indexOf("\n",
|
|
516
|
-
|
|
522
|
+
if (a = !0, l()) break;
|
|
523
|
+
let t = e.indexOf("\n", i + 1);
|
|
524
|
+
i = t < 0 ? e.length : t + 1, s = !0;
|
|
517
525
|
continue;
|
|
518
526
|
}
|
|
519
|
-
if (t === "/" && e[
|
|
520
|
-
|
|
521
|
-
let t = e.indexOf("\n",
|
|
522
|
-
|
|
527
|
+
if (t === "/" && e[i + 1] === "/") {
|
|
528
|
+
if (a = !0, l()) break;
|
|
529
|
+
let t = e.indexOf("\n", i + 2);
|
|
530
|
+
i = t < 0 ? e.length : t + 1, s = !0;
|
|
523
531
|
continue;
|
|
524
532
|
}
|
|
525
|
-
if (t === "/" && e[
|
|
526
|
-
|
|
527
|
-
let t = e.indexOf("*/",
|
|
533
|
+
if (t === "/" && e[i + 1] === "*") {
|
|
534
|
+
if (a = !0, l()) break;
|
|
535
|
+
let t = e.indexOf("*/", i + 2);
|
|
528
536
|
if (t < 0) {
|
|
529
537
|
let t = "unterminated /* comment in CDN sequence";
|
|
530
538
|
if (n?.strict !== !1) throw SyntaxError(t);
|
|
531
|
-
B(t,
|
|
532
|
-
} else
|
|
539
|
+
B(t, i, n, !0), i = e.length;
|
|
540
|
+
} else e.slice(i, t).includes("\n") && (s = !0), i = t + 2;
|
|
533
541
|
continue;
|
|
534
542
|
}
|
|
535
|
-
if (t === "/" && e[
|
|
536
|
-
|
|
537
|
-
let t = e.indexOf("/",
|
|
543
|
+
if (t === "/" && e[i + 1] !== "/") {
|
|
544
|
+
if (a = !0, l()) break;
|
|
545
|
+
let t = e.indexOf("/", i + 1);
|
|
538
546
|
if (t < 0) {
|
|
539
547
|
let t = "unterminated / comment in CDN sequence";
|
|
540
548
|
if (n?.strict !== !1) throw SyntaxError(t);
|
|
541
|
-
B(t,
|
|
542
|
-
} else
|
|
549
|
+
B(t, i, n, !0), i = e.length;
|
|
550
|
+
} else e.slice(i, t).includes("\n") && (s = !0), i = t + 1;
|
|
543
551
|
continue;
|
|
544
552
|
}
|
|
545
|
-
if (t === "," && !
|
|
546
|
-
|
|
553
|
+
if (t === "," && !o) {
|
|
554
|
+
a = !0, o = !0, c = i, i++;
|
|
547
555
|
continue;
|
|
548
556
|
}
|
|
549
557
|
break;
|
|
550
558
|
}
|
|
551
559
|
return {
|
|
552
|
-
offset:
|
|
553
|
-
hadSeparator:
|
|
554
|
-
commaOffset:
|
|
560
|
+
offset: i,
|
|
561
|
+
hadSeparator: a,
|
|
562
|
+
commaOffset: c
|
|
555
563
|
};
|
|
556
564
|
}
|
|
557
|
-
function
|
|
565
|
+
function U(e) {
|
|
558
566
|
if (typeof e == "number") {
|
|
559
567
|
let t = Math.floor(Math.min(10, Math.max(0, e)));
|
|
560
568
|
return t === 0 ? void 0 : t;
|
|
@@ -562,6 +570,6 @@ function H(e) {
|
|
|
562
570
|
if (typeof e == "string") return e.slice(0, 10) || void 0;
|
|
563
571
|
}
|
|
564
572
|
//#endregion
|
|
565
|
-
export { I as CBOR, I as default,
|
|
573
|
+
export { I as CBOR, I as default, s as CBOR_OMIT, i as CBOR_TAG, t as CdnSyntaxError, h as MapEntries, r as Null, _ as Simple, a as Tag, d as Undefined, C as b32, c as dt_as_Date, N as float, w as h32, F as same };
|
|
566
574
|
|
|
567
575
|
//# sourceMappingURL=index.js.map
|