@graphty/graph-io 0.0.0 → 0.2.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/LICENSE +21 -0
- package/README.md +250 -28
- package/dist/chunks/children-CL3Cy0ez.js +238 -0
- package/dist/chunks/children-CL3Cy0ez.js.map +1 -0
- package/dist/chunks/escape-DyI8JofU.js +938 -0
- package/dist/chunks/escape-DyI8JofU.js.map +1 -0
- package/dist/chunks/importer-CQnJuWJw.js +2987 -0
- package/dist/chunks/importer-CQnJuWJw.js.map +1 -0
- package/dist/chunks/importer-CpCpfbxr.js +2015 -0
- package/dist/chunks/importer-CpCpfbxr.js.map +1 -0
- package/dist/chunks/importer-DbnGYr3_.js +2342 -0
- package/dist/chunks/importer-DbnGYr3_.js.map +1 -0
- package/dist/chunks/importer-GozH8DkN.js +3050 -0
- package/dist/chunks/importer-GozH8DkN.js.map +1 -0
- package/dist/chunks/records-CGpxszm1.js +605 -0
- package/dist/chunks/records-CGpxszm1.js.map +1 -0
- package/dist/chunks/text-CajMdVFy.js +189 -0
- package/dist/chunks/text-CajMdVFy.js.map +1 -0
- package/dist/chunks/writer-DxSKC7TL.js +2842 -0
- package/dist/chunks/writer-DxSKC7TL.js.map +1 -0
- package/dist/csv.d.ts +1 -0
- package/dist/csv.js +1702 -0
- package/dist/csv.js.map +1 -0
- package/dist/dot.d.ts +1 -0
- package/dist/dot.js +8 -0
- package/dist/dot.js.map +1 -0
- package/dist/gexf.d.ts +1 -0
- package/dist/gexf.js +3466 -0
- package/dist/gexf.js.map +1 -0
- package/dist/gml.d.ts +1 -0
- package/dist/gml.js +2647 -0
- package/dist/gml.js.map +1 -0
- package/dist/graph-io.d.ts +1 -0
- package/dist/graph-io.js +790 -0
- package/dist/graph-io.js.map +1 -0
- package/dist/graphml.d.ts +1 -0
- package/dist/graphml.js +8 -0
- package/dist/graphml.js.map +1 -0
- package/dist/json.d.ts +1 -0
- package/dist/json.js +11 -0
- package/dist/json.js.map +1 -0
- package/dist/neo4j.d.ts +1 -0
- package/dist/neo4j.js +2046 -0
- package/dist/neo4j.js.map +1 -0
- package/dist/pajek.d.ts +1 -0
- package/dist/pajek.js +8 -0
- package/dist/pajek.js.map +1 -0
- package/dist/src/children.d.ts +134 -0
- package/dist/src/children.d.ts.map +1 -0
- package/dist/src/children.js +274 -0
- package/dist/src/children.js.map +1 -0
- package/dist/src/common/attributes.d.ts +229 -0
- package/dist/src/common/attributes.d.ts.map +1 -0
- package/dist/src/common/attributes.js +368 -0
- package/dist/src/common/attributes.js.map +1 -0
- package/dist/src/common/codes.d.ts +105 -0
- package/dist/src/common/codes.d.ts.map +1 -0
- package/dist/src/common/codes.js +107 -0
- package/dist/src/common/codes.js.map +1 -0
- package/dist/src/common/declared-types.d.ts +84 -0
- package/dist/src/common/declared-types.d.ts.map +1 -0
- package/dist/src/common/declared-types.js +326 -0
- package/dist/src/common/declared-types.js.map +1 -0
- package/dist/src/common/direction.d.ts +206 -0
- package/dist/src/common/direction.d.ts.map +1 -0
- package/dist/src/common/direction.js +370 -0
- package/dist/src/common/direction.js.map +1 -0
- package/dist/src/common/escape.d.ts +92 -0
- package/dist/src/common/escape.d.ts.map +1 -0
- package/dist/src/common/escape.js +212 -0
- package/dist/src/common/escape.js.map +1 -0
- package/dist/src/common/export.d.ts +249 -0
- package/dist/src/common/export.d.ts.map +1 -0
- package/dist/src/common/export.js +594 -0
- package/dist/src/common/export.js.map +1 -0
- package/dist/src/common/format.d.ts +59 -0
- package/dist/src/common/format.d.ts.map +1 -0
- package/dist/src/common/format.js +106 -0
- package/dist/src/common/format.js.map +1 -0
- package/dist/src/common/ids.d.ts +83 -0
- package/dist/src/common/ids.d.ts.map +1 -0
- package/dist/src/common/ids.js +158 -0
- package/dist/src/common/ids.js.map +1 -0
- package/dist/src/common/input.d.ts +100 -0
- package/dist/src/common/input.d.ts.map +1 -0
- package/dist/src/common/input.js +335 -0
- package/dist/src/common/input.js.map +1 -0
- package/dist/src/common/lists.d.ts +34 -0
- package/dist/src/common/lists.d.ts.map +1 -0
- package/dist/src/common/lists.js +185 -0
- package/dist/src/common/lists.js.map +1 -0
- package/dist/src/common/options.d.ts +108 -0
- package/dist/src/common/options.d.ts.map +1 -0
- package/dist/src/common/options.js +265 -0
- package/dist/src/common/options.js.map +1 -0
- package/dist/src/common/report.d.ts +187 -0
- package/dist/src/common/report.d.ts.map +1 -0
- package/dist/src/common/report.js +274 -0
- package/dist/src/common/report.js.map +1 -0
- package/dist/src/common/temporal.d.ts +71 -0
- package/dist/src/common/temporal.d.ts.map +1 -0
- package/dist/src/common/temporal.js +266 -0
- package/dist/src/common/temporal.js.map +1 -0
- package/dist/src/common/text.d.ts +104 -0
- package/dist/src/common/text.d.ts.map +1 -0
- package/dist/src/common/text.js +255 -0
- package/dist/src/common/text.js.map +1 -0
- package/dist/src/common/weights.d.ts +77 -0
- package/dist/src/common/weights.d.ts.map +1 -0
- package/dist/src/common/weights.js +156 -0
- package/dist/src/common/weights.js.map +1 -0
- package/dist/src/common/writer.d.ts +51 -0
- package/dist/src/common/writer.d.ts.map +1 -0
- package/dist/src/common/writer.js +108 -0
- package/dist/src/common/writer.js.map +1 -0
- package/dist/src/common/xml.d.ts +245 -0
- package/dist/src/common/xml.d.ts.map +1 -0
- package/dist/src/common/xml.js +942 -0
- package/dist/src/common/xml.js.map +1 -0
- package/dist/src/formats/csv/exporter.d.ts +70 -0
- package/dist/src/formats/csv/exporter.d.ts.map +1 -0
- package/dist/src/formats/csv/exporter.js +682 -0
- package/dist/src/formats/csv/exporter.js.map +1 -0
- package/dist/src/formats/csv/header.d.ts +66 -0
- package/dist/src/formats/csv/header.d.ts.map +1 -0
- package/dist/src/formats/csv/header.js +152 -0
- package/dist/src/formats/csv/header.js.map +1 -0
- package/dist/src/formats/csv/importer.d.ts +82 -0
- package/dist/src/formats/csv/importer.d.ts.map +1 -0
- package/dist/src/formats/csv/importer.js +849 -0
- package/dist/src/formats/csv/importer.js.map +1 -0
- package/dist/src/formats/csv/index.d.ts +60 -0
- package/dist/src/formats/csv/index.d.ts.map +1 -0
- package/dist/src/formats/csv/index.js +63 -0
- package/dist/src/formats/csv/index.js.map +1 -0
- package/dist/src/formats/csv/records.d.ts +188 -0
- package/dist/src/formats/csv/records.d.ts.map +1 -0
- package/dist/src/formats/csv/records.js +702 -0
- package/dist/src/formats/csv/records.js.map +1 -0
- package/dist/src/formats/csv/values.d.ts +105 -0
- package/dist/src/formats/csv/values.d.ts.map +1 -0
- package/dist/src/formats/csv/values.js +192 -0
- package/dist/src/formats/csv/values.js.map +1 -0
- package/dist/src/formats/dot/exporter.d.ts +52 -0
- package/dist/src/formats/dot/exporter.d.ts.map +1 -0
- package/dist/src/formats/dot/exporter.js +836 -0
- package/dist/src/formats/dot/exporter.js.map +1 -0
- package/dist/src/formats/dot/importer.d.ts +102 -0
- package/dist/src/formats/dot/importer.d.ts.map +1 -0
- package/dist/src/formats/dot/importer.js +1291 -0
- package/dist/src/formats/dot/importer.js.map +1 -0
- package/dist/src/formats/dot/index.d.ts +7 -0
- package/dist/src/formats/dot/index.d.ts.map +1 -0
- package/dist/src/formats/dot/index.js +7 -0
- package/dist/src/formats/dot/index.js.map +1 -0
- package/dist/src/formats/dot/names.d.ts +29 -0
- package/dist/src/formats/dot/names.d.ts.map +1 -0
- package/dist/src/formats/dot/names.js +28 -0
- package/dist/src/formats/dot/names.js.map +1 -0
- package/dist/src/formats/dot/tokenizer.d.ts +114 -0
- package/dist/src/formats/dot/tokenizer.d.ts.map +1 -0
- package/dist/src/formats/dot/tokenizer.js +341 -0
- package/dist/src/formats/dot/tokenizer.js.map +1 -0
- package/dist/src/formats/gexf/exporter.d.ts +56 -0
- package/dist/src/formats/gexf/exporter.d.ts.map +1 -0
- package/dist/src/formats/gexf/exporter.js +1395 -0
- package/dist/src/formats/gexf/exporter.js.map +1 -0
- package/dist/src/formats/gexf/importer.d.ts +73 -0
- package/dist/src/formats/gexf/importer.d.ts.map +1 -0
- package/dist/src/formats/gexf/importer.js +1880 -0
- package/dist/src/formats/gexf/importer.js.map +1 -0
- package/dist/src/formats/gexf/index.d.ts +96 -0
- package/dist/src/formats/gexf/index.d.ts.map +1 -0
- package/dist/src/formats/gexf/index.js +97 -0
- package/dist/src/formats/gexf/index.js.map +1 -0
- package/dist/src/formats/gexf/schema.d.ts +135 -0
- package/dist/src/formats/gexf/schema.d.ts.map +1 -0
- package/dist/src/formats/gexf/schema.js +323 -0
- package/dist/src/formats/gexf/schema.js.map +1 -0
- package/dist/src/formats/gml/exporter.d.ts +69 -0
- package/dist/src/formats/gml/exporter.d.ts.map +1 -0
- package/dist/src/formats/gml/exporter.js +1093 -0
- package/dist/src/formats/gml/exporter.js.map +1 -0
- package/dist/src/formats/gml/importer.d.ts +66 -0
- package/dist/src/formats/gml/importer.d.ts.map +1 -0
- package/dist/src/formats/gml/importer.js +1331 -0
- package/dist/src/formats/gml/importer.js.map +1 -0
- package/dist/src/formats/gml/index.d.ts +85 -0
- package/dist/src/formats/gml/index.d.ts.map +1 -0
- package/dist/src/formats/gml/index.js +88 -0
- package/dist/src/formats/gml/index.js.map +1 -0
- package/dist/src/formats/gml/syntax.d.ts +186 -0
- package/dist/src/formats/gml/syntax.d.ts.map +1 -0
- package/dist/src/formats/gml/syntax.js +467 -0
- package/dist/src/formats/gml/syntax.js.map +1 -0
- package/dist/src/formats/graphml/constants.d.ts +169 -0
- package/dist/src/formats/graphml/constants.d.ts.map +1 -0
- package/dist/src/formats/graphml/constants.js +165 -0
- package/dist/src/formats/graphml/constants.js.map +1 -0
- package/dist/src/formats/graphml/exporter.d.ts +34 -0
- package/dist/src/formats/graphml/exporter.d.ts.map +1 -0
- package/dist/src/formats/graphml/exporter.js +1176 -0
- package/dist/src/formats/graphml/exporter.js.map +1 -0
- package/dist/src/formats/graphml/importer.d.ts +31 -0
- package/dist/src/formats/graphml/importer.d.ts.map +1 -0
- package/dist/src/formats/graphml/importer.js +1607 -0
- package/dist/src/formats/graphml/importer.js.map +1 -0
- package/dist/src/formats/graphml/index.d.ts +8 -0
- package/dist/src/formats/graphml/index.d.ts.map +1 -0
- package/dist/src/formats/graphml/index.js +8 -0
- package/dist/src/formats/graphml/index.js.map +1 -0
- package/dist/src/formats/graphml/tree.d.ts +72 -0
- package/dist/src/formats/graphml/tree.d.ts.map +1 -0
- package/dist/src/formats/graphml/tree.js +290 -0
- package/dist/src/formats/graphml/tree.js.map +1 -0
- package/dist/src/formats/json/dialect.d.ts +125 -0
- package/dist/src/formats/json/dialect.d.ts.map +1 -0
- package/dist/src/formats/json/dialect.js +262 -0
- package/dist/src/formats/json/dialect.js.map +1 -0
- package/dist/src/formats/json/exporter.d.ts +89 -0
- package/dist/src/formats/json/exporter.d.ts.map +1 -0
- package/dist/src/formats/json/exporter.js +1358 -0
- package/dist/src/formats/json/exporter.js.map +1 -0
- package/dist/src/formats/json/importer.d.ts +108 -0
- package/dist/src/formats/json/importer.d.ts.map +1 -0
- package/dist/src/formats/json/importer.js +1838 -0
- package/dist/src/formats/json/importer.js.map +1 -0
- package/dist/src/formats/json/index.d.ts +8 -0
- package/dist/src/formats/json/index.d.ts.map +1 -0
- package/dist/src/formats/json/index.js +8 -0
- package/dist/src/formats/json/index.js.map +1 -0
- package/dist/src/formats/neo4j/exporter.d.ts +68 -0
- package/dist/src/formats/neo4j/exporter.d.ts.map +1 -0
- package/dist/src/formats/neo4j/exporter.js +1055 -0
- package/dist/src/formats/neo4j/exporter.js.map +1 -0
- package/dist/src/formats/neo4j/header.d.ts +52 -0
- package/dist/src/formats/neo4j/header.d.ts.map +1 -0
- package/dist/src/formats/neo4j/header.js +131 -0
- package/dist/src/formats/neo4j/header.js.map +1 -0
- package/dist/src/formats/neo4j/importer.d.ts +73 -0
- package/dist/src/formats/neo4j/importer.d.ts.map +1 -0
- package/dist/src/formats/neo4j/importer.js +932 -0
- package/dist/src/formats/neo4j/importer.js.map +1 -0
- package/dist/src/formats/neo4j/index.d.ts +79 -0
- package/dist/src/formats/neo4j/index.d.ts.map +1 -0
- package/dist/src/formats/neo4j/index.js +83 -0
- package/dist/src/formats/neo4j/index.js.map +1 -0
- package/dist/src/formats/pajek/exporter.d.ts +58 -0
- package/dist/src/formats/pajek/exporter.d.ts.map +1 -0
- package/dist/src/formats/pajek/exporter.js +825 -0
- package/dist/src/formats/pajek/exporter.js.map +1 -0
- package/dist/src/formats/pajek/importer.d.ts +88 -0
- package/dist/src/formats/pajek/importer.d.ts.map +1 -0
- package/dist/src/formats/pajek/importer.js +1047 -0
- package/dist/src/formats/pajek/importer.js.map +1 -0
- package/dist/src/formats/pajek/index.d.ts +7 -0
- package/dist/src/formats/pajek/index.d.ts.map +1 -0
- package/dist/src/formats/pajek/index.js +7 -0
- package/dist/src/formats/pajek/index.js.map +1 -0
- package/dist/src/formats/pajek/syntax.d.ts +112 -0
- package/dist/src/formats/pajek/syntax.d.ts.map +1 -0
- package/dist/src/formats/pajek/syntax.js +269 -0
- package/dist/src/formats/pajek/syntax.js.map +1 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +39 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/registry.d.ts +207 -0
- package/dist/src/registry.d.ts.map +1 -0
- package/dist/src/registry.js +481 -0
- package/dist/src/registry.js.map +1 -0
- package/dist/src/sniff.d.ts +104 -0
- package/dist/src/sniff.d.ts.map +1 -0
- package/dist/src/sniff.js +357 -0
- package/dist/src/sniff.js.map +1 -0
- package/dist/src/types.d.ts +238 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +29 -0
- package/dist/src/types.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +122 -7
- package/src/children.ts +335 -0
- package/src/common/attributes.ts +520 -0
- package/src/common/codes.ts +153 -0
- package/src/common/declared-types.ts +374 -0
- package/src/common/direction.ts +518 -0
- package/src/common/escape.ts +231 -0
- package/src/common/export.ts +817 -0
- package/src/common/format.ts +111 -0
- package/src/common/ids.ts +176 -0
- package/src/common/input.ts +378 -0
- package/src/common/lists.ts +196 -0
- package/src/common/options.ts +377 -0
- package/src/common/report.ts +352 -0
- package/src/common/temporal.ts +302 -0
- package/src/common/text.ts +294 -0
- package/src/common/weights.ts +202 -0
- package/src/common/writer.ts +123 -0
- package/src/common/xml.ts +1053 -0
- package/src/formats/csv/exporter.ts +894 -0
- package/src/formats/csv/header.ts +172 -0
- package/src/formats/csv/importer.ts +1104 -0
- package/src/formats/csv/index.ts +88 -0
- package/src/formats/csv/records.ts +813 -0
- package/src/formats/csv/values.ts +224 -0
- package/src/formats/dot/exporter.ts +1014 -0
- package/src/formats/dot/importer.ts +1549 -0
- package/src/formats/dot/index.ts +7 -0
- package/src/formats/dot/names.ts +40 -0
- package/src/formats/dot/tokenizer.ts +384 -0
- package/src/formats/gexf/exporter.ts +1696 -0
- package/src/formats/gexf/importer.ts +2333 -0
- package/src/formats/gexf/index.ts +142 -0
- package/src/formats/gexf/schema.ts +361 -0
- package/src/formats/gml/exporter.ts +1404 -0
- package/src/formats/gml/importer.ts +1591 -0
- package/src/formats/gml/index.ts +128 -0
- package/src/formats/gml/syntax.ts +545 -0
- package/src/formats/graphml/constants.ts +225 -0
- package/src/formats/graphml/exporter.ts +1458 -0
- package/src/formats/graphml/importer.ts +2027 -0
- package/src/formats/graphml/index.ts +8 -0
- package/src/formats/graphml/tree.ts +318 -0
- package/src/formats/json/dialect.ts +317 -0
- package/src/formats/json/exporter.ts +1616 -0
- package/src/formats/json/importer.ts +2271 -0
- package/src/formats/json/index.ts +8 -0
- package/src/formats/neo4j/exporter.ts +1287 -0
- package/src/formats/neo4j/header.ts +156 -0
- package/src/formats/neo4j/importer.ts +1220 -0
- package/src/formats/neo4j/index.ts +116 -0
- package/src/formats/pajek/exporter.ts +1000 -0
- package/src/formats/pajek/importer.ts +1311 -0
- package/src/formats/pajek/index.ts +7 -0
- package/src/formats/pajek/syntax.ts +307 -0
- package/src/index.ts +244 -0
- package/src/registry.ts +617 -0
- package/src/sniff.ts +397 -0
- package/src/types.ts +262 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Id, label and value escaping for the text formats (design section 8.5), one function per
|
|
3
|
+
* syntax, with the inverse where the importer needs it: XML attribute and element text (GEXF,
|
|
4
|
+
* GraphML), GML quoted strings (`"` and `&` and non-ASCII as `&#NN;` character entities, the
|
|
5
|
+
* NetworkX convention), DOT ids (bare when the grammar allows, quoted with `\"` otherwise), RFC
|
|
6
|
+
* 4180 CSV cells and Pajek labels.
|
|
7
|
+
*/
|
|
8
|
+
import { GraphFormatError } from "@graphty/graph-format";
|
|
9
|
+
import { hasIllegalXmlChar } from "./xml.js";
|
|
10
|
+
const XML_TEXT_SPECIAL = /[&<>\r]/g;
|
|
11
|
+
const XML_ATTR_SPECIAL = /[&<>"\t\n\r]/g;
|
|
12
|
+
const XML_REPLACEMENTS = {
|
|
13
|
+
"&": "&",
|
|
14
|
+
"<": "<",
|
|
15
|
+
">": ">",
|
|
16
|
+
'"': """,
|
|
17
|
+
"\t": "	",
|
|
18
|
+
"\n": " ",
|
|
19
|
+
"\r": " ",
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Escape text for an XML element body: `&`, `<`, `>` and a carriage return (which XML
|
|
23
|
+
* end-of-line handling would turn into a line feed on every read) as character references. A
|
|
24
|
+
* character XML 1.0 forbids (a C0 control other than tab / LF / CR, U+FFFE, U+FFFF, a lone
|
|
25
|
+
* surrogate) has no XML spelling at all and is E_COLUMN_TYPE; the exporters' check() counts them.
|
|
26
|
+
* @param text - the text
|
|
27
|
+
* @returns the escaped text
|
|
28
|
+
*/
|
|
29
|
+
export function escapeXmlText(text) {
|
|
30
|
+
if (hasIllegalXmlChar(text)) {
|
|
31
|
+
throw illegalXml(text);
|
|
32
|
+
}
|
|
33
|
+
return text.replace(XML_TEXT_SPECIAL, (c) => XML_REPLACEMENTS[c]);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Escape text for a double-quoted XML attribute value: `&`, `<`, `>`, `"` and the whitespace
|
|
37
|
+
* characters attribute normalisation would fold; a character XML 1.0 forbids is E_COLUMN_TYPE.
|
|
38
|
+
* @param text - the text
|
|
39
|
+
* @returns the escaped text
|
|
40
|
+
*/
|
|
41
|
+
export function escapeXmlAttribute(text) {
|
|
42
|
+
if (hasIllegalXmlChar(text)) {
|
|
43
|
+
throw illegalXml(text);
|
|
44
|
+
}
|
|
45
|
+
return text.replace(XML_ATTR_SPECIAL, (c) => XML_REPLACEMENTS[c]);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The error of a text no XML 1.0 document can carry.
|
|
49
|
+
* @param text - the text
|
|
50
|
+
* @returns the error
|
|
51
|
+
*/
|
|
52
|
+
function illegalXml(text) {
|
|
53
|
+
return new GraphFormatError("E_COLUMN_TYPE", "the text holds a character XML 1.0 cannot carry", {
|
|
54
|
+
reason: "xml illegal char",
|
|
55
|
+
length: text.length,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const GML_SPECIAL = /["&]|[^ -~]/gu;
|
|
59
|
+
/**
|
|
60
|
+
* Quote a GML string value: double quotes around the text with `"`, `&` and every character
|
|
61
|
+
* outside printable ASCII written as `&#NN;` (NetworkX's writer convention, which its reader and
|
|
62
|
+
* Gephi's decode).
|
|
63
|
+
* A lone surrogate cannot be written and is E_COLUMN_TYPE.
|
|
64
|
+
* @param text - the text
|
|
65
|
+
* @returns the quoted GML string
|
|
66
|
+
*/
|
|
67
|
+
export function quoteGmlString(text) {
|
|
68
|
+
const escaped = text.replace(GML_SPECIAL, (c) => {
|
|
69
|
+
const code = c.codePointAt(0);
|
|
70
|
+
if (code === undefined) {
|
|
71
|
+
return c;
|
|
72
|
+
}
|
|
73
|
+
if (code >= 0xd800 && code <= 0xdfff) {
|
|
74
|
+
throw new GraphFormatError("E_COLUMN_TYPE", "a lone surrogate cannot be written as a GML string", {
|
|
75
|
+
reason: "lone surrogate",
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return `&#${code};`;
|
|
79
|
+
});
|
|
80
|
+
return `"${escaped}"`;
|
|
81
|
+
}
|
|
82
|
+
const GML_ENTITY = /&(#[0-9]+|#x[0-9a-fA-F]+|amp|quot|lt|gt|apos);/g;
|
|
83
|
+
const GML_NAMED = { amp: "&", quot: '"', lt: "<", gt: ">", apos: "'" };
|
|
84
|
+
/**
|
|
85
|
+
* Decode the character entities of a GML string body (the inverse of quoteGmlString on the text
|
|
86
|
+
* between the quotes). An unknown entity is left as written.
|
|
87
|
+
* @param body - the text between the quotes
|
|
88
|
+
* @returns the decoded text
|
|
89
|
+
*/
|
|
90
|
+
export function decodeGmlString(body) {
|
|
91
|
+
return body.replace(GML_ENTITY, (whole, entity) => {
|
|
92
|
+
if (entity.startsWith("#x")) {
|
|
93
|
+
return String.fromCodePoint(Number.parseInt(entity.slice(2), 16));
|
|
94
|
+
}
|
|
95
|
+
if (entity.startsWith("#")) {
|
|
96
|
+
return String.fromCodePoint(Number.parseInt(entity.slice(1), 10));
|
|
97
|
+
}
|
|
98
|
+
return GML_NAMED[entity] ?? whole;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
const DOT_NUMERAL = /^-?(\.[0-9]+|[0-9]+(\.[0-9]*)?)$/;
|
|
102
|
+
const DOT_KEYWORDS = new Set(["node", "edge", "graph", "digraph", "subgraph", "strict"]);
|
|
103
|
+
/**
|
|
104
|
+
* Whether a text is a DOT ID that needs no quotes: an alphanumeric identifier not starting with
|
|
105
|
+
* a digit, or a numeral, and not a keyword (case-insensitive).
|
|
106
|
+
* @param text - the text
|
|
107
|
+
* @returns true when the text can be written bare
|
|
108
|
+
*/
|
|
109
|
+
export function isBareDotId(text) {
|
|
110
|
+
if (DOT_KEYWORDS.has(text.toLowerCase())) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
return isDotIdentifier(text) || DOT_NUMERAL.test(text);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Whether a text is a DOT identifier: a letter, underscore or any character of code 128 and
|
|
117
|
+
* above, followed by letters, digits, underscores or such characters.
|
|
118
|
+
* @param text - the text
|
|
119
|
+
* @returns true for a bare identifier
|
|
120
|
+
*/
|
|
121
|
+
function isDotIdentifier(text) {
|
|
122
|
+
if (text.length === 0) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
for (let i = 0; i < text.length; i++) {
|
|
126
|
+
const c = text.charCodeAt(i);
|
|
127
|
+
const letter = (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c === 95 || c >= 128;
|
|
128
|
+
const digit = c >= 48 && c <= 57;
|
|
129
|
+
if (!letter && (i === 0 || !digit)) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Whether a text can be written as a DOT ID at all. Graphviz's scanner consumes a backslash pair
|
|
137
|
+
* `\\` as one unit and `\"` as an escaped quote, left to right, so a backslash that precedes a
|
|
138
|
+
* double quote or ends the text cannot be written: the written `\\"` reads as a pair and a closing
|
|
139
|
+
* quote, and a trailing backslash escapes the closing quote. Every other text is writable;
|
|
140
|
+
* quoteDotId() writes it.
|
|
141
|
+
* @param text - the id, name or value text
|
|
142
|
+
* @returns true when quoteDotId(text) reads back as `text`
|
|
143
|
+
*/
|
|
144
|
+
export function isWritableDotText(text) {
|
|
145
|
+
return !text.endsWith("\\") && !text.includes('\\"');
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Write a DOT ID: bare when the grammar allows, otherwise double-quoted with `"` escaped as `\"`.
|
|
149
|
+
* In DOT quoted strings the dyad `\"` is the only escape; every other character, a backslash and
|
|
150
|
+
* a raw line break included, is kept as written, so nothing else is rewritten. A text ending in a
|
|
151
|
+
* backslash has no DOT spelling (isWritableDotText); the caller refuses it before writing.
|
|
152
|
+
* @param text - the id or label text
|
|
153
|
+
* @returns the DOT ID
|
|
154
|
+
*/
|
|
155
|
+
export function quoteDotId(text) {
|
|
156
|
+
if (isBareDotId(text)) {
|
|
157
|
+
return text;
|
|
158
|
+
}
|
|
159
|
+
return `"${text.replace(/"/g, '\\"')}"`;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Write a set CSV cell per RFC 4180: quoted with `"` doubled when the text contains the
|
|
163
|
+
* delimiter, a quote, a CR or LF, or leading / trailing whitespace; bare otherwise. The empty
|
|
164
|
+
* string is written as the quoted empty cell `""`, so the importers can tell a set empty string
|
|
165
|
+
* (and an empty-string node id, legal under design section 4.1) from an unset cell, which every
|
|
166
|
+
* exporter writes as nothing between the delimiters.
|
|
167
|
+
* @param text - the cell text of a set cell
|
|
168
|
+
* @param delimiter - the field delimiter (default ",")
|
|
169
|
+
* @returns the cell as written
|
|
170
|
+
*/
|
|
171
|
+
export function quoteCsvCell(text, delimiter = ",") {
|
|
172
|
+
if (text.length === 0) {
|
|
173
|
+
return '""';
|
|
174
|
+
}
|
|
175
|
+
if (!text.includes(delimiter) &&
|
|
176
|
+
!text.includes('"') &&
|
|
177
|
+
!text.includes("\n") &&
|
|
178
|
+
!text.includes("\r") &&
|
|
179
|
+
text === text.trim()) {
|
|
180
|
+
return text;
|
|
181
|
+
}
|
|
182
|
+
return `"${text.replace(/"/g, '""')}"`;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Whether a text can be a Pajek label: Pajek has no escape mechanism inside its double-quoted
|
|
186
|
+
* labels, so a text containing a double quote, a CR or an LF cannot be written.
|
|
187
|
+
* @param text - the label text
|
|
188
|
+
* @returns true when quotePajekLabel() can write it
|
|
189
|
+
*/
|
|
190
|
+
export function isPajekLabel(text) {
|
|
191
|
+
return !text.includes('"') && !text.includes("\n") && !text.includes("\r");
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Write a Pajek label: bare when it is a single run of non-space, non-quote characters, otherwise
|
|
195
|
+
* double-quoted. E_UNSUPPORTED (reason "pajek label") for a text isPajekLabel() rejects; the
|
|
196
|
+
* exporter's check() counts those.
|
|
197
|
+
* @param text - the label text
|
|
198
|
+
* @returns the label as written
|
|
199
|
+
*/
|
|
200
|
+
export function quotePajekLabel(text) {
|
|
201
|
+
if (!isPajekLabel(text)) {
|
|
202
|
+
throw new GraphFormatError("E_UNSUPPORTED", "a Pajek label cannot contain a double quote or a line break", {
|
|
203
|
+
reason: "pajek label",
|
|
204
|
+
value: text,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (text.length > 0 && !/[\s"]/.test(text)) {
|
|
208
|
+
return text;
|
|
209
|
+
}
|
|
210
|
+
return `"${text}"`;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../../../src/common/escape.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,MAAM,gBAAgB,GAAG,UAAU,CAAC;AACpC,MAAM,gBAAgB,GAAG,eAAe,CAAC;AACzC,MAAM,gBAAgB,GAAqC;IACvD,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,OAAO;CAChB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACtC,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,MAAM,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;A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IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QACzB,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QACnB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QACpB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QACpB,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,EACtB,CAAC;QACC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC3C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACrC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IACxC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,gBAAgB,CAAC,eAAe,EAAE,6DAA6D,EAAE;YACvG,MAAM,EAAE,aAAa;YACrB,KAAK,EAAE,IAAI;SACd,CAAC,CAAC;IACP,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,IAAI,GAAG,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The exporter-side machinery of design section 8.5: the ExportCapabilities table helper, the
|
|
3
|
+
* generic check() that turns capability gaps into LossNotes with shared codes, and id sanitising
|
|
4
|
+
* (`sanitizeIds: "error"` by default; an exporter never silently renames a node; "mangle" rewrites
|
|
5
|
+
* the ids the format cannot hold and hands the exporter the originals to write into its
|
|
6
|
+
* `graphty:originalId` attribute).
|
|
7
|
+
*
|
|
8
|
+
* Every exporter's check() calls checkCapabilities() first and appends its format-specific notes
|
|
9
|
+
* (design section 8.5 names W_GML_RECORD_NUMBER_TYPE and W_OPEN_INTERVAL); export() calls
|
|
10
|
+
* sanitizeIds() before writing anything.
|
|
11
|
+
*/
|
|
12
|
+
import { type Dtype, type GraphSnapshot, type NodeId } from "@graphty/graph-format";
|
|
13
|
+
import { type ExportCapabilities, type LossNote } from "../types.js";
|
|
14
|
+
import { type ResolvedExportOptions } from "./options.js";
|
|
15
|
+
/** The shared LossNote codes of checkCapabilities(). */
|
|
16
|
+
export declare const LOSS: Readonly<{
|
|
17
|
+
/** The format has no mixed direction; expanded pairs are written per onMixedDirection. */
|
|
18
|
+
MIXED_DIRECTION: "W_MIXED_DIRECTION";
|
|
19
|
+
/** The format has no mixed direction and onMixedDirection is "error": export() will throw E_DIRECTED. */
|
|
20
|
+
MIXED_DIRECTION_ERROR: "E_MIXED_DIRECTION";
|
|
21
|
+
/** Parallel edges in a format without them. */
|
|
22
|
+
MULTI_EDGES: "W_MULTI_EDGES";
|
|
23
|
+
/** Self-loops in a format without them. */
|
|
24
|
+
SELF_LOOPS: "W_SELF_LOOPS";
|
|
25
|
+
/** The format requires edge ids and the snapshot has none; canonical e0..e{E-1} are generated. */
|
|
26
|
+
EDGE_IDS_GENERATED: "W_EDGE_IDS_GENERATED";
|
|
27
|
+
/** The snapshot has an edge id column and the format cannot write one. */
|
|
28
|
+
EDGE_IDS_DROPPED: "W_EDGE_IDS_DROPPED";
|
|
29
|
+
/** Ids outside the format's charset are rewritten (sanitizeIds "mangle"). */
|
|
30
|
+
ID_MANGLED: "W_ID_MANGLED";
|
|
31
|
+
/** Ids outside the format's charset and sanitizeIds "error": export() will throw E_INVALID_ID. */
|
|
32
|
+
ID_CHARSET: "E_ID_CHARSET";
|
|
33
|
+
/** The format numbers nodes 1..N; ids that are not their 1-based index are kept as labels only. */
|
|
34
|
+
ID_RENUMBERED: "W_ID_RENUMBERED";
|
|
35
|
+
/** A column dtype the format does not keep as declared. */
|
|
36
|
+
DTYPE: "W_DTYPE_UNSUPPORTED";
|
|
37
|
+
/** A multi-component column in a format without strides. */
|
|
38
|
+
COMPONENTS: "W_COMPONENTS_FLATTENED";
|
|
39
|
+
/** A list column in a format without lists. */
|
|
40
|
+
LIST: "W_LIST_UNSUPPORTED";
|
|
41
|
+
/** A json column in a format without nested values. */
|
|
42
|
+
JSON: "W_JSON_UNSUPPORTED";
|
|
43
|
+
/** A declared default in a format without defaults. */
|
|
44
|
+
DEFAULT: "W_DEFAULT_DROPPED";
|
|
45
|
+
/** Declared options in a format without enumerations. */
|
|
46
|
+
OPTIONS: "W_OPTIONS_DROPPED";
|
|
47
|
+
/** A parent / parents column in a format without containment. */
|
|
48
|
+
HIERARCHY: "W_HIERARCHY_DROPPED";
|
|
49
|
+
/** A start / end / timestamp column in a format without temporal support. */
|
|
50
|
+
TEMPORAL: "W_TEMPORAL_DROPPED";
|
|
51
|
+
/** A `<column>.text` companion (design section 5.1) the format cannot carry. */
|
|
52
|
+
TEMPORAL_TEXT: "W_TEMPORAL_TEXT_DROPPED";
|
|
53
|
+
/** A role column the format has no slot for; written as a plain attribute, the role lost. */
|
|
54
|
+
ROLE: "W_ROLE_DROPPED";
|
|
55
|
+
/** A parents (multi-parent) column in a format with single containment only. */
|
|
56
|
+
PARENTS: "W_PARENTS_DROPPED";
|
|
57
|
+
/** A mutual pair written as two directed edges without the mutual mark. */
|
|
58
|
+
MUTUAL_EXPANDED: "W_MUTUAL_EXPANDED";
|
|
59
|
+
/** A mutual pair written as one undirected edge; the mark is lost and the pair reads back undirected. */
|
|
60
|
+
MUTUAL_AS_UNDIRECTED: "W_MUTUAL_AS_UNDIRECTED";
|
|
61
|
+
/** Node ids whose written text reads back as the other type under the importer's id rule. */
|
|
62
|
+
ID_TEXT_TYPE: "W_ID_TEXT_TYPE";
|
|
63
|
+
/** Two node ids share one written text; export() throws E_INVALID_ID. */
|
|
64
|
+
ID_TEXT_COLLISION: "E_ID_TEXT_COLLISION";
|
|
65
|
+
/** A plain column named like the importer's weight key reads back as THE weight. */
|
|
66
|
+
WEIGHT_KEY_CLASH: "W_WEIGHT_KEY_CLASH";
|
|
67
|
+
/** A role-less column whose written name the importer maps to a role. */
|
|
68
|
+
ROLE_ASSUMED: "W_ROLE_ASSUMED";
|
|
69
|
+
/** A role column written into the format's slot reads back under the importer's fixed name. */
|
|
70
|
+
COLUMN_NAME_CHANGED: "W_COLUMN_NAME_CHANGED";
|
|
71
|
+
/** A declared column whose every row is unset vanishes through a format without declarations. */
|
|
72
|
+
EMPTY_COLUMN: "W_EMPTY_COLUMN_DROPPED";
|
|
73
|
+
/** A string / dict column that reads back as the other storage class (the dictionary heuristic). */
|
|
74
|
+
STORAGE_CLASS: "W_STORAGE_CLASS_CHANGED";
|
|
75
|
+
/** An f64 column whose set values are all integral reads back as i32 through an untyped format. */
|
|
76
|
+
INTEGRAL_F64: "W_INTEGRAL_F64_AS_I32";
|
|
77
|
+
/** Text cells that read back as numbers or booleans under the 5.1 grammar. */
|
|
78
|
+
TEXT_INFERRED: "W_TEXT_INFERRED";
|
|
79
|
+
/** A string cell holding a character XML 1.0 forbids; export() throws E_COLUMN_TYPE. */
|
|
80
|
+
XML_ILLEGAL_CHAR: "E_XML_ILLEGAL_CHAR";
|
|
81
|
+
/** A dict column without declared options gains one on re-import. */
|
|
82
|
+
OPTIONS_GAINED: "W_OPTIONS_GAINED";
|
|
83
|
+
/** A spells column in a format without spells. */
|
|
84
|
+
SPELLS: "W_SPELLS_DROPPED";
|
|
85
|
+
/** Dynamic attribute values (extension tables) in a format without them. */
|
|
86
|
+
DYNAMIC_VALUES: "W_DYNAMIC_VALUES_DROPPED";
|
|
87
|
+
/** An open-interval column in a format without open intervals (design section 5.1). */
|
|
88
|
+
OPEN_INTERVAL: "W_OPEN_INTERVAL";
|
|
89
|
+
/** Graph-level attributes in a format without them. */
|
|
90
|
+
GRAPH_ATTRIBUTES: "W_GRAPH_ATTRIBUTES_DROPPED";
|
|
91
|
+
/** A position column in a format without positions. */
|
|
92
|
+
POSITIONS: "W_POSITIONS_DROPPED";
|
|
93
|
+
/** Visual columns in a format without them. */
|
|
94
|
+
VIZ: "W_VIZ_DROPPED";
|
|
95
|
+
/** An extension table the format cannot carry. */
|
|
96
|
+
EXTENSION_TABLE: "W_EXTENSION_TABLE_DROPPED";
|
|
97
|
+
}>;
|
|
98
|
+
/** The capabilities of a format that keeps nothing beyond plain topology; the base every exporter overrides. */
|
|
99
|
+
export declare const NO_CAPABILITIES: ExportCapabilities;
|
|
100
|
+
/**
|
|
101
|
+
* Build a capabilities table from the fields a format supports; every field left out is the
|
|
102
|
+
* conservative NO_CAPABILITIES value, so an exporter states what it keeps and nothing is assumed.
|
|
103
|
+
* @param supported - the fields the format supports
|
|
104
|
+
* @returns a frozen table
|
|
105
|
+
*/
|
|
106
|
+
export declare function capabilities(supported: Partial<ExportCapabilities>): ExportCapabilities;
|
|
107
|
+
/**
|
|
108
|
+
* Format facts checkCapabilities() needs that the 12.4 table does not carry.
|
|
109
|
+
* Consumed by the per-format importers and exporters under src/formats.
|
|
110
|
+
* @public
|
|
111
|
+
*/
|
|
112
|
+
export interface CheckExtras {
|
|
113
|
+
/** Whether the format can write open intervals (GEXF 1.2 startopen / endopen); default false. */
|
|
114
|
+
readonly openIntervals?: boolean | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* Whether the format carries the `<column>.text` companions of design section 5.1 (the lexical
|
|
117
|
+
* form of a temporal value); default false, and every companion is then reported as
|
|
118
|
+
* W_TEMPORAL_TEXT_DROPPED.
|
|
119
|
+
*/
|
|
120
|
+
readonly temporalText?: boolean | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* The dtype the format's importer gives a position column; an f32 / f64 position of the other
|
|
123
|
+
* dtype is reported as W_DTYPE_UNSUPPORTED because its values differ at the other precision.
|
|
124
|
+
* Undefined skips the check.
|
|
125
|
+
*/
|
|
126
|
+
readonly positionDtype?: Dtype | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* The roles beyond the structural, position, viz, hierarchy and temporal ones that the format
|
|
129
|
+
* has a slot for (`label`, `kind`, `labels`, `idSpace`, `sourcePort`, `targetPort`, ...); a
|
|
130
|
+
* column with any other role is written as a plain attribute and reported as W_ROLE_DROPPED.
|
|
131
|
+
* Defaults to none.
|
|
132
|
+
*/
|
|
133
|
+
readonly roles?: ReadonlySet<string> | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* Roles the format writes into a fixed slot whose importer reads them back under a fixed name;
|
|
136
|
+
* a role column named otherwise is reported as W_COLUMN_NAME_CHANGED (role -> the name the
|
|
137
|
+
* importer gives it). Defaults to none.
|
|
138
|
+
*/
|
|
139
|
+
readonly roleNames?: Readonly<Record<string, string>> | undefined;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The generic pre-flight of design section 8.5: compare a snapshot with a format's capabilities
|
|
143
|
+
* and return one LossNote per gap, with the shared codes of LOSS. Format-specific notes are the
|
|
144
|
+
* exporter's to append.
|
|
145
|
+
* @param snapshot - the snapshot about to be exported
|
|
146
|
+
* @param caps - the exporter's capabilities
|
|
147
|
+
* @param options - the resolved common export options
|
|
148
|
+
* @param extras - format facts the capabilities table does not carry
|
|
149
|
+
* @returns the notes, empty when the export is exact
|
|
150
|
+
*/
|
|
151
|
+
export declare function checkCapabilities(snapshot: GraphSnapshot, caps: ExportCapabilities, options: ResolvedExportOptions, extras?: CheckExtras): LossNote[];
|
|
152
|
+
/**
|
|
153
|
+
* The number of source edges that were undirected in a directed snapshot (the halves of an
|
|
154
|
+
* expanded pair count once; an expanded self-loop has no mirror and counts once).
|
|
155
|
+
* @param snapshot - the snapshot
|
|
156
|
+
* @returns the count; 0 for an undirected snapshot or one without the directed role
|
|
157
|
+
*/
|
|
158
|
+
export declare function countMixedEdges(snapshot: GraphSnapshot): number;
|
|
159
|
+
/**
|
|
160
|
+
* The number of arcs that repeat the previous arc's target within a row (parallel edges), counted
|
|
161
|
+
* over the forward CSR; an undirected parallel edge is counted in both rows.
|
|
162
|
+
* @param snapshot - the snapshot
|
|
163
|
+
* @returns the count
|
|
164
|
+
*/
|
|
165
|
+
export declare function countParallelArcs(snapshot: GraphSnapshot): number;
|
|
166
|
+
/**
|
|
167
|
+
* The id charsets of ExportCapabilities.
|
|
168
|
+
* Consumed by the per-format importers and exporters under src/formats.
|
|
169
|
+
* @public
|
|
170
|
+
*/
|
|
171
|
+
export type IdCharset = ExportCapabilities["idCharset"];
|
|
172
|
+
/**
|
|
173
|
+
* The ids to write for every node after sanitising (design section 8.5).
|
|
174
|
+
* Consumed by the per-format importers and exporters under src/formats.
|
|
175
|
+
* @public
|
|
176
|
+
*/
|
|
177
|
+
export interface SanitizedIds {
|
|
178
|
+
/** The charset applied. */
|
|
179
|
+
readonly charset: IdCharset;
|
|
180
|
+
/** How many ids differ from the snapshot's. */
|
|
181
|
+
readonly changed: number;
|
|
182
|
+
/**
|
|
183
|
+
* The id to write for a node.
|
|
184
|
+
* @param index - the node index
|
|
185
|
+
* @returns the id as the format will read it back
|
|
186
|
+
*/
|
|
187
|
+
idAt(index: number): NodeId;
|
|
188
|
+
/**
|
|
189
|
+
* Whether a node's written id differs from its original.
|
|
190
|
+
* @param index - the node index
|
|
191
|
+
* @returns true when the exporter must record the original
|
|
192
|
+
*/
|
|
193
|
+
isChanged(index: number): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* The original id of a node.
|
|
196
|
+
* @param index - the node index
|
|
197
|
+
* @returns the snapshot's id
|
|
198
|
+
*/
|
|
199
|
+
originalAt(index: number): NodeId;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Whether a code point is an XML NameChar.
|
|
203
|
+
* @param cp - the code point
|
|
204
|
+
* @returns true when it may appear in an NMTOKEN
|
|
205
|
+
*/
|
|
206
|
+
export declare function isNameChar(cp: number): boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Whether a text is an XML NMTOKEN (one or more NameChars; GraphML node and edge ids).
|
|
209
|
+
* @param text - the text
|
|
210
|
+
* @returns true for a non-empty text of NameChars
|
|
211
|
+
*/
|
|
212
|
+
export declare function isNmtoken(text: string): boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Whether an id can be written unchanged under a charset.
|
|
215
|
+
* @param id - the id
|
|
216
|
+
* @param charset - the charset
|
|
217
|
+
* @returns true when the id needs no rewriting ("dense-1-based" is never true: see sanitizeIds)
|
|
218
|
+
*/
|
|
219
|
+
export declare function isRepresentableId(id: NodeId, charset: IdCharset): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* How many node ids a charset cannot hold as they are (for check()); under "dense-1-based" the
|
|
222
|
+
* ids that are not their own 1-based index.
|
|
223
|
+
* @param snapshot - the snapshot
|
|
224
|
+
* @param charset - the charset
|
|
225
|
+
* @returns the count
|
|
226
|
+
*/
|
|
227
|
+
export declare function countUnrepresentableIds(snapshot: GraphSnapshot, charset: IdCharset): number;
|
|
228
|
+
/**
|
|
229
|
+
* Sanitise the node ids for a charset (design section 8.5). Under "error" any id the charset
|
|
230
|
+
* cannot hold is E_INVALID_ID (details.reason "charset") and nothing is written; under "mangle"
|
|
231
|
+
* such ids are rewritten deterministically and uniquely: NMTOKEN by replacing every other
|
|
232
|
+
* character with `_` (an empty result becomes `_`) and suffixing `_2`, `_3`... on collision;
|
|
233
|
+
* integer by the smallest unused non-negative integers in index order. "dense-1-based" always
|
|
234
|
+
* writes the 1-based index (Pajek numbers vertices; the exporter writes the original id as the
|
|
235
|
+
* label), which is a renumbering rather than a mangling, so it never throws under "error"; under
|
|
236
|
+
* "mangle" the exporter also writes the original id under its originalId attribute.
|
|
237
|
+
* @param snapshot - the snapshot
|
|
238
|
+
* @param charset - the charset
|
|
239
|
+
* @param mode - the resolved sanitizeIds option
|
|
240
|
+
* @returns the ids to write
|
|
241
|
+
*/
|
|
242
|
+
export declare function sanitizeIds(snapshot: GraphSnapshot, charset: IdCharset, mode: "error" | "mangle"): SanitizedIds;
|
|
243
|
+
/**
|
|
244
|
+
* Rewrite a text as an NMTOKEN: every character that is not a NameChar becomes `_`.
|
|
245
|
+
* @param text - the text
|
|
246
|
+
* @returns a non-empty NMTOKEN
|
|
247
|
+
*/
|
|
248
|
+
export declare function mangleNmtoken(text: string): string;
|
|
249
|
+
//# sourceMappingURL=export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../src/common/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAEH,KAAK,KAAK,EAEV,KAAK,aAAa,EAElB,KAAK,MAAM,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAqBrE,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE1D,wDAAwD;AACxD,eAAO,MAAM,IAAI;IACb,0FAA0F;;IAE1F,yGAAyG;;IAEzG,+CAA+C;;IAE/C,2CAA2C;;IAE3C,kGAAkG;;IAElG,0EAA0E;;IAE1E,6EAA6E;;IAE7E,kGAAkG;;IAElG,mGAAmG;;IAEnG,2DAA2D;;IAE3D,4DAA4D;;IAE5D,+CAA+C;;IAE/C,uDAAuD;;IAEvD,uDAAuD;;IAEvD,yDAAyD;;IAEzD,iEAAiE;;IAEjE,6EAA6E;;IAE7E,gFAAgF;;IAEhF,6FAA6F;;IAE7F,gFAAgF;;IAEhF,2EAA2E;;IAE3E,yGAAyG;;IAEzG,6FAA6F;;IAE7F,yEAAyE;;IAEzE,oFAAoF;;IAEpF,yEAAyE;;IAEzE,+FAA+F;;IAE/F,iGAAiG;;IAEjG,oGAAoG;;IAEpG,mGAAmG;;IAEnG,8EAA8E;;IAE9E,wFAAwF;;IAExF,qEAAqE;;IAErE,kDAAkD;;IAElD,4EAA4E;;IAE5E,u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