@cbortech/cbor 0.23.1 → 0.24.0
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 +52 -3
- package/README.md +52 -3
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor.d.ts +16 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{mapEntries-CSjvgq1X.js → mapEntries-D5MWtXqq.js} +512 -1154
- package/dist/mapEntries-D5MWtXqq.js.map +1 -0
- package/dist/mapEntries-bihZ3yks.cjs +31 -0
- package/dist/mapEntries-bihZ3yks.cjs.map +1 -0
- package/dist/types.d.ts +12 -2
- package/package.json +18 -17
- package/dist/extensions/hash.d.ts +0 -17
- package/dist/mapEntries-C73nWM8o.cjs +0 -31
- package/dist/mapEntries-C73nWM8o.cjs.map +0 -1
- package/dist/mapEntries-CSjvgq1X.js.map +0 -1
package/README.ja.md
CHANGED
|
@@ -57,7 +57,9 @@ console.log(value);
|
|
|
57
57
|
```ts
|
|
58
58
|
import { CBOR } from '@cbortech/cbor';
|
|
59
59
|
|
|
60
|
-
const text = CBOR.
|
|
60
|
+
const text = CBOR.fromCBOR(
|
|
61
|
+
new Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
62
|
+
).toEDN();
|
|
61
63
|
|
|
62
64
|
console.log(text);
|
|
63
65
|
// [1,2,3]
|
|
@@ -68,7 +70,7 @@ console.log(text);
|
|
|
68
70
|
```ts
|
|
69
71
|
import { CBOR } from '@cbortech/cbor';
|
|
70
72
|
|
|
71
|
-
const bytes = CBOR.
|
|
73
|
+
const bytes = CBOR.fromEDN('[1, 2, 3]').toCBOR();
|
|
72
74
|
|
|
73
75
|
console.log(bytes);
|
|
74
76
|
// Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
@@ -324,6 +326,41 @@ console.log(text);
|
|
|
324
326
|
// DT'2026-05-06T00:00:00Z'
|
|
325
327
|
```
|
|
326
328
|
|
|
329
|
+
## オプション extension
|
|
330
|
+
|
|
331
|
+
追加の application extension は別パッケージとして公開されています。必要なものを
|
|
332
|
+
インストールし、`extensions` オプションに渡して使います。
|
|
333
|
+
|
|
334
|
+
`hash` は CBOR-EDN の仕様に含まれる application extension ですが、利用には
|
|
335
|
+
外部パッケージが必要です。そのため、このパッケージ本体には含めず、
|
|
336
|
+
`@cbortech/hash-extension` として提供しています。
|
|
337
|
+
|
|
338
|
+
`uuid` は CBOR-EDN の仕様には定められていない、このライブラリ独自の
|
|
339
|
+
application extension です。仕様上の標準機能と区別するため、
|
|
340
|
+
`@cbortech/uuid-extension` として別パッケージで提供しています。
|
|
341
|
+
|
|
342
|
+
```bash
|
|
343
|
+
npm install @cbortech/hash-extension @cbortech/uuid-extension
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
import { CBOR } from '@cbortech/cbor';
|
|
348
|
+
import hashExtension from '@cbortech/hash-extension';
|
|
349
|
+
import uuidExtension from '@cbortech/uuid-extension';
|
|
350
|
+
|
|
351
|
+
const cbor = new CBOR({
|
|
352
|
+
extensions: [hashExtension, uuidExtension],
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
const digest = cbor.fromEDN("hash'foo'");
|
|
356
|
+
console.log(digest.toEDN());
|
|
357
|
+
// hash'foo'
|
|
358
|
+
|
|
359
|
+
const id = cbor.fromEDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
|
|
360
|
+
console.log(id.toEDN());
|
|
361
|
+
// uuid'550e8400-e29b-41d4-a716-446655440000'
|
|
362
|
+
```
|
|
363
|
+
|
|
327
364
|
## タグ
|
|
328
365
|
|
|
329
366
|
JavaScript 上で CBOR のタグ付き値を扱うには `CBOR.Tag` を使います。
|
|
@@ -350,6 +387,18 @@ console.log(CBOR.Tag.getValue(value));
|
|
|
350
387
|
// "hello"
|
|
351
388
|
```
|
|
352
389
|
|
|
390
|
+
タグ情報が不要で、中身だけを通常の JavaScript 値として扱いたい場合は
|
|
391
|
+
`stripTags: true` を指定できます。
|
|
392
|
+
|
|
393
|
+
```ts
|
|
394
|
+
import { CBOR } from '@cbortech/cbor';
|
|
395
|
+
|
|
396
|
+
const value = CBOR.parse('42("hello")', { stripTags: true });
|
|
397
|
+
|
|
398
|
+
console.log(value);
|
|
399
|
+
// "hello"
|
|
400
|
+
```
|
|
401
|
+
|
|
353
402
|
## Simple 値
|
|
354
403
|
|
|
355
404
|
`false`、`true`、`null`、`undefined` 以外の CBOR simple value には `CBOR.Simple` を使います。
|
|
@@ -463,7 +512,7 @@ console.log(item.toEDN());
|
|
|
463
512
|
このライブラリは次の仕様を対象にしています。
|
|
464
513
|
|
|
465
514
|
- [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
|
|
466
|
-
- [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-
|
|
515
|
+
- [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-24](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/24/)
|
|
467
516
|
|
|
468
517
|
CBOR-EDN は、CBOR データを人間が読み書きしやすいテキストとして表現するための記法です。
|
|
469
518
|
サンプル、テストベクター、デバッグ、fixture、設定ファイルに近い用途など、CBOR のバイト列をそのまま扱うと読みにくい場面で役立ちます。
|
package/README.md
CHANGED
|
@@ -59,7 +59,9 @@ console.log(value);
|
|
|
59
59
|
```ts
|
|
60
60
|
import { CBOR } from '@cbortech/cbor';
|
|
61
61
|
|
|
62
|
-
const text = CBOR.
|
|
62
|
+
const text = CBOR.fromCBOR(
|
|
63
|
+
new Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
64
|
+
).toEDN();
|
|
63
65
|
|
|
64
66
|
console.log(text);
|
|
65
67
|
// [1,2,3]
|
|
@@ -70,7 +72,7 @@ console.log(text);
|
|
|
70
72
|
```ts
|
|
71
73
|
import { CBOR } from '@cbortech/cbor';
|
|
72
74
|
|
|
73
|
-
const bytes = CBOR.
|
|
75
|
+
const bytes = CBOR.fromEDN('[1, 2, 3]').toCBOR();
|
|
74
76
|
|
|
75
77
|
console.log(bytes);
|
|
76
78
|
// Uint8Array([0x83, 0x01, 0x02, 0x03])
|
|
@@ -328,6 +330,41 @@ console.log(text);
|
|
|
328
330
|
// DT'2026-05-06T00:00:00Z'
|
|
329
331
|
```
|
|
330
332
|
|
|
333
|
+
## Optional Extensions
|
|
334
|
+
|
|
335
|
+
Additional application extensions are published as separate packages. Install
|
|
336
|
+
the ones you need and pass them through the `extensions` option.
|
|
337
|
+
|
|
338
|
+
`hash` is an application extension defined by the CBOR-EDN specification, but
|
|
339
|
+
it requires an external package. For that reason, it is not bundled with this
|
|
340
|
+
package and is provided separately as `@cbortech/hash-extension`.
|
|
341
|
+
|
|
342
|
+
`uuid` is a library-specific application extension that is not defined by the
|
|
343
|
+
CBOR-EDN specification. To keep it distinct from standard CBOR-EDN features, it
|
|
344
|
+
is provided separately as `@cbortech/uuid-extension`.
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
npm install @cbortech/hash-extension @cbortech/uuid-extension
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
import { CBOR } from '@cbortech/cbor';
|
|
352
|
+
import hashExtension from '@cbortech/hash-extension';
|
|
353
|
+
import uuidExtension from '@cbortech/uuid-extension';
|
|
354
|
+
|
|
355
|
+
const cbor = new CBOR({
|
|
356
|
+
extensions: [hashExtension, uuidExtension],
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const digest = cbor.fromEDN("hash'foo'");
|
|
360
|
+
console.log(digest.toEDN());
|
|
361
|
+
// hash'foo'
|
|
362
|
+
|
|
363
|
+
const id = cbor.fromEDN("uuid'550e8400-e29b-41d4-a716-446655440000'");
|
|
364
|
+
console.log(id.toEDN());
|
|
365
|
+
// uuid'550e8400-e29b-41d4-a716-446655440000'
|
|
366
|
+
```
|
|
367
|
+
|
|
331
368
|
## Tags
|
|
332
369
|
|
|
333
370
|
Use `CBOR.Tag` for CBOR tagged values in JavaScript.
|
|
@@ -354,6 +391,18 @@ console.log(CBOR.Tag.getValue(value));
|
|
|
354
391
|
// "hello"
|
|
355
392
|
```
|
|
356
393
|
|
|
394
|
+
Use `stripTags: true` when you only need the tagged content as a plain
|
|
395
|
+
JavaScript value.
|
|
396
|
+
|
|
397
|
+
```ts
|
|
398
|
+
import { CBOR } from '@cbortech/cbor';
|
|
399
|
+
|
|
400
|
+
const value = CBOR.parse('42("hello")', { stripTags: true });
|
|
401
|
+
|
|
402
|
+
console.log(value);
|
|
403
|
+
// "hello"
|
|
404
|
+
```
|
|
405
|
+
|
|
357
406
|
## Simple Values
|
|
358
407
|
|
|
359
408
|
Use `CBOR.Simple` for CBOR simple values other than `false`, `true`, `null`, and
|
|
@@ -469,7 +518,7 @@ The `CBOR` facade also exposes:
|
|
|
469
518
|
This library targets:
|
|
470
519
|
|
|
471
520
|
- [CBOR, RFC 8949](https://www.rfc-editor.org/rfc/rfc8949)
|
|
472
|
-
- [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-
|
|
521
|
+
- [CBOR Extended Diagnostic Notation (CBOR-EDN), draft-ietf-cbor-edn-literals-24](https://datatracker.ietf.org/doc/draft-ietf-cbor-edn-literals/24/)
|
|
473
522
|
|
|
474
523
|
CBOR-EDN is a human-readable text notation for CBOR data. It is useful for
|
|
475
524
|
examples, test vectors, debugging, fixtures, and configuration-like files where
|
package/dist/ast/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../mapEntries-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../mapEntries-bihZ3yks.cjs`);exports.CborArray=e.p,exports.CborBigNint=e.c,exports.CborBigUint=e.l,exports.CborByteString=e.g,exports.CborEmbeddedCBOR=e.u,exports.CborFloat=e.v,exports.CborIndefiniteByteString=e.h,exports.CborIndefiniteTextString=e.m,exports.CborItem=e.x,exports.CborMap=e.f,exports.CborNint=e.y,exports.CborSimple=e.d,exports.CborTag=e._,exports.CborTextString=e.o,exports.CborUint=e.b;
|
package/dist/ast/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { _ as e, b as t, c as n, d as r, f as i, g as a, h as o, l as s, m as c, o as l, p as u, u as d, v as f, x as p, y as m } from "../mapEntries-
|
|
1
|
+
import { _ as e, b as t, c as n, d as r, f as i, g as a, h as o, l as s, m as c, o as l, p as u, u as d, v as f, x as p, y as m } from "../mapEntries-D5MWtXqq.js";
|
|
2
2
|
export { u as CborArray, n as CborBigNint, s as CborBigUint, a as CborByteString, d as CborEmbeddedCBOR, f as CborFloat, o as CborIndefiniteByteString, c as CborIndefiniteTextString, p as CborItem, i as CborMap, m as CborNint, r as CborSimple, e as CborTag, l as CborTextString, t as CborUint };
|
package/dist/cbor.d.ts
CHANGED
|
@@ -58,7 +58,13 @@ export declare class CBOR {
|
|
|
58
58
|
fromHexDump(text: string, options?: FromHexDumpOptions): CborItem;
|
|
59
59
|
decode(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToJSOptions): unknown;
|
|
60
60
|
encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Use `fromCBOR(input, options).toEDN(options)` instead.
|
|
63
|
+
*/
|
|
61
64
|
cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToEDNOptions): string;
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use `fromEDN(text, options).toCBOR(options)` instead.
|
|
67
|
+
*/
|
|
62
68
|
cborEdnToCbor(text: string, options?: FromEDNOptions & ToCBOROptions): Uint8Array;
|
|
63
69
|
parse(text: string): unknown;
|
|
64
70
|
parse(text: string, reviver: (this: unknown, key: unknown, value: unknown) => unknown): unknown;
|
|
@@ -89,9 +95,17 @@ export declare class CBOR {
|
|
|
89
95
|
static decode(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToJSOptions): unknown;
|
|
90
96
|
/** Encode a JavaScript value directly to CBOR binary data. */
|
|
91
97
|
static encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array;
|
|
92
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Convert CBOR binary data directly to a CBOR-EDN text string.
|
|
100
|
+
*
|
|
101
|
+
* @deprecated Use `CBOR.fromCBOR(input, options).toEDN(options)` instead.
|
|
102
|
+
*/
|
|
93
103
|
static cborToCborEdn(input: ArrayBufferView | ArrayBufferLike, options?: FromCBOROptions & ToEDNOptions): string;
|
|
94
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Convert a CBOR-EDN text string directly to CBOR binary data.
|
|
106
|
+
*
|
|
107
|
+
* @deprecated Use `CBOR.fromEDN(text, options).toCBOR(options)` instead.
|
|
108
|
+
*/
|
|
95
109
|
static cborEdnToCbor(text: string, options?: FromEDNOptions & ToCBOROptions): Uint8Array;
|
|
96
110
|
/**
|
|
97
111
|
* Parse a CBOR-EDN text string directly to a JavaScript value.
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./mapEntries-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./mapEntries-bihZ3yks.cjs`);var t=class t{static OMIT=e.C;static TAG=e.w;static Tag=e.E;static Simple=e.S;static MapEntries=e.t;static dt_as_Date=e.a;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,n){let r=t.fromCBOR(e,this.#t(n));return r._defaults=this.#e,r}fromEDN(e,n){let r=t.fromEDN(e,this.#t(n));return r._defaults=this.#e,r}fromJS(e,n){let r=t.fromJS(e,this.#t(n));return r._defaults=this.#e,r}fromHexDump(e,n){let r=t.fromHexDump(e,this.#t(n));return r._defaults=this.#e,r}decode(e,n){return t.decode(e,this.#t(n))}encode(e,n){return t.encode(e,this.#t(n))}cborToCborEdn(e,n){return t.cborToCborEdn(e,this.#t(n))}cborEdnToCbor(e,n){return t.cborEdnToCbor(e,this.#t(n))}parse(e,n){if(typeof n==`function`){let r=this.#t({reviver:n});return t.fromEDN(e,r).toJS(r)}let r=this.#t(n);return t.fromEDN(e,r).toJS(r)}stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i={...this.#e};return n===null?i.replacer=void 0:(typeof n==`function`||Array.isArray(n))&&(i.replacer=n),r!==void 0&&(i.indent=a(r)),t.stringify(e,i)}return t.stringify(e,this.#t(n??void 0))}format(e,n){return t.format(e,this.#t(n))}static fromCBOR(t,n){return e.i(t,n)}static fromEDN(t,n){return e.s(t,n)}static fromJS(t,n){return e.r(t,n)}static fromHexDump(t,r){let i=[],a=n(t).trim().split(/\s+/).filter(Boolean);for(let e of a){if(!/^[0-9A-Fa-f]{2}$/.test(e))throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);i.push(parseInt(e,16))}return e.i(new Uint8Array(i),r)}static decode(e,n){return t.fromCBOR(e,n).toJS(n)}static encode(e,n){return t.fromJS(e,n).toCBOR(n)}static cborToCborEdn(e,n){return t.fromCBOR(e,n).toEDN(n)}static cborEdnToCbor(e,n){return t.fromEDN(e,n).toCBOR(n)}static parse(e,n){return typeof n==`function`?t.fromEDN(e).toJS({reviver:n}):t.fromEDN(e,n).toJS(n)}static stringify(t,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,o=a(r);if(i){let n=e.n(t,i);return n===void 0||n===e.C?void 0:e.r(n).toEDN(o===void 0?void 0:{indent:o})}return e.r(t).toEDN(o===void 0?void 0:{indent:o})}let i=n;if(i?.replacer){let n=e.n(t,i.replacer,i.extensions,i.undefinedOmits);if(n===void 0||n===e.C)return;let{replacer:r,...a}=i;return e.r(n,Object.keys(a).length>0?a:void 0).toEDN(i)}return e.r(t,i).toEDN(i)}static format(e,n){return t.fromEDN(e,n).toEDN(n)}};function n(e){let t=``,n=0;for(;n<e.length;){let a=e[n],o=e[n+1]??``;if(a===`-`&&o===`-`){n=r(e,n+2),t+=` `;continue}if(a===`#`){n=r(e,n+1),t+=` `;continue}if(a===`/`&&o===`/`){n=r(e,n+2),t+=` `;continue}if(a===`/`&&o===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=i(e.slice(n,r+2)),n=r+2;continue}if(a===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=i(e.slice(n,r+1)),n=r+1;continue}t+=a,n++}return t}function r(e,t){let n=e.indexOf(`
|
|
2
2
|
`,t);return n<0?e.length:n}function i(e){return e.replace(/[^\r\n]/g,` `)}function a(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.CBOR=t,exports.default=t,exports.CBOR_OMIT=e.C,exports.CBOR_TAG=e.w,exports.MapEntries=e.t,exports.Null=e.T,exports.Simple=e.S,exports.Tag=e.E,exports.Undefined=e.D,exports.dt_as_Date=e.a;
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromHexDumpOptions,\n FromEDNOptions,\n FromJSOptions,\n ToCBOROptions,\n ToEDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseEDN } from './edn/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 CBOR-EDN 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 fromEDN(text: string, options?: FromEDNOptions): CborItem {\n const node = CBOR.fromEDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\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 decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.cborToCborEdn(input, this.#merge(options));\n }\n\n cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cborEdnToCbor(text, this.#merge(options));\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: FromEDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromEDN(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 & ToEDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\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 & ToEDNOptions = {\n ...(this.#defaults as FromJSOptions & ToEDNOptions),\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?: FromEDNOptions & ToEDNOptions): 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 CBOR-EDN text string into an AST node. */\n static fromEDN(text: string, options?: FromEDNOptions): CborItem {\n return parseEDN(text, options);\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 throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\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 /** 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 /** Convert CBOR binary data directly to a CBOR-EDN text string. */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toEDN(options);\n }\n\n /** Convert a CBOR-EDN text string directly to CBOR binary data. */\n static cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromEDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CBOR-EDN 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 EDN 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: FromEDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromEDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromEDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CBOR-EDN 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 `ToEDNOptions.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 & ToEDNOptions\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 & ToEDNOptions),\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).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToEDNOptions) | 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 ).toEDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toEDN(opts);\n }\n\n /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.fromEDN(text, options).toEDN(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 === '/' && 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\n/** Map JSON.stringify `space` argument to ToEDNOptions.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":"4IAwCA,IAAa,EAAb,MAAa,CAAK,CAMhB,OAAgB,KAAyB,EAAA,EAGzC,OAAgB,IAAuB,EAAA,EAGvC,OAAgB,IAAmB,EAAA,EAGnC,OAAgB,OAAyB,EAAA,EAGzC,OAAgB,WAAiC,EAAA,EAGjD,OAAgB,WAAiC,EAAA,EAIjD,GAWA,YAAY,EAAwB,CAClC,KAAKA,GAAY,GAAY,EAAE,CAGjC,GAAyB,EAA8B,CACrD,MAAO,CAAE,GAAG,KAAKA,GAAW,GAAI,GAAW,EAAE,CAAG,CAGlD,SACE,EACA,EACU,CACV,IAAM,EAAO,EAAK,SAAS,EAAO,KAAKC,GAAO,EAAQ,CAAC,CAEvD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,QAAQ,EAAc,EAAoC,CACxD,IAAM,EAAO,EAAK,QAAQ,EAAM,KAAKC,GAAO,EAAQ,CAAC,CAErD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,OAAO,EAAgB,EAAmC,CACxD,IAAM,EAAO,EAAK,OAAO,EAAO,KAAKC,GAAO,EAAQ,CAAC,CAErD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,YAAY,EAAc,EAAwC,CAChE,IAAM,EAAO,EAAK,YAAY,EAAM,KAAKC,GAAO,EAAQ,CAAC,CAEzD,MADA,GAAK,UAAY,KAAKD,GACf,EAGT,OACE,EACA,EACS,CACT,OAAO,EAAK,OAAO,EAAO,KAAKC,GAAO,EAAQ,CAAC,CAGjD,OAAO,EAAgB,EAAqD,CAC1E,OAAO,EAAK,OAAO,EAAO,KAAKA,GAAO,EAAQ,CAAC,CAGjD,cACE,EACA,EACQ,CACR,OAAO,EAAK,cAAc,EAAO,KAAKA,GAAO,EAAQ,CAAC,CAGxD,cACE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S,EAAgB,EAAc,EAAuB,CAC5D,IAAM,EAAM,EAAK,QAAQ;EAAM,EAAM,CACrC,OAAO,EAAM,EAAI,EAAK,OAAS,EAGjC,SAAS,EAAe,EAAsB,CAC5C,OAAO,EAAK,QAAQ,WAAY,IAAI,CAMtC,SAAS,EACP,EAC6B,CAC7B,GAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAI,KAAK,MAAM,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,EAAM,CAAC,CAAC,CACtD,OAAO,IAAM,EAAI,IAAA,GAAY,EAE/B,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,GAClB,EAAK,IAAA"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromHexDumpOptions,\n FromEDNOptions,\n FromJSOptions,\n ToCBOROptions,\n ToEDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseEDN } from './edn/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 CBOR-EDN 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 fromEDN(text: string, options?: FromEDNOptions): CborItem {\n const node = CBOR.fromEDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\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 decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromCBOR(input, options).toEDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.cborToCborEdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromEDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cborEdnToCbor(text, this.#merge(options));\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: FromEDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromEDN(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 & ToEDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\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 & ToEDNOptions = {\n ...(this.#defaults as FromJSOptions & ToEDNOptions),\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?: FromEDNOptions & ToEDNOptions): 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 CBOR-EDN text string into an AST node. */\n static fromEDN(text: string, options?: FromEDNOptions): CborItem {\n return parseEDN(text, options);\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 throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\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 /** 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 * Convert CBOR binary data directly to a CBOR-EDN text string.\n *\n * @deprecated Use `CBOR.fromCBOR(input, options).toEDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toEDN(options);\n }\n\n /**\n * Convert a CBOR-EDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.fromEDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromEDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CBOR-EDN 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 EDN 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: FromEDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromEDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromEDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CBOR-EDN 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 `ToEDNOptions.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 & ToEDNOptions\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 & ToEDNOptions),\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).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToEDNOptions) | 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 ).toEDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toEDN(opts);\n }\n\n /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.fromEDN(text, options).toEDN(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 === '/' && 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\n/** Map JSON.stringify `space` argument to ToEDNOptions.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":"4IAwCA,IAAa,EAAb,MAAa,CAAK,CAMhB,OAAgB,KAAyB,EAAA,EAGzC,OAAgB,IAAuB,EAAA,EAGvC,OAAgB,IAAmB,EAAA,EAGnC,OAAgB,OAAyB,EAAA,EAGzC,OAAgB,WAAiC,EAAA,EAGjD,OA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AI,IAAA,GAAY,EAE/B,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,GAClB,EAAK,IAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as e, D as t, E as n, S as r, T as i, a, i as o, n as s, r as c, s as l, t as u, w as d } from "./mapEntries-
|
|
1
|
+
import { C as e, D as t, E as n, S as r, T as i, a, i as o, n as s, r as c, s as l, t as u, w as d } from "./mapEntries-D5MWtXqq.js";
|
|
2
2
|
//#region src/cbor.ts
|
|
3
3
|
var f = class t {
|
|
4
4
|
static OMIT = e;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromHexDumpOptions,\n FromEDNOptions,\n FromJSOptions,\n ToCBOROptions,\n ToEDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseEDN } from './edn/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 CBOR-EDN 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 fromEDN(text: string, options?: FromEDNOptions): CborItem {\n const node = CBOR.fromEDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\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 decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.cborToCborEdn(input, this.#merge(options));\n }\n\n cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cborEdnToCbor(text, this.#merge(options));\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: FromEDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromEDN(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 & ToEDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\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 & ToEDNOptions = {\n ...(this.#defaults as FromJSOptions & ToEDNOptions),\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?: FromEDNOptions & ToEDNOptions): 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 CBOR-EDN text string into an AST node. */\n static fromEDN(text: string, options?: FromEDNOptions): CborItem {\n return parseEDN(text, options);\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 throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\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 /** 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 /** Convert CBOR binary data directly to a CBOR-EDN text string. */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toEDN(options);\n }\n\n /** Convert a CBOR-EDN text string directly to CBOR binary data. */\n static cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromEDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CBOR-EDN 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 EDN 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: FromEDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromEDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromEDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CBOR-EDN 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 `ToEDNOptions.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 & ToEDNOptions\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 & ToEDNOptions),\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).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToEDNOptions) | 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 ).toEDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toEDN(opts);\n }\n\n /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.fromEDN(text, options).toEDN(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 === '/' && 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\n/** Map JSON.stringify `space` argument to ToEDNOptions.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":";;AAwCA,IAAa,IAAb,MAAa,EAAK;CAMhB,OAAgB,OAAyB;CAGzC,OAAgB,MAAuB;CAGvC,OAAgB,MAAmB;CAGnC,OAAgB,SAAyB;CAGzC,OAAgB,aAAiC;CAGjD,OAAgB,aAAiC;CAIjD;CAWA,YAAY,GAAwB;EAClC,KAAKA,KAAY,KAAY,EAAE;;CAGjC,GAAyB,GAA8B;EACrD,OAAO;GAAE,GAAG,KAAKA;GAAW,GAAI,KAAW,EAAE;GAAG;;CAGlD,SACE,GACA,GACU;EACV,IAAM,IAAO,EAAK,SAAS,GAAO,KAAKC,GAAO,EAAQ,CAAC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EAChC,KAAO;GACP;;EAGF,IAAI,MAAO,KAAK;GAEd,AADA,IAAI,EAAgB,GAAM,IAAI,EAAE,EAChC,KAAO;GACP;;EAGF,IAAI,MAAO,OAAO,MAAS,KAAK;GAE9B,AADA,IAAI,EAAgB,GAAM,IAAI,EAAE,EAChC,KAAO;GACP;;EAGF,IAAI,MAAO,OAAO,MAAS,KAAK;GAC9B,IAAM,IAAM,EAAK,QAAQ,MAAM,IAAI,EAAE;GACrC,IAAI,IAAM,GAAG,MAAU,YAAY,mCAAmC;GAEtE,AADA,KAAO,EAAe,EAAK,MAAM,GAAG,IAAM,EAAE,CAAC,EAC7C,IAAI,IAAM;GACV;;EAGF,IAAI,MAAO,KAAK;GACd,IAAM,IAAM,EAAK,QAAQ,KAAK,IAAI,EAAE;GACpC,IAAI,IAAM,GAAG,MAAU,YAAY,mCAAmC;GAEtE,AADA,KAAO,EAAe,EAAK,MAAM,GAAG,IAAM,EAAE,CAAC,EAC7C,IAAI,IAAM;GACV;;EAIF,AADA,KAAO,GACP;;CAGF,OAAO;;AAGT,SAAS,EAAgB,GAAc,GAAuB;CAC5D,IAAM,IAAM,EAAK,QAAQ,MAAM,EAAM;CACrC,OAAO,IAAM,IAAI,EAAK,SAAS;;AAGjC,SAAS,EAAe,GAAsB;CAC5C,OAAO,EAAK,QAAQ,YAAY,IAAI;;AAMtC,SAAS,EACP,GAC6B;CAC7B,IAAI,OAAO,KAAU,UAAU;EAC7B,IAAM,IAAI,KAAK,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,EAAM,CAAC,CAAC;EACtD,OAAO,MAAM,IAAI,KAAA,IAAY;;CAE/B,IAAI,OAAO,KAAU,UAEnB,OADU,EAAM,MAAM,GAAG,GAClB,IAAK,KAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromHexDumpOptions,\n FromEDNOptions,\n FromJSOptions,\n ToCBOROptions,\n ToEDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseEDN } from './edn/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 CBOR-EDN 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 fromEDN(text: string, options?: FromEDNOptions): CborItem {\n const node = CBOR.fromEDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\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 decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromCBOR(input, options).toEDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.cborToCborEdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromEDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cborEdnToCbor(text, this.#merge(options));\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: FromEDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromEDN(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 & ToEDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\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 & ToEDNOptions = {\n ...(this.#defaults as FromJSOptions & ToEDNOptions),\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?: FromEDNOptions & ToEDNOptions): 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 CBOR-EDN text string into an AST node. */\n static fromEDN(text: string, options?: FromEDNOptions): CborItem {\n return parseEDN(text, options);\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 throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\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 /** 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 * Convert CBOR binary data directly to a CBOR-EDN text string.\n *\n * @deprecated Use `CBOR.fromCBOR(input, options).toEDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toEDN(options);\n }\n\n /**\n * Convert a CBOR-EDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.fromEDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromEDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CBOR-EDN 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 EDN 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: FromEDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromEDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromEDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CBOR-EDN 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 `ToEDNOptions.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 & ToEDNOptions\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 & ToEDNOptions),\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).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToEDNOptions) | 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 ).toEDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toEDN(opts);\n }\n\n /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.fromEDN(text, options).toEDN(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 === '/' && 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\n/** Map JSON.stringify `space` argument to ToEDNOptions.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":";;AAwCA,IAAa,IAAb,MAAa,EAAK;CAMhB,OAAgB,OAAyB;CAGzC,OAAgB,MAAuB;CAGvC,OAAgB,MAAmB;CAGnC,OAAgB,SAAyB;CAGzC,OAAgB,aAAiC;CAGjD,OAAgB,aAAiC;CAIjD;CAWA,YAAY,GAAwB;EAClC,KAAKA,KAAY,KAAY,EAAE;;CAGjC,GAAyB,GAA8B;EACrD,OAAO;GAAE,GAAG,KAAKA;GAAW,GAAI,KAAW,EAAE;GAAG;;CAGlD,SACE,GACA,GACU;EACV,IAAM,IAAO,EAAK,SAAS,GAAO,KAAKC,GAAO,EAAQ,CAAC;EAEvD,OADA,EAAK,YAAY,KAAKD,IACf;;CAGT,QAAQ,GAAc,GAAoC;EACxD,IAAM,IAAO,EAAK,QAAQ,GAAM,KAAKC,GAAO,EAAQ,CAAC;EAErD,OADA,EAAK,YAAY,KAAKD,IACf;;CAGT,OAAO,GAAgB,GAAmC;EACxD,IAAM,IAAO,EAAK,OAAO,GAAO,KAAKC,GAAO,EAAQ,CAAC;EAErD,OADA,EAAK,YAAY,KAAKD,IACf;;CAGT,YAAY,GAAc,GAAwC;EAChE,IAAM,IAAO,EAAK,YAAY,GAAM,KAAKC,G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