@graphty/graph-io 0.3.18 → 0.3.20
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 +80 -2
- package/dist/chunks/{escape-D-gZWO26.js → escape-B-tkk_Cl.js} +74 -16
- package/dist/chunks/escape-B-tkk_Cl.js.map +1 -0
- package/dist/chunks/{writer-GAdltGmC.js → export-Bh60Dv-n.js} +7 -252
- package/dist/chunks/export-Bh60Dv-n.js.map +1 -0
- package/dist/chunks/exporter-BGrsWamJ.js +736 -0
- package/dist/chunks/exporter-BGrsWamJ.js.map +1 -0
- package/dist/chunks/exporter-DIeGJXAZ.js +834 -0
- package/dist/chunks/exporter-DIeGJXAZ.js.map +1 -0
- package/dist/chunks/{importer-Br_QeAeE.js → importer-BWY2FFc5.js} +28 -6
- package/dist/chunks/importer-BWY2FFc5.js.map +1 -0
- package/dist/chunks/importer-BaQpCEcJ.js +2194 -0
- package/dist/chunks/importer-BaQpCEcJ.js.map +1 -0
- package/dist/chunks/importer-DD-xv9_Y.js +1471 -0
- package/dist/chunks/importer-DD-xv9_Y.js.map +1 -0
- package/dist/chunks/{importer-aNJfe0qu.js → importer-DEcKhsmQ.js} +2 -2
- package/dist/chunks/{importer-aNJfe0qu.js.map → importer-DEcKhsmQ.js.map} +1 -1
- package/dist/chunks/{importer-DHagxvDD.js → importer-DIrbbnAf.js} +6 -4
- package/dist/chunks/{importer-DHagxvDD.js.map → importer-DIrbbnAf.js.map} +1 -1
- package/dist/chunks/importer-D_e7e7LX.js +3055 -0
- package/dist/chunks/importer-D_e7e7LX.js.map +1 -0
- package/dist/chunks/{importer-Du5crN9l.js → importer-Wv4C4gaF.js} +278 -82
- package/dist/chunks/importer-Wv4C4gaF.js.map +1 -0
- package/dist/chunks/importer-vi3bSdtw.js +1713 -0
- package/dist/chunks/importer-vi3bSdtw.js.map +1 -0
- package/dist/chunks/{importer-d0uQxFp6.js → importer-zGLo8Dg_.js} +6 -4
- package/dist/chunks/{importer-d0uQxFp6.js.map → importer-zGLo8Dg_.js.map} +1 -1
- package/dist/chunks/json-elements-DDS8N2Dd.js +779 -0
- package/dist/chunks/json-elements-DDS8N2Dd.js.map +1 -0
- package/dist/chunks/{records-Bk9jgodz.js → records-dbRkxwaq.js} +2 -2
- package/dist/chunks/{records-Bk9jgodz.js.map → records-dbRkxwaq.js.map} +1 -1
- package/dist/chunks/{report-BOk0p5y8.js → report-B1z4WT9e.js} +143 -111
- package/dist/chunks/{report-BOk0p5y8.js.map → report-B1z4WT9e.js.map} +1 -1
- package/dist/chunks/weights-Dzba96G3.js +176 -0
- package/dist/chunks/weights-Dzba96G3.js.map +1 -0
- package/dist/chunks/writer-C7flM-Ih.js +77 -0
- package/dist/chunks/writer-C7flM-Ih.js.map +1 -0
- package/dist/csv.js +6 -4
- package/dist/csv.js.map +1 -1
- package/dist/cx.d.ts +1 -0
- package/dist/cx.js +6 -0
- package/dist/cx.js.map +1 -0
- package/dist/cx2.d.ts +1 -0
- package/dist/cx2.js +10 -0
- package/dist/cx2.js.map +1 -0
- package/dist/cys.d.ts +1 -0
- package/dist/cys.js +6 -0
- package/dist/cys.js.map +1 -0
- package/dist/dot.js +1 -1
- package/dist/gexf.js +16 -4
- package/dist/gexf.js.map +1 -1
- package/dist/gml.js +13 -14
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +302 -399
- package/dist/graph-io.js.map +1 -1
- package/dist/graphml.js +1 -1
- package/dist/json.js +1 -1
- package/dist/neo4j.js +6 -4
- package/dist/neo4j.js.map +1 -1
- package/dist/obo.js +1 -1
- package/dist/pajek.js +1 -1
- package/dist/src/common/cell-budget.d.ts +84 -0
- package/dist/src/common/cell-budget.d.ts.map +1 -0
- package/dist/src/common/cell-budget.js +138 -0
- package/dist/src/common/cell-budget.js.map +1 -0
- package/dist/src/common/input.d.ts +10 -0
- package/dist/src/common/input.d.ts.map +1 -1
- package/dist/src/common/input.js +39 -0
- package/dist/src/common/input.js.map +1 -1
- package/dist/src/common/json-elements.d.ts +286 -0
- package/dist/src/common/json-elements.d.ts.map +1 -0
- package/dist/src/common/json-elements.js +926 -0
- package/dist/src/common/json-elements.js.map +1 -0
- package/dist/src/common/options.d.ts +6 -0
- package/dist/src/common/options.d.ts.map +1 -1
- package/dist/src/common/options.js +1 -1
- package/dist/src/common/options.js.map +1 -1
- package/dist/src/common/xml.d.ts +37 -3
- package/dist/src/common/xml.d.ts.map +1 -1
- package/dist/src/common/xml.js +86 -6
- package/dist/src/common/xml.js.map +1 -1
- package/dist/src/common/zip.d.ts +92 -0
- package/dist/src/common/zip.d.ts.map +1 -0
- package/dist/src/common/zip.js +399 -0
- package/dist/src/common/zip.js.map +1 -0
- package/dist/src/formats/cx/importer.d.ts +133 -0
- package/dist/src/formats/cx/importer.d.ts.map +1 -0
- package/dist/src/formats/cx/importer.js +2220 -0
- package/dist/src/formats/cx/importer.js.map +1 -0
- package/dist/src/formats/cx/index.d.ts +7 -0
- package/dist/src/formats/cx/index.d.ts.map +1 -0
- package/dist/src/formats/cx/index.js +7 -0
- package/dist/src/formats/cx/index.js.map +1 -0
- package/dist/src/formats/cx2/exporter.d.ts +59 -0
- package/dist/src/formats/cx2/exporter.d.ts.map +1 -0
- package/dist/src/formats/cx2/exporter.js +864 -0
- package/dist/src/formats/cx2/exporter.js.map +1 -0
- package/dist/src/formats/cx2/importer.d.ts +169 -0
- package/dist/src/formats/cx2/importer.d.ts.map +1 -0
- package/dist/src/formats/cx2/importer.js +1652 -0
- package/dist/src/formats/cx2/importer.js.map +1 -0
- package/dist/src/formats/cx2/index.d.ts +7 -0
- package/dist/src/formats/cx2/index.d.ts.map +1 -0
- package/dist/src/formats/cx2/index.js +7 -0
- package/dist/src/formats/cx2/index.js.map +1 -0
- package/dist/src/formats/cys/constants.d.ts +68 -0
- package/dist/src/formats/cys/constants.d.ts.map +1 -0
- package/dist/src/formats/cys/constants.js +76 -0
- package/dist/src/formats/cys/constants.js.map +1 -0
- package/dist/src/formats/cys/importer.d.ts +38 -0
- package/dist/src/formats/cys/importer.d.ts.map +1 -0
- package/dist/src/formats/cys/importer.js +830 -0
- package/dist/src/formats/cys/importer.js.map +1 -0
- package/dist/src/formats/cys/index.d.ts +7 -0
- package/dist/src/formats/cys/index.d.ts.map +1 -0
- package/dist/src/formats/cys/index.js +7 -0
- package/dist/src/formats/cys/index.js.map +1 -0
- package/dist/src/formats/cys/session.d.ts +132 -0
- package/dist/src/formats/cys/session.d.ts.map +1 -0
- package/dist/src/formats/cys/session.js +315 -0
- package/dist/src/formats/cys/session.js.map +1 -0
- package/dist/src/formats/cys/tables.d.ts +90 -0
- package/dist/src/formats/cys/tables.d.ts.map +1 -0
- package/dist/src/formats/cys/tables.js +293 -0
- package/dist/src/formats/cys/tables.js.map +1 -0
- package/dist/src/formats/dot/exporter.d.ts +2 -0
- package/dist/src/formats/dot/exporter.d.ts.map +1 -1
- package/dist/src/formats/dot/exporter.js +12 -0
- package/dist/src/formats/dot/exporter.js.map +1 -1
- package/dist/src/formats/dot/importer.js +6 -2
- package/dist/src/formats/dot/importer.js.map +1 -1
- package/dist/src/formats/gexf/exporter.d.ts +2 -0
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -1
- package/dist/src/formats/gexf/exporter.js +6 -0
- package/dist/src/formats/gexf/exporter.js.map +1 -1
- package/dist/src/formats/gexf/importer.d.ts +0 -2
- package/dist/src/formats/gexf/importer.d.ts.map +1 -1
- package/dist/src/formats/gexf/importer.js +1 -3
- package/dist/src/formats/gexf/importer.js.map +1 -1
- package/dist/src/formats/gexf/index.d.ts +1 -1
- package/dist/src/formats/gexf/index.js +2 -2
- package/dist/src/formats/gexf/index.js.map +1 -1
- package/dist/src/formats/gml/exporter.d.ts +0 -8
- package/dist/src/formats/gml/exporter.d.ts.map +1 -1
- package/dist/src/formats/gml/exporter.js +8 -18
- package/dist/src/formats/gml/exporter.js.map +1 -1
- package/dist/src/formats/json/importer.d.ts.map +1 -1
- package/dist/src/formats/json/importer.js +6 -104
- package/dist/src/formats/json/importer.js.map +1 -1
- package/dist/src/formats/xgmml/columns.d.ts +152 -0
- package/dist/src/formats/xgmml/columns.d.ts.map +1 -0
- package/dist/src/formats/xgmml/columns.js +593 -0
- package/dist/src/formats/xgmml/columns.js.map +1 -0
- package/dist/src/formats/xgmml/constants.d.ts +196 -0
- package/dist/src/formats/xgmml/constants.d.ts.map +1 -0
- package/dist/src/formats/xgmml/constants.js +197 -0
- package/dist/src/formats/xgmml/constants.js.map +1 -0
- package/dist/src/formats/xgmml/document.d.ts +361 -0
- package/dist/src/formats/xgmml/document.d.ts.map +1 -0
- package/dist/src/formats/xgmml/document.js +695 -0
- package/dist/src/formats/xgmml/document.js.map +1 -0
- package/dist/src/formats/xgmml/emit.d.ts +341 -0
- package/dist/src/formats/xgmml/emit.d.ts.map +1 -0
- package/dist/src/formats/xgmml/emit.js +1275 -0
- package/dist/src/formats/xgmml/emit.js.map +1 -0
- package/dist/src/formats/xgmml/exporter.d.ts +24 -0
- package/dist/src/formats/xgmml/exporter.d.ts.map +1 -0
- package/dist/src/formats/xgmml/exporter.js +999 -0
- package/dist/src/formats/xgmml/exporter.js.map +1 -0
- package/dist/src/formats/xgmml/importer.d.ts +58 -0
- package/dist/src/formats/xgmml/importer.d.ts.map +1 -0
- package/dist/src/formats/xgmml/importer.js +360 -0
- package/dist/src/formats/xgmml/importer.js.map +1 -0
- package/dist/src/formats/xgmml/index.d.ts +8 -0
- package/dist/src/formats/xgmml/index.d.ts.map +1 -0
- package/dist/src/formats/xgmml/index.js +8 -0
- package/dist/src/formats/xgmml/index.js.map +1 -0
- package/dist/src/formats/xgmml/values.d.ts +60 -0
- package/dist/src/formats/xgmml/values.d.ts.map +1 -0
- package/dist/src/formats/xgmml/values.js +148 -0
- package/dist/src/formats/xgmml/values.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/registry.d.ts +7 -0
- package/dist/src/registry.d.ts.map +1 -1
- package/dist/src/registry.js +30 -10
- package/dist/src/registry.js.map +1 -1
- package/dist/src/sniff.d.ts +1 -1
- package/dist/src/sniff.d.ts.map +1 -1
- package/dist/src/sniff.js +4 -0
- package/dist/src/sniff.js.map +1 -1
- package/dist/xgmml.d.ts +1 -0
- package/dist/xgmml.js +9 -0
- package/dist/xgmml.js.map +1 -0
- package/package.json +25 -2
- package/src/common/cell-budget.ts +170 -0
- package/src/common/input.ts +40 -0
- package/src/common/json-elements.ts +1147 -0
- package/src/common/options.ts +1 -1
- package/src/common/xml.ts +127 -6
- package/src/common/zip.ts +472 -0
- package/src/formats/cx/importer.ts +2733 -0
- package/src/formats/cx/index.ts +7 -0
- package/src/formats/cx2/exporter.ts +1036 -0
- package/src/formats/cx2/importer.ts +2187 -0
- package/src/formats/cx2/index.ts +7 -0
- package/src/formats/cys/constants.ts +99 -0
- package/src/formats/cys/importer.ts +1100 -0
- package/src/formats/cys/index.ts +7 -0
- package/src/formats/cys/session.ts +428 -0
- package/src/formats/cys/tables.ts +400 -0
- package/src/formats/dot/exporter.ts +17 -0
- package/src/formats/dot/importer.ts +6 -2
- package/src/formats/gexf/exporter.ts +11 -0
- package/src/formats/gexf/importer.ts +1 -2
- package/src/formats/gexf/index.ts +1 -1
- package/src/formats/gml/exporter.ts +8 -19
- package/src/formats/json/importer.ts +6 -105
- package/src/formats/xgmml/columns.ts +747 -0
- package/src/formats/xgmml/constants.ts +265 -0
- package/src/formats/xgmml/document.ts +975 -0
- package/src/formats/xgmml/emit.ts +1563 -0
- package/src/formats/xgmml/exporter.ts +1215 -0
- package/src/formats/xgmml/importer.ts +491 -0
- package/src/formats/xgmml/index.ts +8 -0
- package/src/formats/xgmml/values.ts +183 -0
- package/src/index.ts +19 -0
- package/src/registry.ts +46 -15
- package/src/sniff.ts +18 -1
- package/dist/chunks/escape-D-gZWO26.js.map +0 -1
- package/dist/chunks/importer-Br_QeAeE.js.map +0 -1
- package/dist/chunks/importer-Du5crN9l.js.map +0 -1
- package/dist/chunks/writer-GAdltGmC.js.map +0 -1
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
import { DirectionResolver, type EdgeKind } from "../../common/direction.js";
|
|
67
67
|
import { ID_MERGED_CODE, IdCoercer } from "../../common/ids.js";
|
|
68
68
|
import { readText, textChunks, throwIfAborted } from "../../common/input.js";
|
|
69
|
+
import { MAYBE_UNSAFE_INTEGER, reviveNonstandard, rewriteNumbers } from "../../common/json-elements.js";
|
|
69
70
|
import {
|
|
70
71
|
chooseGraph,
|
|
71
72
|
type ImportFormatDefaults,
|
|
@@ -77,6 +78,7 @@ import {
|
|
|
77
78
|
} from "../../common/options.js";
|
|
78
79
|
import { ImportReportBuilder } from "../../common/report.js";
|
|
79
80
|
import { weightFromValue } from "../../common/weights.js";
|
|
81
|
+
import { sniffJsonDialectHead } from "../../sniff.js";
|
|
80
82
|
import {
|
|
81
83
|
type CommonImportOptions,
|
|
82
84
|
type GraphChoiceOptions,
|
|
@@ -1272,113 +1274,9 @@ function parseDocument(text: string, report: ImportReportBuilder): unknown {
|
|
|
1272
1274
|
return root;
|
|
1273
1275
|
}
|
|
1274
1276
|
|
|
1275
|
-
/** A run of 16 digits not inside a fraction: the shortest integer literal that can exceed 2^53 (9007199254740992). */
|
|
1276
|
-
const MAYBE_UNSAFE_INTEGER = /(?<![0-9.])[0-9]{16}/;
|
|
1277
|
-
|
|
1278
1277
|
/** How many of the integers kept as text the warning lists. */
|
|
1279
1278
|
const BIG_INTEGERS_SHOWN = 10;
|
|
1280
1279
|
|
|
1281
|
-
/**
|
|
1282
|
-
* The prefix of the string a non-standard token is rewritten to (a NUL character first, which no
|
|
1283
|
-
* sensible attribute value starts with); reviveNonstandard() turns it back into the number.
|
|
1284
|
-
*/
|
|
1285
|
-
const NONSTANDARD_SENTINEL = `${String.fromCharCode(0)}graph-io:`;
|
|
1286
|
-
|
|
1287
|
-
/** The non-standard tokens Python's json module writes, longest first so -Infinity wins over a bare minus. */
|
|
1288
|
-
const NONSTANDARD_TOKENS: readonly (readonly [string, number])[] = [
|
|
1289
|
-
["-Infinity", -Infinity],
|
|
1290
|
-
["Infinity", Infinity],
|
|
1291
|
-
["NaN", NaN],
|
|
1292
|
-
];
|
|
1293
|
-
|
|
1294
|
-
/** A JSON integer literal (no fraction, no exponent, no leading zero), as CANONICAL_INTEGER in common/ids.ts. */
|
|
1295
|
-
const INTEGER_LITERAL = /^-?(0|[1-9][0-9]*)$/;
|
|
1296
|
-
|
|
1297
|
-
/**
|
|
1298
|
-
* Rewrite the numbers JSON.parse cannot read exactly, outside strings and in value positions only:
|
|
1299
|
-
* NaN / Infinity / -Infinity become sentinel strings, an integer literal that is not a safe
|
|
1300
|
-
* integer becomes a string of its digits. A container stack tells a value position (after `:`,
|
|
1301
|
-
* `[`, or `,` inside an array) from a key position, so `{NaN: 1}` stays invalid.
|
|
1302
|
-
* @param text - the document text
|
|
1303
|
-
* @returns the rewritten text, the non-standard tokens seen and the integer literals quoted
|
|
1304
|
-
*/
|
|
1305
|
-
function rewriteNumbers(text: string): { text: string; tokens: Set<string>; bigIntegers: string[] } {
|
|
1306
|
-
const parts: string[] = [];
|
|
1307
|
-
const tokens = new Set<string>();
|
|
1308
|
-
const bigIntegers: string[] = [];
|
|
1309
|
-
const arrays: boolean[] = [];
|
|
1310
|
-
let expectValue = true;
|
|
1311
|
-
let copied = 0;
|
|
1312
|
-
let i = 0;
|
|
1313
|
-
const n = text.length;
|
|
1314
|
-
while (i < n) {
|
|
1315
|
-
const ch = text[i];
|
|
1316
|
-
if (ch === '"') {
|
|
1317
|
-
i++;
|
|
1318
|
-
while (i < n && text[i] !== '"') {
|
|
1319
|
-
i += text[i] === "\\" ? 2 : 1;
|
|
1320
|
-
}
|
|
1321
|
-
i++;
|
|
1322
|
-
expectValue = false;
|
|
1323
|
-
continue;
|
|
1324
|
-
}
|
|
1325
|
-
if (ch === "{" || ch === "[") {
|
|
1326
|
-
arrays.push(ch === "[");
|
|
1327
|
-
expectValue = ch === "[";
|
|
1328
|
-
} else if (ch === "}" || ch === "]") {
|
|
1329
|
-
arrays.pop();
|
|
1330
|
-
expectValue = false;
|
|
1331
|
-
} else if (ch === ":") {
|
|
1332
|
-
expectValue = true;
|
|
1333
|
-
} else if (ch === ",") {
|
|
1334
|
-
expectValue = arrays.length > 0 && arrays[arrays.length - 1];
|
|
1335
|
-
} else if (expectValue && ch !== " " && ch !== "\t" && ch !== "\n" && ch !== "\r") {
|
|
1336
|
-
expectValue = false;
|
|
1337
|
-
const token = NONSTANDARD_TOKENS.find(([word]) => text.startsWith(word, i));
|
|
1338
|
-
let end = i;
|
|
1339
|
-
let replacement: string | null = null;
|
|
1340
|
-
if (token !== undefined) {
|
|
1341
|
-
end = i + token[0].length;
|
|
1342
|
-
tokens.add(token[0]);
|
|
1343
|
-
replacement = JSON.stringify(`${NONSTANDARD_SENTINEL}${token[0]}`);
|
|
1344
|
-
} else if (ch === "-" || (ch >= "0" && ch <= "9")) {
|
|
1345
|
-
end = i + 1;
|
|
1346
|
-
while (end < n && "0123456789+-.eE".includes(text[end])) {
|
|
1347
|
-
end++;
|
|
1348
|
-
}
|
|
1349
|
-
const literal = text.slice(i, end);
|
|
1350
|
-
if (INTEGER_LITERAL.test(literal) && !Number.isSafeInteger(Number(literal))) {
|
|
1351
|
-
bigIntegers.push(literal);
|
|
1352
|
-
replacement = `"${literal}"`;
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
if (replacement !== null) {
|
|
1356
|
-
parts.push(text.slice(copied, i), replacement);
|
|
1357
|
-
copied = end;
|
|
1358
|
-
}
|
|
1359
|
-
i = Math.max(end, i + 1);
|
|
1360
|
-
continue;
|
|
1361
|
-
}
|
|
1362
|
-
i++;
|
|
1363
|
-
}
|
|
1364
|
-
parts.push(text.slice(copied));
|
|
1365
|
-
return { text: parts.join(""), tokens, bigIntegers };
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
/**
|
|
1369
|
-
* The JSON.parse reviver that turns the sentinel strings of rewriteNumbers() back into numbers.
|
|
1370
|
-
* @param _key - the member key (unused)
|
|
1371
|
-
* @param value - the parsed value
|
|
1372
|
-
* @returns the number for a sentinel string, the value otherwise
|
|
1373
|
-
*/
|
|
1374
|
-
function reviveNonstandard(_key: string, value: unknown): unknown {
|
|
1375
|
-
if (typeof value === "string" && value.startsWith(NONSTANDARD_SENTINEL)) {
|
|
1376
|
-
const found = NONSTANDARD_TOKENS.find(([word]) => word === value.slice(NONSTANDARD_SENTINEL.length));
|
|
1377
|
-
return found === undefined ? value : found[1];
|
|
1378
|
-
}
|
|
1379
|
-
return value;
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
1280
|
/**
|
|
1383
1281
|
* The dialect to read: the forced one, else the shape rule of sniffJsonDialect(); a document
|
|
1384
1282
|
* that matches no dialect is a fatal E_JSON_DIALECT.
|
|
@@ -2979,7 +2877,10 @@ export const jsonImporter: GraphImporter<JsonImportOptions> = Object.freeze({
|
|
|
2979
2877
|
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
|
|
2980
2878
|
return 0;
|
|
2981
2879
|
}
|
|
2982
|
-
|
|
2880
|
+
const score = SNIFF_KEYS.some((key) => trimmed.includes(key)) ? 0.9 : 0.5;
|
|
2881
|
+
// a top-level array is a graph only as Cytoscape.js elements (`[{"data": ...}]`): a CX or
|
|
2882
|
+
// CX2 document (`[{"metaData": ...}]`, `[{"CXVersion": ...}]`) is another format's
|
|
2883
|
+
return trimmed.startsWith("[") && sniffJsonDialectHead(trimmed) !== "cytoscape" ? Math.min(score, 0.3) : score;
|
|
2983
2884
|
},
|
|
2984
2885
|
|
|
2985
2886
|
/**
|