Initial commit: notification-elements-demo app

Interactive Angular 19 demo for @sda/notification-elements-ui with
6 sections: Bell & Feed, Notification Center, Inbox, Comments &
Threads, Mention Input, and Full-Featured layout. Includes mock
data, dark mode toggle, and real-time event log.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Giuliano Silvestro
2026-02-13 21:49:19 +10:00
commit 5d0c9ec7eb
36473 changed files with 3778146 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
import { Reader } from '@jsonjoy.com/buffers/lib/Reader';
import type { BinaryJsonDecoder, PackValue } from '../types';
export declare const readKey: (reader: Reader) => string;
export declare class JsonDecoder implements BinaryJsonDecoder {
reader: Reader;
read(uint8: Uint8Array): unknown;
decode(uint8: Uint8Array): unknown;
readAny(): unknown;
skipWhitespace(): void;
readNull(): null;
readTrue(): true;
readFalse(): false;
readBool(): unknown;
readNum(): number;
readStr(): string;
tryReadBin(): Uint8Array | undefined;
readBin(): Uint8Array;
readArr(): unknown[];
readObj(): PackValue | Record<string, unknown> | unknown;
}

View File

@@ -0,0 +1,601 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonDecoder = exports.readKey = void 0;
const decodeUtf8_1 = require("@jsonjoy.com/buffers/lib/utf8/decodeUtf8");
const Reader_1 = require("@jsonjoy.com/buffers/lib/Reader");
const fromBase64Bin_1 = require("@jsonjoy.com/base64/lib/fromBase64Bin");
const util_1 = require("./util");
const REGEX_REPLACE_ESCAPED_CHARS = /\\(b|f|n|r|t|"|\/|\\)/g;
const escapedCharReplacer = (char) => {
switch (char) {
case '\\b':
return '\b';
case '\\f':
return '\f';
case '\\n':
return '\n';
case '\\r':
return '\r';
case '\\t':
return '\t';
case '\\"':
return '"';
case '\\/':
return '/';
case '\\\\':
return '\\';
}
return char;
};
const hasBinaryPrefix = (u8, x) => u8[x] === 0x64 &&
u8[x + 1] === 0x61 &&
u8[x + 2] === 0x74 &&
u8[x + 3] === 0x61 &&
u8[x + 4] === 0x3a &&
u8[x + 5] === 0x61 &&
u8[x + 6] === 0x70 &&
u8[x + 7] === 0x70 &&
u8[x + 8] === 0x6c &&
u8[x + 9] === 0x69 &&
u8[x + 10] === 0x63 &&
u8[x + 11] === 0x61 &&
u8[x + 12] === 0x74 &&
u8[x + 13] === 0x69 &&
u8[x + 14] === 0x6f &&
u8[x + 15] === 0x6e &&
u8[x + 16] === 0x2f &&
u8[x + 17] === 0x6f &&
u8[x + 18] === 0x63 &&
u8[x + 19] === 0x74 &&
u8[x + 20] === 0x65 &&
u8[x + 21] === 0x74 &&
u8[x + 22] === 0x2d &&
u8[x + 23] === 0x73 &&
u8[x + 24] === 0x74 &&
u8[x + 25] === 0x72 &&
u8[x + 26] === 0x65 &&
u8[x + 27] === 0x61 &&
u8[x + 28] === 0x6d &&
u8[x + 29] === 0x3b &&
u8[x + 30] === 0x62 &&
u8[x + 31] === 0x61 &&
u8[x + 32] === 0x73 &&
u8[x + 33] === 0x65 &&
u8[x + 34] === 0x36 &&
u8[x + 35] === 0x34 &&
u8[x + 36] === 0x2c;
const isUndefined = (u8, x) => u8[x++] === 0x61 &&
u8[x++] === 0x74 &&
u8[x++] === 0x61 &&
u8[x++] === 0x3a &&
u8[x++] === 0x61 &&
u8[x++] === 0x70 &&
u8[x++] === 0x70 &&
u8[x++] === 0x6c &&
u8[x++] === 0x69 &&
u8[x++] === 0x63 &&
u8[x++] === 0x61 &&
u8[x++] === 0x74 &&
u8[x++] === 0x69 &&
u8[x++] === 0x6f &&
u8[x++] === 0x6e &&
u8[x++] === 0x2f &&
u8[x++] === 0x63 &&
u8[x++] === 0x62 &&
u8[x++] === 0x6f &&
u8[x++] === 0x72 &&
u8[x++] === 0x2c &&
u8[x++] === 0x62 &&
u8[x++] === 0x61 &&
u8[x++] === 0x73 &&
u8[x++] === 0x65 &&
u8[x++] === 0x36 &&
u8[x++] === 0x34 &&
u8[x++] === 0x3b &&
u8[x++] === 0x39 &&
u8[x++] === 0x77 &&
u8[x++] === 0x3d &&
u8[x++] === 0x3d &&
u8[x++] === 0x22;
const fromCharCode = String.fromCharCode;
const readKey = (reader) => {
const buf = reader.uint8;
const len = buf.length;
const points = [];
let x = reader.x;
let prev = 0;
while (x < len) {
let code = buf[x++];
if ((code & 0x80) === 0) {
if (prev === 92) {
switch (code) {
case 98:
code = 8;
break;
case 102:
code = 12;
break;
case 110:
code = 10;
break;
case 114:
code = 13;
break;
case 116:
code = 9;
break;
case 34:
code = 34;
break;
case 47:
code = 47;
break;
case 92:
code = 92;
break;
default:
throw new Error('Invalid JSON');
}
prev = 0;
}
else {
if (code === 34)
break;
prev = code;
if (prev === 92)
continue;
}
}
else {
const octet2 = buf[x++] & 0x3f;
if ((code & 0xe0) === 0xc0) {
code = ((code & 0x1f) << 6) | octet2;
}
else {
const octet3 = buf[x++] & 0x3f;
if ((code & 0xf0) === 0xe0) {
code = ((code & 0x1f) << 12) | (octet2 << 6) | octet3;
}
else {
if ((code & 0xf8) === 0xf0) {
const octet4 = buf[x++] & 0x3f;
let unit = ((code & 0x07) << 0x12) | (octet2 << 0x0c) | (octet3 << 0x06) | octet4;
if (unit > 0xffff) {
unit -= 0x10000;
const unit0 = ((unit >>> 10) & 0x3ff) | 0xd800;
unit = 0xdc00 | (unit & 0x3ff);
points.push(unit0);
code = unit;
}
else {
code = unit;
}
}
}
}
}
points.push(code);
}
reader.x = x;
return fromCharCode.apply(String, points);
};
exports.readKey = readKey;
class JsonDecoder {
constructor() {
this.reader = new Reader_1.Reader();
}
read(uint8) {
this.reader.reset(uint8);
return this.readAny();
}
decode(uint8) {
this.reader.reset(uint8);
return this.readAny();
}
readAny() {
this.skipWhitespace();
const reader = this.reader;
const x = reader.x;
const uint8 = reader.uint8;
const char = uint8[x];
switch (char) {
case 34: {
if (uint8[x + 1] === 0x64) {
const bin = this.tryReadBin();
if (bin)
return bin;
if (isUndefined(uint8, x + 2)) {
reader.x = x + 35;
return undefined;
}
}
return this.readStr();
}
case 91:
return this.readArr();
case 102:
return this.readFalse();
case 110:
return this.readNull();
case 116:
return this.readTrue();
case 123:
return this.readObj();
default:
if ((char >= 48 && char <= 57) || char === 45)
return this.readNum();
throw new Error('Invalid JSON');
}
}
skipWhitespace() {
const reader = this.reader;
const uint8 = reader.uint8;
let x = reader.x;
let char = 0;
while (true) {
char = uint8[x];
switch (char) {
case 32:
case 9:
case 10:
case 13:
x++;
continue;
default:
reader.x = x;
return;
}
}
}
readNull() {
if (this.reader.u32() !== 0x6e756c6c)
throw new Error('Invalid JSON');
return null;
}
readTrue() {
if (this.reader.u32() !== 0x74727565)
throw new Error('Invalid JSON');
return true;
}
readFalse() {
const reader = this.reader;
if (reader.u8() !== 0x66 || reader.u32() !== 0x616c7365)
throw new Error('Invalid JSON');
return false;
}
readBool() {
const reader = this.reader;
switch (reader.uint8[reader.x]) {
case 102:
return this.readFalse();
case 116:
return this.readTrue();
default:
throw new Error('Invalid JSON');
}
}
readNum() {
const reader = this.reader;
const uint8 = reader.uint8;
let x = reader.x;
let c = uint8[x++];
const c1 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c2 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c3 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c4 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c5 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c6 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c7 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c8 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c9 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c10 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c11 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c12 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c13 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c14 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c15 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c16 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c17 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c18 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c19 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c20 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c21 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c22 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c23 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
const c24 = c;
c = uint8[x++];
if (!c || ((c < 45 || c > 57) && c !== 43 && c !== 69 && c !== 101)) {
reader.x = x - 1;
const num = +fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24);
if (num !== num)
throw new Error('Invalid JSON');
return num;
}
throw new Error('Invalid JSON');
}
readStr() {
const reader = this.reader;
const uint8 = reader.uint8;
const char = uint8[reader.x++];
if (char !== 0x22)
throw new Error('Invalid JSON');
const x0 = reader.x;
const x1 = (0, util_1.findEndingQuote)(uint8, x0);
let str = (0, decodeUtf8_1.decodeUtf8)(uint8, x0, x1 - x0);
str = str.replace(REGEX_REPLACE_ESCAPED_CHARS, escapedCharReplacer);
reader.x = x1 + 1;
return str;
}
tryReadBin() {
const reader = this.reader;
const u8 = reader.uint8;
let x = reader.x;
if (u8[x++] !== 0x22)
return undefined;
const hasDataUrlPrefix = hasBinaryPrefix(u8, x);
if (!hasDataUrlPrefix)
return undefined;
x += 37;
const x0 = x;
x = (0, util_1.findEndingQuote)(u8, x);
reader.x = x0;
const bin = (0, fromBase64Bin_1.fromBase64Bin)(reader.view, x0, x - x0);
reader.x = x + 1;
return bin;
}
readBin() {
const reader = this.reader;
const u8 = reader.uint8;
let x = reader.x;
if (u8[x++] !== 0x22)
throw new Error('Invalid JSON');
const hasDataUrlPrefix = hasBinaryPrefix(u8, x);
if (!hasDataUrlPrefix)
throw new Error('Invalid JSON');
x += 37;
const x0 = x;
x = (0, util_1.findEndingQuote)(u8, x);
reader.x = x0;
const bin = (0, fromBase64Bin_1.fromBase64Bin)(reader.view, x0, x - x0);
reader.x = x + 1;
return bin;
}
readArr() {
const reader = this.reader;
if (reader.u8() !== 0x5b)
throw new Error('Invalid JSON');
const arr = [];
const uint8 = reader.uint8;
let first = true;
while (true) {
this.skipWhitespace();
const char = uint8[reader.x];
if (char === 0x5d)
return reader.x++, arr;
if (char === 0x2c)
reader.x++;
else if (!first)
throw new Error('Invalid JSON');
this.skipWhitespace();
arr.push(this.readAny());
first = false;
}
}
readObj() {
const reader = this.reader;
if (reader.u8() !== 0x7b)
throw new Error('Invalid JSON');
const obj = {};
const uint8 = reader.uint8;
let first = true;
while (true) {
this.skipWhitespace();
let char = uint8[reader.x];
if (char === 0x7d)
return reader.x++, obj;
if (char === 0x2c)
reader.x++;
else if (!first)
throw new Error('Invalid JSON');
this.skipWhitespace();
char = uint8[reader.x++];
if (char !== 0x22)
throw new Error('Invalid JSON');
const key = (0, exports.readKey)(reader);
if (key === '__proto__')
throw new Error('Invalid JSON');
this.skipWhitespace();
if (reader.u8() !== 0x3a)
throw new Error('Invalid JSON');
this.skipWhitespace();
obj[key] = this.readAny();
first = false;
}
}
}
exports.JsonDecoder = JsonDecoder;
//# sourceMappingURL=JsonDecoder.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,9 @@
import { JsonDecoder } from './JsonDecoder';
import type { PackValue } from '../types';
export declare const fromBase64Bin: (view: DataView, offset: number, length: number) => Uint8Array;
export declare class JsonDecoderDag extends JsonDecoder {
readObj(): PackValue | Record<string, PackValue> | Uint8Array | unknown;
protected tryReadBytes(): Uint8Array | undefined;
protected tryReadCid(): undefined | unknown;
readCid(cid: string): unknown;
}

View File

@@ -0,0 +1,118 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonDecoderDag = exports.fromBase64Bin = void 0;
const JsonDecoder_1 = require("./JsonDecoder");
const util_1 = require("./util");
const createFromBase64Bin_1 = require("@jsonjoy.com/base64/lib/createFromBase64Bin");
exports.fromBase64Bin = (0, createFromBase64Bin_1.createFromBase64Bin)(undefined, '');
class JsonDecoderDag extends JsonDecoder_1.JsonDecoder {
readObj() {
const bytes = this.tryReadBytes();
if (bytes)
return bytes;
const cid = this.tryReadCid();
if (cid)
return cid;
return super.readObj();
}
tryReadBytes() {
const reader = this.reader;
const x = reader.x;
if (reader.u8() !== 0x7b) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x22 || reader.u8() !== 0x2f || reader.u8() !== 0x22) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x3a) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x7b) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x22 ||
reader.u8() !== 0x62 ||
reader.u8() !== 0x79 ||
reader.u8() !== 0x74 ||
reader.u8() !== 0x65 ||
reader.u8() !== 0x73 ||
reader.u8() !== 0x22) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x3a) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x22) {
reader.x = x;
return;
}
const bufStart = reader.x;
const bufEnd = (0, util_1.findEndingQuote)(reader.uint8, bufStart);
reader.x = 1 + bufEnd;
this.skipWhitespace();
if (reader.u8() !== 0x7d) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x7d) {
reader.x = x;
return;
}
const bin = (0, exports.fromBase64Bin)(reader.view, bufStart, bufEnd - bufStart);
return bin;
}
tryReadCid() {
const reader = this.reader;
const x = reader.x;
if (reader.u8() !== 0x7b) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x22 || reader.u8() !== 0x2f || reader.u8() !== 0x22) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x3a) {
reader.x = x;
return;
}
this.skipWhitespace();
if (reader.u8() !== 0x22) {
reader.x = x;
return;
}
const bufStart = reader.x;
const bufEnd = (0, util_1.findEndingQuote)(reader.uint8, bufStart);
reader.x = 1 + bufEnd;
this.skipWhitespace();
if (reader.u8() !== 0x7d) {
reader.x = x;
return;
}
const finalX = reader.x;
reader.x = bufStart;
const cid = reader.ascii(bufEnd - bufStart);
reader.x = finalX;
return this.readCid(cid);
}
readCid(cid) {
return cid;
}
}
exports.JsonDecoderDag = JsonDecoderDag;
//# sourceMappingURL=JsonDecoderDag.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"JsonDecoderDag.js","sourceRoot":"","sources":["../../src/json/JsonDecoderDag.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAC1C,iCAAuC;AAEvC,qFAAgF;AAEnE,QAAA,aAAa,GAAG,IAAA,yCAAmB,EAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AAEhE,M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AAQ,CAAC;QACpB,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;QAC5C,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,OAAO,CAAC,GAAW;QACxB,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AA7HD,wCA6HC"}

View File

@@ -0,0 +1,11 @@
import { JsonDecoder } from './JsonDecoder';
import type { PackValue } from '../types';
export declare class DecodeFinishError extends Error {
readonly value: unknown;
constructor(value: unknown);
}
export declare class JsonDecoderPartial extends JsonDecoder {
readAny(): unknown;
readArr(): unknown[];
readObj(): PackValue | Record<string, unknown> | unknown;
}

View File

@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonDecoderPartial = exports.DecodeFinishError = void 0;
const JsonDecoder_1 = require("./JsonDecoder");
class DecodeFinishError extends Error {
constructor(value) {
super('DECODE_FINISH');
this.value = value;
}
}
exports.DecodeFinishError = DecodeFinishError;
class JsonDecoderPartial extends JsonDecoder_1.JsonDecoder {
readAny() {
try {
return super.readAny();
}
catch (error) {
if (error instanceof DecodeFinishError)
return error.value;
throw error;
}
}
readArr() {
const reader = this.reader;
if (reader.u8() !== 0x5b)
throw new Error('Invalid JSON');
const arr = [];
const uint8 = reader.uint8;
let first = true;
while (true) {
this.skipWhitespace();
const char = uint8[reader.x];
if (char === 0x5d)
return reader.x++, arr;
if (char === 0x2c)
reader.x++;
else if (!first)
return arr;
this.skipWhitespace();
try {
arr.push(this.readAny());
}
catch (error) {
if (error instanceof DecodeFinishError)
return arr.push(error.value), arr;
if (error instanceof Error && error.message === 'Invalid JSON')
throw new DecodeFinishError(arr);
throw error;
}
first = false;
}
}
readObj() {
const reader = this.reader;
if (reader.u8() !== 0x7b)
throw new Error('Invalid JSON');
const obj = {};
const uint8 = reader.uint8;
while (true) {
this.skipWhitespace();
let char = uint8[reader.x];
if (char === 0x7d)
return reader.x++, obj;
if (char === 0x2c) {
reader.x++;
continue;
}
try {
char = uint8[reader.x++];
if (char !== 0x22)
throw new Error('Invalid JSON');
const key = (0, JsonDecoder_1.readKey)(reader);
if (key === '__proto__')
throw new Error('Invalid JSON');
this.skipWhitespace();
if (reader.u8() !== 0x3a)
throw new Error('Invalid JSON');
this.skipWhitespace();
try {
obj[key] = this.readAny();
}
catch (error) {
if (error instanceof DecodeFinishError) {
obj[key] = error.value;
return obj;
}
throw error;
}
}
catch (error) {
if (error instanceof DecodeFinishError)
return obj;
if (error instanceof Error && error.message === 'Invalid JSON')
throw new DecodeFinishError(obj);
throw error;
}
}
}
}
exports.JsonDecoderPartial = JsonDecoderPartial;
//# sourceMappingURL=JsonDecoderPartial.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"JsonDecoderPartial.js","sourceRoot":"","sources":["../../src/json/JsonDecoderPartial.ts"],"names":[],"mappings":";;;AAAA,+CAAmD;AAGnD,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAA4B,KAAc;QACxC,KAAK,CAAC,eAAe,CAAC,CAAC;QADG,UAAK,GAAL,KAAK,CAAS;IAE1C,CAAC;CACF;AAJD,8CAIC;AAwBD,MAAa,kBAAmB,SAAQ,yBAAW;IAC1C,OAAO;QACZ,IAAI,CAAC;YACH,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,iBAAiB;gBAAE,OAAO,KAAK,CAAC,KAAK,CAAC;YAC3D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAEM,OAAO;QACZ,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,MAAM,CAAC,EAAE,EAAE,KAAK,IAAI;YAAU,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;QAClE,MAAM,GAAG,GAAc,EAAE,C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B,CAAC,GAAG,CAAC,CAAC;gBACjG,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAvED,gDAuEC"}

View File

@@ -0,0 +1,36 @@
import type { IWriter, IWriterGrowable } from '@jsonjoy.com/buffers/lib';
import type { BinaryJsonEncoder, StreamingBinaryJsonEncoder } from '../types';
export declare class JsonEncoder implements BinaryJsonEncoder, StreamingBinaryJsonEncoder {
readonly writer: IWriter & IWriterGrowable;
constructor(writer: IWriter & IWriterGrowable);
encode(value: unknown): Uint8Array;
writeUnknown(value: unknown): void;
writeAny(value: unknown): void;
writeNull(): void;
writeUndef(): void;
writeBoolean(bool: boolean): void;
writeNumber(num: number): void;
writeInteger(int: number): void;
writeUInteger(uint: number): void;
writeFloat(float: number): void;
writeBin(buf: Uint8Array): void;
writeStr(str: string): void;
writeAsciiStr(str: string): void;
writeArr(arr: unknown[]): void;
writeArrSeparator(): void;
writeObj(obj: Record<string, unknown>): void;
writeObjSeparator(): void;
writeObjKeySeparator(): void;
writeStartStr(): void;
writeStrChunk(str: string): void;
writeEndStr(): void;
writeStartBin(): void;
writeBinChunk(buf: Uint8Array): void;
writeEndBin(): void;
writeStartArr(): void;
writeArrChunk(item: unknown): void;
writeEndArr(): void;
writeStartObj(): void;
writeObjChunk(key: string, value: unknown): void;
writeEndObj(): void;
}

View File

@@ -0,0 +1,263 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonEncoder = void 0;
const toBase64Bin_1 = require("@jsonjoy.com/base64/lib/toBase64Bin");
class JsonEncoder {
constructor(writer) {
this.writer = writer;
}
encode(value) {
const writer = this.writer;
writer.reset();
this.writeAny(value);
return writer.flush();
}
writeUnknown(value) {
this.writeNull();
}
writeAny(value) {
switch (typeof value) {
case 'boolean':
return this.writeBoolean(value);
case 'number':
return this.writeNumber(value);
case 'string':
return this.writeStr(value);
case 'object': {
if (value === null)
return this.writeNull();
const constructor = value.constructor;
switch (constructor) {
case Object:
return this.writeObj(value);
case Array:
return this.writeArr(value);
case Uint8Array:
return this.writeBin(value);
default:
if (value instanceof Uint8Array)
return this.writeBin(value);
if (Array.isArray(value))
return this.writeArr(value);
return this.writeUnknown(value);
}
}
case 'undefined': {
return this.writeUndef();
}
default:
return this.writeUnknown(value);
}
}
writeNull() {
this.writer.u32(0x6e756c6c);
}
writeUndef() {
const writer = this.writer;
const length = 35;
writer.ensureCapacity(length);
const view = writer.view;
let x = writer.x;
view.setUint32(x, 577003892);
x += 4;
view.setUint32(x, 1631215984);
x += 4;
view.setUint32(x, 1886153059);
x += 4;
view.setUint32(x, 1635019119);
x += 4;
view.setUint32(x, 1848599394);
x += 4;
view.setUint32(x, 1869753442);
x += 4;
view.setUint32(x, 1634952502);
x += 4;
view.setUint32(x, 876296567);
x += 4;
view.setUint16(x, 15677);
x += 2;
writer.uint8[x++] = 0x22;
writer.x = x;
}
writeBoolean(bool) {
if (bool)
this.writer.u32(0x74727565);
else
this.writer.u8u32(0x66, 0x616c7365);
}
writeNumber(num) {
const str = num.toString();
this.writer.ascii(str);
}
writeInteger(int) {
this.writeNumber(int >> 0 === int ? int : Math.trunc(int));
}
writeUInteger(uint) {
this.writeInteger(uint < 0 ? -uint : uint);
}
writeFloat(float) {
this.writeNumber(float);
}
writeBin(buf) {
const writer = this.writer;
const length = buf.length;
writer.ensureCapacity(38 + 3 + (length << 1));
const view = writer.view;
let x = writer.x;
view.setUint32(x, 577003892);
x += 4;
view.setUint32(x, 1631215984);
x += 4;
view.setUint32(x, 1886153059);
x += 4;
view.setUint32(x, 1635019119);
x += 4;
view.setUint32(x, 1848602467);
x += 4;
view.setUint32(x, 1952805933);
x += 4;
view.setUint32(x, 1937011301);
x += 4;
view.setUint32(x, 1634548578);
x += 4;
view.setUint32(x, 1634952502);
x += 4;
view.setUint16(x, 13356);
x += 2;
x = (0, toBase64Bin_1.toBase64Bin)(buf, 0, length, view, x);
writer.uint8[x++] = 0x22;
writer.x = x;
}
writeStr(str) {
const writer = this.writer;
const length = str.length;
writer.ensureCapacity(length * 4 + 2);
if (length < 256) {
const startX = writer.x;
let x = startX;
const uint8 = writer.uint8;
uint8[x++] = 0x22;
for (let i = 0; i < length; i++) {
const code = str.charCodeAt(i);
switch (code) {
case 34:
case 92:
uint8[x++] = 0x5c;
break;
}
if (code < 32 || code > 126) {
writer.x = startX;
const jsonStr = JSON.stringify(str);
writer.ensureCapacity(jsonStr.length * 4 + 4);
writer.utf8(jsonStr);
return;
}
else
uint8[x++] = code;
}
uint8[x++] = 0x22;
writer.x = x;
return;
}
const jsonStr = JSON.stringify(str);
writer.ensureCapacity(jsonStr.length * 4 + 4);
writer.utf8(jsonStr);
}
writeAsciiStr(str) {
const length = str.length;
const writer = this.writer;
writer.ensureCapacity(length * 2 + 2);
const uint8 = writer.uint8;
let x = writer.x;
uint8[x++] = 0x22;
for (let i = 0; i < length; i++) {
const code = str.charCodeAt(i);
switch (code) {
case 34:
case 92:
uint8[x++] = 0x5c;
break;
}
uint8[x++] = code;
}
uint8[x++] = 0x22;
writer.x = x;
}
writeArr(arr) {
const writer = this.writer;
writer.u8(0x5b);
const length = arr.length;
const last = length - 1;
for (let i = 0; i < last; i++) {
this.writeAny(arr[i]);
writer.u8(0x2c);
}
if (last >= 0)
this.writeAny(arr[last]);
writer.u8(0x5d);
}
writeArrSeparator() {
this.writer.u8(0x2c);
}
writeObj(obj) {
const writer = this.writer;
const keys = Object.keys(obj);
const length = keys.length;
if (!length)
return writer.u16(0x7b7d);
writer.u8(0x7b);
for (let i = 0; i < length; i++) {
const key = keys[i];
const value = obj[key];
this.writeStr(key);
writer.u8(0x3a);
this.writeAny(value);
writer.u8(0x2c);
}
writer.uint8[writer.x - 1] = 0x7d;
}
writeObjSeparator() {
this.writer.u8(0x2c);
}
writeObjKeySeparator() {
this.writer.u8(0x3a);
}
writeStartStr() {
throw new Error('Method not implemented.');
}
writeStrChunk(str) {
throw new Error('Method not implemented.');
}
writeEndStr() {
throw new Error('Method not implemented.');
}
writeStartBin() {
throw new Error('Method not implemented.');
}
writeBinChunk(buf) {
throw new Error('Method not implemented.');
}
writeEndBin() {
throw new Error('Method not implemented.');
}
writeStartArr() {
this.writer.u8(0x5b);
}
writeArrChunk(item) {
throw new Error('Method not implemented.');
}
writeEndArr() {
this.writer.u8(0x5d);
}
writeStartObj() {
this.writer.u8(0x7b);
}
writeObjChunk(key, value) {
throw new Error('Method not implemented.');
}
writeEndObj() {
this.writer.u8(0x7d);
}
}
exports.JsonEncoder = JsonEncoder;
//# sourceMappingURL=JsonEncoder.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
import { JsonEncoderStable } from './JsonEncoderStable';
export declare class JsonEncoderDag extends JsonEncoderStable {
writeBin(buf: Uint8Array): void;
writeCid(cid: string): void;
}

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonEncoderDag = void 0;
const JsonEncoderStable_1 = require("./JsonEncoderStable");
const createToBase64Bin_1 = require("@jsonjoy.com/base64/lib/createToBase64Bin");
const objBaseLength = '{"/":{"bytes":""}}'.length;
const cidBaseLength = '{"/":""}'.length;
const base64Encode = (0, createToBase64Bin_1.createToBase64Bin)(undefined, '');
class JsonEncoderDag extends JsonEncoderStable_1.JsonEncoderStable {
writeBin(buf) {
const writer = this.writer;
const length = buf.length;
writer.ensureCapacity(objBaseLength + (length << 1));
const view = writer.view;
const uint8 = writer.uint8;
let x = writer.x;
view.setUint32(x, 0x7b222f22);
x += 4;
view.setUint32(x, 0x3a7b2262);
x += 4;
view.setUint32(x, 0x79746573);
x += 4;
view.setUint16(x, 0x223a);
x += 2;
uint8[x] = 0x22;
x += 1;
x = base64Encode(buf, 0, length, view, x);
view.setUint16(x, 0x227d);
x += 2;
uint8[x] = 0x7d;
x += 1;
writer.x = x;
}
writeCid(cid) {
const writer = this.writer;
writer.ensureCapacity(cidBaseLength + cid.length);
writer.u32(0x7b222f22);
writer.u16(0x3a22);
writer.ascii(cid);
writer.u16(0x227d);
}
}
exports.JsonEncoderDag = JsonEncoderDag;
//# sourceMappingURL=JsonEncoderDag.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"JsonEncoderDag.js","sourceRoot":"","sources":["../../src/json/JsonEncoderDag.ts"],"names":[],"mappings":";;;AAAA,2DAAsD;AACtD,iFAA4E;AAE5E,MAAM,aAAa,GAAG,oBAAoB,CAAC,MAAM,CAAC;AAClD,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,CAAC;AACxC,MAAM,YAAY,GAAG,IAAA,qCAAiB,EAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AAOtD,MAAa,cAAe,SAAQ,qCAAiB;IAa5C,QAAQ,CAAC,GAAe;QAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QAC1B,MAAM,CAAC,cAAc,CAAC,aAAa,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC;QACrD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACzB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;QACjB,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QAC9B,CAAC,IAAI,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QAC9B,CAAC,IAAI,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;QAC9B,CAAC,IAAI,CAAC,CAAC;QACP,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1B,CAAC,IAAI,CAAC,CAAC;QACP,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QAChB,CAAC,IAAI,CAAC,CAAC;QACP,CAAC,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1B,CAAC,IAAI,CAAC,CAAC;QACP,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QAChB,CAAC,IAAI,CAAC,CAAC;QACP,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;IAEM,QAAQ,CAAC,GAAW;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,aAAa,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;QAClD,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACvB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACnB,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAClB,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;CACF;AA9CD,wCA8CC"}

View File

@@ -0,0 +1,4 @@
import { JsonEncoder } from './JsonEncoder';
export declare class JsonEncoderStable extends JsonEncoder {
writeObj(obj: Record<string, unknown>): void;
}

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonEncoderStable = void 0;
const JsonEncoder_1 = require("./JsonEncoder");
const insertion2_1 = require("@jsonjoy.com/util/lib/sort/insertion2");
const objKeyCmp_1 = require("@jsonjoy.com/util/lib/objKeyCmp");
class JsonEncoderStable extends JsonEncoder_1.JsonEncoder {
writeObj(obj) {
const writer = this.writer;
const keys = Object.keys(obj);
(0, insertion2_1.sort)(keys, objKeyCmp_1.objKeyCmp);
const length = keys.length;
if (!length)
return writer.u16(0x7b7d);
writer.u8(0x7b);
for (let i = 0; i < length; i++) {
const key = keys[i];
const value = obj[key];
this.writeStr(key);
writer.u8(0x3a);
this.writeAny(value);
writer.u8(0x2c);
}
writer.uint8[writer.x - 1] = 0x7d;
}
}
exports.JsonEncoderStable = JsonEncoderStable;
//# sourceMappingURL=JsonEncoderStable.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"JsonEncoderStable.js","sourceRoot":"","sources":["../../src/json/JsonEncoderStable.ts"],"names":[],"mappings":";;;AAAA,+CAA0C;AAC1C,sEAA2D;AAC3D,+DAA0D;AAE1D,MAAa,iBAAkB,SAAQ,yBAAW;IACzC,QAAQ,CAAC,GAA4B;QAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC9B,IAAA,iBAAI,EAAC,IAAI,EAAE,qBAAS,CAAC,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM;YAAE,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACvC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACpB,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACnB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YAChB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrB,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;QACD,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IACpC,CAAC;CACF;AAlBD,8CAkBC"}

View File

@@ -0,0 +1,6 @@
export * from './types';
export * from './JsonEncoder';
export * from './JsonEncoderStable';
export * from './JsonEncoderDag';
export * from './JsonDecoder';
export * from './JsonDecoderDag';

10
node_modules/@jsonjoy.com/json-pack/lib/json/index.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./types"), exports);
tslib_1.__exportStar(require("./JsonEncoder"), exports);
tslib_1.__exportStar(require("./JsonEncoderStable"), exports);
tslib_1.__exportStar(require("./JsonEncoderDag"), exports);
tslib_1.__exportStar(require("./JsonDecoder"), exports);
tslib_1.__exportStar(require("./JsonDecoderDag"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,wDAA8B;AAC9B,8DAAoC;AACpC,2DAAiC;AACjC,wDAA8B;AAC9B,2DAAiC"}

View File

@@ -0,0 +1,4 @@
export type JsonUint8Array<T> = Uint8Array & {
__BRAND__: 'json';
__TYPE__: T;
};

View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/json/types.ts"],"names":[],"mappings":""}

View File

@@ -0,0 +1 @@
export declare const findEndingQuote: (uint8: Uint8Array, x: number) => number;

22
node_modules/@jsonjoy.com/json-pack/lib/json/util.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findEndingQuote = void 0;
const findEndingQuote = (uint8, x) => {
const len = uint8.length;
let char = uint8[x];
let prev = 0;
while (x < len) {
if (char === 34 && prev !== 92)
break;
if (char === 92 && prev === 92)
prev = 0;
else
prev = char;
char = uint8[++x];
}
if (x === len)
throw new Error('Invalid JSON');
return x;
};
exports.findEndingQuote = findEndingQuote;
//# sourceMappingURL=util.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/json/util.ts"],"names":[],"mappings":";;;AAAO,MAAM,eAAe,GAAG,CAAC,KAAiB,EAAE,CAAS,EAAU,EAAE;IACtE,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACzB,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC;QACf,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE;YAAE,MAAM;QACtC,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE;YAAE,IAAI,GAAG,CAAC,CAAC;;YACpC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,CAAC,KAAK,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;IAC/C,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAZW,QAAA,eAAe,mBAY1B"}