links-notation 0.22.0 → 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.md +3 -0
- package/dist/index.js +904 -109
- package/index.d.ts +96 -0
- package/package.json +4 -4
- package/src/Binary.js +772 -0
- package/src/Link.js +3 -47
- package/src/ReferenceLiteral.js +66 -0
- package/src/grammar.pegjs +12 -2
- package/src/index.js +16 -0
- package/src/parser-generated.js +262 -89
- package/tests/Binary.test.js +165 -0
- package/tests/EmptyReference.test.js +2 -2
- package/tests/ReferenceFidelity.test.js +99 -0
- package/bun.lock +0 -213
package/index.d.ts
CHANGED
|
@@ -470,3 +470,99 @@ export function formatLinks(
|
|
|
470
470
|
links: Link[],
|
|
471
471
|
lessParentheses?: boolean | FormatOptions | FormatConfig
|
|
472
472
|
): string;
|
|
473
|
+
|
|
474
|
+
/** Binary links notation v1: bigint preserves unsigned 64-bit references. */
|
|
475
|
+
export class External {
|
|
476
|
+
value: bigint;
|
|
477
|
+
constructor(value: bigint | number);
|
|
478
|
+
}
|
|
479
|
+
export class ArityRange {
|
|
480
|
+
min: bigint;
|
|
481
|
+
max: bigint | null;
|
|
482
|
+
constructor(min?: bigint | number, max?: bigint | number | null);
|
|
483
|
+
contains(length: bigint | number): boolean;
|
|
484
|
+
readonly fixed: boolean;
|
|
485
|
+
static parse(text: string): ArityRange;
|
|
486
|
+
}
|
|
487
|
+
export interface BinaryLimits {
|
|
488
|
+
maxLinks: number;
|
|
489
|
+
maxReferences: number;
|
|
490
|
+
maxNodes: number;
|
|
491
|
+
maxStringBytes: number;
|
|
492
|
+
maxDepth: number;
|
|
493
|
+
}
|
|
494
|
+
export class DecodeLimits implements BinaryLimits {
|
|
495
|
+
maxLinks: number;
|
|
496
|
+
maxReferences: number;
|
|
497
|
+
maxNodes: number;
|
|
498
|
+
maxStringBytes: number;
|
|
499
|
+
maxDepth: number;
|
|
500
|
+
constructor(values?: Partial<BinaryLimits>);
|
|
501
|
+
static unlimited(): DecodeLimits;
|
|
502
|
+
}
|
|
503
|
+
export class BinaryLinoOptions {
|
|
504
|
+
externalReferences: boolean;
|
|
505
|
+
arity: ArityRange;
|
|
506
|
+
packedWidths: boolean;
|
|
507
|
+
constructor(
|
|
508
|
+
externalReferences?: boolean,
|
|
509
|
+
arity?: ArityRange,
|
|
510
|
+
packedWidths?: boolean
|
|
511
|
+
);
|
|
512
|
+
static ofPacket(packet: LinksPacket): BinaryLinoOptions;
|
|
513
|
+
}
|
|
514
|
+
export type PacketReference = bigint | number | External;
|
|
515
|
+
export type AddressedLink = [bigint | number, PacketReference[]];
|
|
516
|
+
export class Section {
|
|
517
|
+
gap: bigint;
|
|
518
|
+
arity: ArityRange;
|
|
519
|
+
width: number;
|
|
520
|
+
links: PacketReference[][];
|
|
521
|
+
constructor(
|
|
522
|
+
gap: bigint | number,
|
|
523
|
+
arity: ArityRange,
|
|
524
|
+
width: number,
|
|
525
|
+
links: PacketReference[][]
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
export class PacketReader {
|
|
529
|
+
bytes: Uint8Array;
|
|
530
|
+
offset: number;
|
|
531
|
+
constructor(bytes: Uint8Array, offset?: number);
|
|
532
|
+
read(limits?: DecodeLimits): LinksPacket | null;
|
|
533
|
+
}
|
|
534
|
+
export class LinksPacket {
|
|
535
|
+
externalReferences: boolean;
|
|
536
|
+
sections: Section[];
|
|
537
|
+
constructor(externalReferences?: boolean, sections?: Section[]);
|
|
538
|
+
links(): [bigint, (bigint | External)[]][];
|
|
539
|
+
validate(limits?: DecodeLimits): this;
|
|
540
|
+
toBytes(limits?: DecodeLimits): Uint8Array;
|
|
541
|
+
static fromBytes(bytes: Uint8Array, limits?: DecodeLimits): LinksPacket;
|
|
542
|
+
static parseLinks(text: string): [bigint, (bigint | External)[]][];
|
|
543
|
+
static pack(
|
|
544
|
+
externalReferences: boolean,
|
|
545
|
+
links: AddressedLink[],
|
|
546
|
+
packedWidths?: boolean
|
|
547
|
+
): LinksPacket;
|
|
548
|
+
}
|
|
549
|
+
export class BinaryLinoCodec {
|
|
550
|
+
options: BinaryLinoOptions;
|
|
551
|
+
limits: DecodeLimits;
|
|
552
|
+
constructor(options?: BinaryLinoOptions, limits?: DecodeLimits);
|
|
553
|
+
encodePacket(document: Link[]): LinksPacket;
|
|
554
|
+
encode(document: Link[]): Uint8Array;
|
|
555
|
+
decodePacket(packet: LinksPacket): Link[];
|
|
556
|
+
decode(bytes: Uint8Array): Link[];
|
|
557
|
+
parseDocument(text: string, parser?: Parser): Link[];
|
|
558
|
+
formatDocument(document: Link[]): string;
|
|
559
|
+
encodeText(text: string, parser?: Parser): Uint8Array;
|
|
560
|
+
decodeText(bytes: Uint8Array): string;
|
|
561
|
+
}
|
|
562
|
+
export function formatBinaryDocument(document: Link[]): string;
|
|
563
|
+
export function formatBinaryReference(reference: string): string;
|
|
564
|
+
|
|
565
|
+
/** Encode exact Unicode as a version 1 UTF-8 hex literal (~1{...}). Throws on unpaired surrogates. */
|
|
566
|
+
export function encodeReferenceLiteral(text: string): string;
|
|
567
|
+
/** Decode a complete literal. Throws on malformed hex, UTF-8, or unsupported versions. */
|
|
568
|
+
export function decodeReferenceLiteral(literal: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "links-notation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Links Notation parser for JavaScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/link-foundation/links-notation#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"bun-types": "^1.4.
|
|
36
|
-
"eslint": "^10.
|
|
35
|
+
"bun-types": "^1.4.2",
|
|
36
|
+
"eslint": "^10.12.0",
|
|
37
37
|
"peggy": "^5.1.0",
|
|
38
|
-
"prettier": "^3.9.
|
|
38
|
+
"prettier": "^3.9.9",
|
|
39
39
|
"typescript": "^7.0.2"
|
|
40
40
|
}
|
|
41
41
|
}
|