@graphty/graph-io 0.3.32 → 0.3.34
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/dist/chunks/{choose-BJq_vp1b.js → choose-494CpuXQ.js} +2 -2
- package/dist/chunks/{choose-BJq_vp1b.js.map → choose-494CpuXQ.js.map} +1 -1
- package/dist/chunks/{constants-Bw-6JQuC.js → constants-BBK4rsQZ.js} +2 -2
- package/dist/chunks/{constants-Bw-6JQuC.js.map → constants-BBK4rsQZ.js.map} +1 -1
- package/dist/chunks/{escape-CnTfa_y8.js → escape-wVIEtLv6.js} +6 -6
- package/dist/chunks/escape-wVIEtLv6.js.map +1 -0
- package/dist/chunks/{export-ZucVKiU4.js → export-Cbt4h_0n.js} +8 -8
- package/dist/chunks/export-Cbt4h_0n.js.map +1 -0
- package/dist/chunks/{exporter-BOLJIzvA.js → exporter-CkPnJCXU.js} +36 -12
- package/dist/chunks/exporter-CkPnJCXU.js.map +1 -0
- package/dist/chunks/{exporter-hc2ZuqVe.js → exporter-CqnmKk-f.js} +4 -4
- package/dist/chunks/{exporter-hc2ZuqVe.js.map → exporter-CqnmKk-f.js.map} +1 -1
- package/dist/chunks/{exporter-DgDjwLOm.js → exporter-DMxRy-0l.js} +4 -4
- package/dist/chunks/{exporter-DgDjwLOm.js.map → exporter-DMxRy-0l.js.map} +1 -1
- package/dist/chunks/{exporter-DRNkA2k0.js → exporter-LZTIAzkS.js} +19 -7
- package/dist/chunks/{exporter-DRNkA2k0.js.map → exporter-LZTIAzkS.js.map} +1 -1
- package/dist/chunks/{importer-DsNj_zoG.js → importer-BTSvNJUB.js} +4 -4
- package/dist/chunks/importer-BTSvNJUB.js.map +1 -0
- package/dist/chunks/{importer-ByCd2CAY.js → importer-BTbjwN10.js} +5 -5
- package/dist/chunks/{importer-ByCd2CAY.js.map → importer-BTbjwN10.js.map} +1 -1
- package/dist/chunks/{importer-WPz-AUz8.js → importer-C1VMuEBQ.js} +8 -8
- package/dist/chunks/importer-C1VMuEBQ.js.map +1 -0
- package/dist/chunks/{importer-BAlFKpHP.js → importer-CSmH218L.js} +6 -6
- package/dist/chunks/{importer-BAlFKpHP.js.map → importer-CSmH218L.js.map} +1 -1
- package/dist/chunks/{importer-D7xB8oVV.js → importer-DMgcD1wI.js} +5 -5
- package/dist/chunks/{importer-D7xB8oVV.js.map → importer-DMgcD1wI.js.map} +1 -1
- package/dist/chunks/{importer-rjFCmKfx.js → importer-DtKPzhVp.js} +5 -5
- package/dist/chunks/importer-DtKPzhVp.js.map +1 -0
- package/dist/chunks/{importer-CaLIrkjL.js → importer-DvPvd4Yy.js} +22 -15
- package/dist/chunks/importer-DvPvd4Yy.js.map +1 -0
- package/dist/chunks/{json-elements-CkC87El2.js → json-elements-CxJF-Szz.js} +6 -6
- package/dist/chunks/json-elements-CxJF-Szz.js.map +1 -0
- package/dist/chunks/{ontology-export-BRErBO6J.js → ontology-export-p1PsPenq.js} +2 -2
- package/dist/chunks/{ontology-export-BRErBO6J.js.map → ontology-export-p1PsPenq.js.map} +1 -1
- package/dist/chunks/{records-DwfSjH8c.js → records-BrfHycmg.js} +2 -2
- package/dist/chunks/{records-DwfSjH8c.js.map → records-BrfHycmg.js.map} +1 -1
- package/dist/chunks/{text-BEEWD-G1.js → text-BD-TzLNm.js} +4 -4
- package/dist/chunks/text-BD-TzLNm.js.map +1 -0
- package/dist/csv.js +4 -4
- package/dist/cx.js +1 -1
- package/dist/cx2.js +2 -2
- package/dist/cys.js +1 -1
- package/dist/dot.js +1 -1
- package/dist/gexf.js +2 -2
- package/dist/gml.js +10 -10
- package/dist/gml.js.map +1 -1
- package/dist/graph-io.js +26 -26
- package/dist/graphml.js +2 -2
- package/dist/json.js +1 -1
- package/dist/neo4j.js +3 -3
- package/dist/obo.js +1 -1
- package/dist/pajek.js +1 -1
- package/dist/src/common/attributes.js +1 -1
- package/dist/src/common/attributes.js.map +1 -1
- package/dist/src/common/declared-types.js +2 -2
- package/dist/src/common/declared-types.js.map +1 -1
- package/dist/src/common/escape.js +2 -2
- package/dist/src/common/escape.js.map +1 -1
- package/dist/src/common/ids.js +1 -1
- package/dist/src/common/ids.js.map +1 -1
- package/dist/src/common/json-elements.d.ts.map +1 -1
- package/dist/src/common/json-elements.js +3 -3
- package/dist/src/common/json-elements.js.map +1 -1
- package/dist/src/common/temporal.js +3 -3
- package/dist/src/common/temporal.js.map +1 -1
- package/dist/src/common/text.js +2 -2
- package/dist/src/common/text.js.map +1 -1
- package/dist/src/common/xml.js +2 -2
- package/dist/src/common/xml.js.map +1 -1
- package/dist/src/formats/cx/exporter.js +1 -1
- package/dist/src/formats/cx/exporter.js.map +1 -1
- package/dist/src/formats/cx/importer.js +3 -3
- package/dist/src/formats/cx/importer.js.map +1 -1
- package/dist/src/formats/cx2/importer.js +1 -1
- package/dist/src/formats/cx2/importer.js.map +1 -1
- package/dist/src/formats/gml/exporter.js +1 -1
- package/dist/src/formats/gml/exporter.js.map +1 -1
- package/dist/src/formats/gml/importer.js +2 -2
- package/dist/src/formats/gml/importer.js.map +1 -1
- package/dist/src/formats/gml/syntax.js +4 -4
- package/dist/src/formats/gml/syntax.js.map +1 -1
- package/dist/src/formats/graphml/importer.js +1 -1
- package/dist/src/formats/graphml/importer.js.map +1 -1
- package/dist/src/formats/json/exporter.d.ts +2 -0
- package/dist/src/formats/json/exporter.d.ts.map +1 -1
- package/dist/src/formats/json/exporter.js +3 -1
- package/dist/src/formats/json/exporter.js.map +1 -1
- package/dist/src/formats/json/obographs-export.d.ts +2 -0
- package/dist/src/formats/json/obographs-export.d.ts.map +1 -1
- package/dist/src/formats/json/obographs-export.js +5 -0
- package/dist/src/formats/json/obographs-export.js.map +1 -1
- package/dist/src/formats/obo/exporter.d.ts +2 -0
- package/dist/src/formats/obo/exporter.d.ts.map +1 -1
- package/dist/src/formats/obo/exporter.js +5 -0
- package/dist/src/formats/obo/exporter.js.map +1 -1
- package/dist/src/formats/obo/syntax.d.ts.map +1 -1
- package/dist/src/formats/obo/syntax.js +39 -10
- package/dist/src/formats/obo/syntax.js.map +1 -1
- package/dist/src/formats/pajek/exporter.d.ts.map +1 -1
- package/dist/src/formats/pajek/exporter.js +2 -4
- package/dist/src/formats/pajek/exporter.js.map +1 -1
- package/dist/src/formats/pajek/importer.js +2 -2
- package/dist/src/formats/pajek/importer.js.map +1 -1
- package/dist/src/formats/pajek/syntax.d.ts.map +1 -1
- package/dist/src/formats/pajek/syntax.js +14 -4
- package/dist/src/formats/pajek/syntax.js.map +1 -1
- package/dist/src/formats/xgmml/values.js +1 -1
- package/dist/src/formats/xgmml/values.js.map +1 -1
- package/dist/xgmml.js +2 -2
- package/package.json +2 -2
- package/src/common/attributes.ts +1 -1
- package/src/common/declared-types.ts +2 -2
- package/src/common/escape.ts +2 -2
- package/src/common/ids.ts +1 -1
- package/src/common/json-elements.ts +3 -3
- package/src/common/temporal.ts +3 -3
- package/src/common/text.ts +2 -2
- package/src/common/xml.ts +2 -2
- package/src/formats/cx/exporter.ts +1 -1
- package/src/formats/cx/importer.ts +3 -3
- package/src/formats/cx2/importer.ts +1 -1
- package/src/formats/gml/exporter.ts +1 -1
- package/src/formats/gml/importer.ts +2 -2
- package/src/formats/gml/syntax.ts +4 -4
- package/src/formats/graphml/importer.ts +1 -1
- package/src/formats/json/exporter.ts +3 -1
- package/src/formats/json/obographs-export.ts +10 -0
- package/src/formats/obo/exporter.ts +10 -0
- package/src/formats/obo/syntax.ts +42 -9
- package/src/formats/pajek/exporter.ts +2 -4
- package/src/formats/pajek/importer.ts +2 -2
- package/src/formats/pajek/syntax.ts +14 -5
- package/src/formats/xgmml/values.ts +1 -1
- package/dist/chunks/escape-CnTfa_y8.js.map +0 -1
- package/dist/chunks/export-ZucVKiU4.js.map +0 -1
- package/dist/chunks/exporter-BOLJIzvA.js.map +0 -1
- package/dist/chunks/importer-CaLIrkjL.js.map +0 -1
- package/dist/chunks/importer-DsNj_zoG.js.map +0 -1
- package/dist/chunks/importer-WPz-AUz8.js.map +0 -1
- package/dist/chunks/importer-rjFCmKfx.js.map +0 -1
- package/dist/chunks/json-elements-CkC87El2.js.map +0 -1
- package/dist/chunks/text-BEEWD-G1.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records-DwfSjH8c.js","sources":["../../src/formats/csv/records.ts"],"sourcesContent":["/**\n * The one streaming CSV record reader of the package (design sections 8.2 and 8.4: hand-written\n * tokenisers per format; CSV and Neo4j CSV are line-oriented over a byte stream): RFC 4180 records\n * with a configurable single-character delimiter and quote, a doubled quote inside a quoted field,\n * quoted fields spanning lines, LF / CRLF / lone-CR terminators, read from the common text reader\n * one chunk at a time as a character state machine. Only the open field is ever held, so a field\n * spanning many chunks costs its length once and a multi-gigabyte file is never buffered.\n *\n * `RecordReader` (used by the Neo4j importer) keeps one reusable cell array and one reusable\n * \"was quoted\" array: a quoted empty field (`\"\"`) is an empty string while an unquoted empty field\n * means \"not set\", and only the tokeniser can tell the two apart. `CsvRecordReader` (the CSV\n * importer) wraps it with delimiter sniffing over a bounded preview and yields a fresh cell array\n * per row. A malformed quoted field is fatal for both: an unterminated quote swallows the rest of\n * the file, and text after a closing quote makes every later cell boundary unreliable.\n */\n\nimport { GraphFormatError } from \"@graphty/graph-format\";\n\nimport { MAX_TEXT_LENGTH, type ReadOptions, textChunks, tooLarge } from \"../../common/input.js\";\nimport { type ImportReportBuilder } from \"../../common/report.js\";\nimport { type ImportInput } from \"../../types.js\";\n\n/**\n * A quoted field is never closed; the import aborts (everything after it would be one cell).\n * @category Issue and loss codes\n */\nexport const UNCLOSED_QUOTE_CODE = \"E_CSV_UNCLOSED_QUOTE\";\n\n/**\n * A closing quote is followed by text other than a delimiter or a line break; the import aborts.\n * @category Issue and loss codes\n */\nexport const BAD_QUOTE_CODE = \"E_CSV_QUOTE\";\n\n/**\n * The delimiters tried, in priority order, when none is given.\n * @category Plugin helpers\n */\nexport const DELIMITER_CANDIDATES: readonly string[] = Object.freeze([\",\", \"\\t\", \";\", \"|\", \" \"]);\n\n/** Rows the delimiter sniff looks at. */\nconst PREVIEW_ROWS = 10;\n\n/** Characters buffered for the sniff when the input has fewer than PREVIEW_ROWS line breaks. */\nconst PREVIEW_CHARS = 64 * 1024;\n\nconst LF = 10;\nconst CR = 13;\nconst TAB = 9;\nconst SPACE = 32;\n\n/** An Excel delimiter directive: a first line `sep=;` names the delimiter and is not a record. */\nconst SEP_DIRECTIVE = /^sep=([^\\r\\n])(?:\\r\\n|\\n|\\r|$)/i;\n\n/** Tokeniser state: at the start of a field. */\nconst START = 0;\n/** Tokeniser state: inside an unquoted field. */\nconst UNQUOTED = 1;\n/** Tokeniser state: inside a quoted field. */\nconst QUOTED = 2;\n/** Tokeniser state: just after a quote inside a quoted field (a second quote is a literal, anything else ends the field). */\nconst CLOSING = 3;\n/** Tokeniser state: after a closed quoted field, before the delimiter (text here is malformed). */\nconst AFTER_QUOTED = 4;\n/** Inside a leading comment line (skipped up to its line break). */\nconst COMMENT = 5;\n\ntype State = typeof START | typeof UNQUOTED | typeof QUOTED | typeof CLOSING | typeof AFTER_QUOTED | typeof COMMENT;\n\n/**\n * The delimiter and quote of a reader.\n * @category Plugin helpers\n */\nexport interface RecordSyntax {\n /** The field delimiter, one character; null sniffs it from the first rows. */\n readonly delimiter: string | null;\n /** The quote character, one character. */\n readonly quote: string;\n /** The delimiters tried when `delimiter` is null; DELIMITER_CANDIDATES by default. */\n readonly candidates?: readonly string[] | undefined;\n /**\n * Characters that open a comment line while no record has been read yet (SNAP `#`, KONECT\n * `%`): such leading lines are skipped, kept in `leadingComments` and left out of the delimiter\n * sniff. A later line starting with one of them is an ordinary record. Default: none.\n */\n readonly comments?: readonly string[] | undefined;\n /**\n * Whether the delimiter sniff skips a candidate under which a closing quote is followed by\n * other text (see sniffDelimiter). False by default: that text then aborts the read.\n */\n readonly skipQuoteErrors?: boolean | undefined;\n /**\n * Whether a space delimiter means the whitespace dialect of SNAP / KONECT edge lists: any run of\n * spaces and tabs separates two fields, and whitespace at the start and end of a line is\n * ignored. False by default (every space is a delimiter).\n */\n readonly collapseSpaces?: boolean | undefined;\n /** Whether an Excel `sep=X` first line names the delimiter for the sniff. False by default. */\n readonly sepDirective?: boolean | undefined;\n /**\n * Called with the sniff preview (leading comment lines removed) and the line it starts on,\n * before any record is scanned, so a caller can refuse input that is not delimited text at all.\n * Only called when the delimiter is sniffed.\n */\n readonly inspect?: ((preview: string, line: number) => void) | undefined;\n}\n\n/**\n * Check a delimiter or quote option: exactly one character that is not a line break, and the two\n * must differ.\n * @param syntax - the delimiter (or null for sniffing) and quote\n * @returns the syntax unchanged; E_UNSUPPORTED when invalid\n * @category Plugin helpers\n */\nexport function checkRecordSyntax(syntax: RecordSyntax): RecordSyntax {\n for (const [option, value] of [\n [\"delimiter\", syntax.delimiter],\n [\"quote\", syntax.quote],\n ] as const) {\n if (value === null) {\n continue;\n }\n if (value.length !== 1 || value === \"\\n\" || value === \"\\r\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option ${option}: ${JSON.stringify(value)} is not a single non-line-break character`,\n { option, found: value },\n );\n }\n }\n if (syntax.delimiter !== null && syntax.delimiter === syntax.quote) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"options delimiter and quote must differ\", {\n option: \"delimiter\",\n found: syntax.delimiter,\n });\n }\n return syntax;\n}\n\n/**\n * Sniff the line terminator of a text: a lone `\\r` only when the text has `\\r` and no `\\n` at all\n * (classic Mac files); `\\n` otherwise.\n * @param text - the preview text\n * @returns \"\\n\" or \"\\r\"\n * @category Plugin helpers\n */\nexport function sniffNewline(text: string): \"\\n\" | \"\\r\" {\n return !text.includes(\"\\n\") && text.includes(\"\\r\") ? \"\\r\" : \"\\n\";\n}\n\n/**\n * Split a text into records synchronously (the first `maxRows` of them), honoring quotes; for\n * the delimiter sniff and the registry's head sniff, where the input is a bounded preview.\n * @param text - the text\n * @param delimiter - the delimiter\n * @param quote - the quote character\n * @param maxRows - the most rows to return\n * @param strictQuotes - return null when a closing quote is followed by text other than the\n * delimiter or a line break (the import would abort under this delimiter)\n * @param collapse - the whitespace dialect (RecordSyntax.collapseSpaces) for a space delimiter\n * @returns the rows as cell arrays (blank lines skipped), or null (see strictQuotes)\n * @category Plugin helpers\n */\nexport function splitRecords(\n text: string,\n delimiter: string,\n quote: string,\n maxRows: number,\n strictQuotes = false,\n collapse = false,\n): string[][] | null {\n const delimiterCode = delimiter.codePointAt(0);\n const splitter = new RecordSplitter(text, quote, delimiterCode, collapse && delimiterCode === SPACE, strictQuotes);\n let i = 0;\n while (i < text.length && splitter.rows.length < maxRows) {\n i = splitter.step(i);\n if (i < 0) {\n return null;\n }\n }\n if (splitter.rows.length < maxRows) {\n splitter.finish();\n }\n return splitter.rows;\n}\n\n/** The state machine of splitRecords(): one character at a time, quotes honored. */\nclass RecordSplitter {\n /** The rows read so far. */\n readonly rows: string[][] = [];\n\n private cells: string[] = [];\n\n private state: State = START;\n\n /** Where the unread part of the current field starts. */\n private segment = 0;\n\n private field = \"\";\n\n private readonly quoteCode: number | undefined;\n\n /**\n * Create a splitter.\n * @param text - the text\n * @param quote - the quote character\n * @param delimiterCode - the delimiter's code\n * @param whitespace - whether runs of spaces and tabs are one separator\n * @param strictQuotes - whether text after a closing quote gives up\n */\n constructor(\n private readonly text: string,\n private readonly quote: string,\n private readonly delimiterCode: number | undefined,\n private readonly whitespace: boolean,\n private readonly strictQuotes: boolean,\n ) {\n this.quoteCode = quote.codePointAt(0);\n }\n\n /**\n * Read one character.\n * @param i - its index\n * @returns the index of the next character to read, or -1 to give up (strictQuotes)\n */\n step(i: number): number {\n const c = this.text.codePointAt(i);\n if (this.state === QUOTED) {\n if (c === this.quoteCode) {\n this.field += this.text.slice(this.segment, i);\n this.state = CLOSING;\n }\n return i + 1;\n }\n const isDelimiter = c === this.delimiterCode || (this.whitespace && c === TAB);\n if (this.state === CLOSING) {\n const next = this.afterQuote(i, c, isDelimiter || c === LF || c === CR);\n if (next !== null) {\n return next;\n }\n }\n if (isDelimiter || c === LF || c === CR) {\n return this.separator(i, isDelimiter);\n }\n if (this.state === START) {\n const quoted = c === this.quoteCode;\n this.state = quoted ? QUOTED : UNQUOTED;\n this.segment = quoted ? i + 1 : i;\n }\n return i + 1;\n }\n\n /**\n * Read the character after a quote that may close a quoted field: a second quote is a quote\n * character in the field; anything else closes it.\n * @param i - its index\n * @param c - its code\n * @param separates - whether it is a delimiter or a line break\n * @returns the index of the next character to read, -1 to give up (strictQuotes), or null to\n * read this character as the one after the field\n */\n private afterQuote(i: number, c: number | undefined, separates: boolean): number | null {\n if (c === this.quoteCode) {\n this.field += this.quote;\n this.segment = i + 1;\n this.state = QUOTED;\n return i + 1;\n }\n if (this.strictQuotes && !separates) {\n return -1;\n }\n this.state = AFTER_QUOTED;\n this.segment = i;\n return null;\n }\n\n /**\n * Read a delimiter or a line break: end the field, and at a line break the row.\n * @param i - its index\n * @param isDelimiter - whether it is a delimiter\n * @returns the index of the next character to read\n */\n private separator(i: number, isDelimiter: boolean): number {\n if (this.state === UNQUOTED || this.state === AFTER_QUOTED) {\n this.field += this.text.slice(this.segment, i);\n }\n let next = i + 1;\n if (isDelimiter && this.whitespace && this.state === START) {\n // a run of whitespace, or indentation: one separator\n } else if (isDelimiter) {\n this.cells.push(this.field);\n this.field = \"\";\n this.state = START;\n } else {\n this.endRow();\n this.state = START;\n if (this.text.codePointAt(i) === CR && this.text.codePointAt(i + 1) === LF) {\n next = i + 2;\n }\n }\n this.segment = next;\n return next;\n }\n\n /** End the row at a line break; a blank line is no row. */\n private endRow(): void {\n if (this.state === START && this.cells.length === 0) {\n return;\n }\n if (!(this.whitespace && this.state === START)) {\n this.cells.push(this.field);\n }\n this.rows.push(this.cells);\n this.cells = [];\n this.field = \"\";\n }\n\n /** End the text: the last row, when it has no line break after it. */\n finish(): void {\n if (this.state === START && this.cells.length === 0) {\n return;\n }\n if (this.state === UNQUOTED || this.state === AFTER_QUOTED || this.state === QUOTED) {\n this.field += this.text.slice(this.segment);\n }\n if (!(this.whitespace && this.state === START)) {\n this.cells.push(this.field);\n }\n this.rows.push(this.cells);\n }\n}\n\n/**\n * The preview text without its leading comment lines (those starting with one of the comment\n * characters), so the sniff sees the records only.\n * @param text - the preview text\n * @param comments - the comment characters\n * @returns the text from the first non-comment line on\n * @category Plugin helpers\n */\nexport function stripLeadingComments(text: string, comments: readonly string[]): string {\n if (comments.length === 0) {\n return text;\n }\n let at = 0;\n while (at < text.length) {\n if (text[at] === \"\\n\" || text[at] === \"\\r\") {\n // a blank line among the leading comments (the scanner skips it too)\n at++;\n continue;\n }\n if (!comments.includes(text[at])) {\n break;\n }\n const lf = text.indexOf(\"\\n\", at);\n const cr = text.indexOf(\"\\r\", at);\n const end = Math.min(lf < 0 ? Infinity : lf, cr < 0 ? Infinity : cr);\n if (end === Infinity) {\n return \"\";\n }\n at = end;\n }\n return at === 0 ? text : text.slice(at);\n}\n\n/**\n * Sniff the delimiter of a text: every candidate is tried over the first rows and the one whose\n * field count is most consistent across rows wins (a tie goes to the earlier candidate, so a\n * space inside comma-separated cells never beats the comma); a\n * candidate that yields fewer than two fields per row on average is never chosen. `null` when no\n * candidate qualifies (a single-column file).\n * @param text - the preview text\n * @param newline - the sniffed line terminator (unused by the splitter, which reads every kind;\n * kept for callers that sniffed it)\n * @param candidates - the delimiters to try, in priority order\n * @param quote - the quote character\n * @param skipQuoteErrors - also never choose a candidate under which a closing quote is followed\n * by other text. Only for inputs whose field counts say nothing (an adjacency table's rows vary in\n * width): elsewhere a stray character after a quote would make a worse candidate win silently\n * instead of aborting the read\n * @param collapse - read a space candidate in the whitespace dialect (RecordSyntax.collapseSpaces)\n * @returns the delimiter, or null\n * @category Plugin helpers\n */\nexport function sniffDelimiter(\n text: string,\n newline: \"\\n\" | \"\\r\" = \"\\n\",\n candidates: readonly string[] = DELIMITER_CANDIDATES,\n quote = '\"',\n skipQuoteErrors = false,\n collapse = false,\n): string | null {\n let best: string | null = null;\n let bestDelta = Infinity;\n const terminated = text.endsWith(\"\\n\") || text.endsWith(\"\\r\");\n for (const delimiter of candidates) {\n if (delimiter === quote || delimiter === newline) {\n continue;\n }\n const split = splitRecords(text, delimiter, quote, PREVIEW_ROWS, skipQuoteErrors, collapse);\n if (split === null) {\n // a quoted cell this delimiter does not close: it is not the file's delimiter\n continue;\n }\n let rows = split.filter((row) => !isBlankRow(row));\n if (rows.length > 1 && !terminated) {\n // the preview is a prefix of the file: its last row may be cut short\n rows = rows.slice(0, -1);\n }\n if (rows.length === 0) {\n continue;\n }\n let total = 0;\n let delta = 0;\n for (let i = 0; i < rows.length; i++) {\n const count = rows[i].length;\n total += count;\n if (i > 0) {\n delta += Math.abs(count - rows[i - 1].length);\n }\n }\n const average = total / rows.length;\n if (average > 1.99 && delta < bestDelta) {\n best = delimiter;\n bestDelta = delta;\n }\n }\n return best;\n}\n\n/**\n * Whether a parsed row is a blank line: one cell holding only whitespace.\n * @param row - the row\n * @returns true for a blank line\n */\nfunction isBlankRow(row: readonly string[]): boolean {\n return row.length === 1 && row[0].trim().length === 0;\n}\n\n/**\n * Reads the records of one input. Iterate with `for await (const count of reader)`: each\n * iteration fills `reader.cells[0..count)` and `reader.quoted[0..count)` and sets `reader.line`\n * to the 1-based line the record started on. Blank lines (an empty unquoted record of one field)\n * are skipped. The arrays are reused between records. When the syntax gives no delimiter, the\n * first rows (PREVIEW_ROWS, or PREVIEW_CHARS characters) are buffered and the delimiter sniffed\n * from them before the first record is yielded.\n * @category Plugin helpers\n */\nexport class RecordReader implements AsyncIterable<number> {\n /** The cells of the record most recently yielded; only the first `count` entries are valid. */\n readonly cells: string[] = [];\n\n /** Whether each cell of the record most recently yielded was quoted. */\n readonly quoted: boolean[] = [];\n\n /** The leading comment lines (without their line breaks), in order; empty without `syntax.comments`. */\n readonly leadingComments: string[] = [];\n\n /** The 1-based line of each leading comment, parallel to `leadingComments`. */\n readonly leadingCommentLines: number[] = [];\n\n /** The line of the first quote inside an unquoted field (kept as text, RFC 4180 forbids it); 0 for none. */\n strayQuoteLine = 0;\n\n /** Whether the sniff took the delimiter from an Excel `sep=X` first line (yielded as the first record). */\n sepDirective = false;\n\n private readonly input: ImportInput;\n\n readonly report: ImportReportBuilder;\n\n private readonly readOptions: ReadOptions;\n\n /** The delimiter (null while unsniffed), quote and comment characters. */\n readonly syntax: RecordSyntax;\n\n private delimiterText: string | null;\n\n private recordLine = 0;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input (or an async iterable of already decoded text chunks)\n * @param report - the report decode and quoting errors are recorded in\n * @param syntax - the delimiter (null to sniff) and quote (already checked)\n * @param readOptions - cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, syntax: RecordSyntax, readOptions: ReadOptions) {\n this.input = input;\n this.report = report;\n this.readOptions = readOptions;\n this.syntax = syntax;\n this.delimiterText = syntax.delimiter;\n }\n\n /**\n * The 1-based line the most recently yielded record started on.\n * @returns the line number; 0 before the first record\n */\n get line(): number {\n return this.recordLine;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.delimiterText;\n }\n\n /**\n * Iterate the records.\n * @yields the number of cells of each record\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<number, void, undefined> {\n const scanner = new RecordScanner(this);\n for await (const chunk of this.chunks()) {\n // the first chunk arrives after the sniff (or with the given delimiter)\n scanner.setDelimiter((this.delimiterText ?? \",\").charCodeAt(0));\n let i = 0;\n while (i < chunk.length) {\n i = scanner.scan(chunk, i);\n if (scanner.ready) {\n scanner.ready = false;\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n scanner.count = 0;\n }\n }\n scanner.endChunk(chunk);\n }\n if (scanner.finish()) {\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n }\n }\n\n /**\n * Record a text-after-quote error (fatal).\n * @param line - the line the field started on\n * @param field - the 1-based position of the field in its record\n * @returns never\n */\n badQuote(line: number, field: number): never {\n return this.report.fail(\n BAD_QUOTE_CODE,\n `text after the closing quote of quoted field ${field} (a quote inside a quoted field is written as two quotes)`,\n { line },\n );\n }\n\n /**\n * Record an unclosed-quote error (fatal).\n * @param line - the line the field started on\n * @returns never\n */\n unclosedQuote(line: number): never {\n return this.report.fail(UNCLOSED_QUOTE_CODE, `a quoted field starting on line ${line} is never closed`, {\n line,\n });\n }\n\n /**\n * The decoded text chunks of the input; when the delimiter is to be sniffed, the first rows\n * are buffered (bounded by PREVIEW_ROWS line breaks or PREVIEW_CHARS characters), the sniff\n * runs, and the buffered text is yielded as one chunk before the rest streams through.\n * @yields the text chunks\n * @returns nothing\n */\n private async *chunks(): AsyncGenerator<string, void, undefined> {\n const source = textChunks(this.input, this.report, this.readOptions);\n if (this.delimiterText !== null) {\n yield* source;\n return;\n }\n const pieces: string[] = [];\n let length = 0;\n let breaks = 0;\n let lastWasCr = false;\n let sniffed = false;\n // the leading comment lines are left out of the sniff, so they do not count toward its rows\n const commentCodes = (this.syntax.comments ?? []).map((c) => c.codePointAt(0));\n let leading = commentCodes.length > 0;\n let lineStart = true;\n let inComment = false;\n for await (const chunk of source) {\n if (sniffed) {\n yield chunk;\n continue;\n }\n pieces.push(chunk);\n length += chunk.length;\n for (let i = 0; i < chunk.length && breaks < PREVIEW_ROWS; i++) {\n const c = chunk.charCodeAt(i);\n if (c === LF || c === CR) {\n if (!(c === LF && lastWasCr) && !inComment) {\n breaks++;\n }\n inComment = false;\n lineStart = true;\n } else {\n if (lineStart && leading) {\n inComment = commentCodes.includes(c);\n leading = inComment;\n }\n lineStart = false;\n }\n lastWasCr = c === CR;\n }\n if (breaks < PREVIEW_ROWS && length < PREVIEW_CHARS) {\n continue;\n }\n const text = pieces.join(\"\");\n pieces.length = 0;\n this.sniff(text);\n sniffed = true;\n yield text;\n }\n if (!sniffed) {\n const text = pieces.join(\"\");\n if (text.length > 0) {\n this.sniff(text);\n yield text;\n }\n }\n }\n\n /**\n * Sniff the delimiter from the preview text and record it.\n * @param text - the preview\n */\n private sniff(text: string): void {\n // the sniff is a heuristic over the first rows: a single chunk holding a huge quoted cell\n // is capped so the candidate scans stay bounded\n const preview = text.slice(0, PREVIEW_CHARS);\n const body = stripLeadingComments(preview, this.syntax.comments ?? []);\n if (this.syntax.inspect !== undefined) {\n const skipped = preview.slice(0, preview.length - body.length).match(/\\r\\n|\\r|\\n/g)?.length ?? 0;\n this.syntax.inspect(body, skipped + 1);\n }\n const directive = this.syntax.sepDirective === true ? SEP_DIRECTIVE.exec(text) : null;\n if (directive !== null && directive[1] !== this.syntax.quote) {\n this.delimiterText = directive[1];\n this.sepDirective = true;\n return;\n }\n const candidates = this.syntax.candidates ?? DELIMITER_CANDIDATES;\n this.delimiterText =\n sniffDelimiter(\n body,\n sniffNewline(body),\n candidates,\n this.syntax.quote,\n this.syntax.skipQuoteErrors,\n this.syntax.collapseSpaces,\n ) ?? candidates[0];\n }\n}\n\n/**\n * The record state machine of RecordReader, resumable at every record end so the reader can\n * yield a record before the next one overwrites the shared cell arrays. Every state lives on the\n * instance; `scan()` runs the per-character loop over one chunk from a position and returns where\n * it stopped (after the character that completed a record, with `ready` set, or the chunk end).\n */\nclass RecordScanner {\n /** Whether a record just completed. */\n ready = false;\n\n /** The cell count of the record in progress (the completed one while `ready`). */\n count = 0;\n\n /** The line the completed record started on (valid while `ready`, and after finish()). */\n recordLine = 1;\n\n /** The line the record in progress started on. */\n private startLine = 1;\n\n private readonly reader: RecordReader;\n\n private readonly quoteCode: number;\n\n private readonly quoteText: string;\n\n private readonly commentCodes: readonly number[];\n\n private delimiterCode = -1;\n\n /** The whitespace dialect: the delimiter is a space and RecordSyntax.collapseSpaces is set. */\n private collapse = false;\n\n private state: State = START;\n\n private field = \"\";\n\n private fieldQuoted = false;\n\n private line = 1;\n\n private lastWasCr = false;\n\n /** Whether no record has started yet (comment lines are recognized until one does). */\n private leading: boolean;\n\n private comment = \"\";\n\n /** The start of the unconsumed run of the current chunk that belongs to the field or comment. */\n private segment = 0;\n\n /**\n * Create a scanner over a reader's cell arrays.\n * @param reader - the reader\n */\n constructor(reader: RecordReader) {\n this.reader = reader;\n this.quoteCode = reader.syntax.quote.charCodeAt(0);\n this.quoteText = reader.syntax.quote;\n this.commentCodes = (reader.syntax.comments ?? []).map((c) => c.charCodeAt(0));\n this.leading = this.commentCodes.length > 0;\n }\n\n /**\n * Set the delimiter once it is known (before the first chunk is scanned).\n * @param code - the delimiter's character code\n */\n setDelimiter(code: number): void {\n if (this.delimiterCode < 0) {\n this.delimiterCode = code;\n this.collapse = code === SPACE && this.reader.syntax.collapseSpaces === true;\n }\n }\n\n /**\n * Scan one chunk from a position until a record completes or the chunk ends.\n * @param chunk - the chunk\n * @param from - where to start\n * @returns the position after the last character consumed\n */\n scan(chunk: string, from: number): number {\n const { quoteCode, delimiterCode } = this;\n const n = chunk.length;\n let i = from;\n this.segment = from;\n while (i < n) {\n const c = chunk.charCodeAt(i);\n if (this.state === COMMENT) {\n if (c === LF || c === CR) {\n this.comment = this.grow(this.comment, chunk.slice(this.segment, i));\n this.reader.leadingComments.push(this.comment);\n this.reader.leadingCommentLines.push(this.line);\n this.comment = \"\";\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n }\n i++;\n continue;\n }\n if (this.state === QUOTED) {\n // jump to the next quote; the run in between is field text whose line breaks are counted\n const q = chunk.indexOf(this.quoteText, i);\n const end = q < 0 ? n : q;\n if (end > i) {\n this.countLineBreaks(chunk, i, end);\n }\n if (q < 0) {\n i = n;\n break;\n }\n this.field = this.grow(this.field, chunk.slice(this.segment, q));\n this.state = CLOSING;\n this.lastWasCr = false;\n i = q + 1;\n continue;\n }\n const isDelimiter = c === delimiterCode || (this.collapse && c === TAB);\n if (this.state === CLOSING) {\n if (c === quoteCode) {\n this.field = this.grow(this.field, this.quoteText);\n this.segment = i + 1;\n this.state = QUOTED;\n this.lastWasCr = false;\n i++;\n continue;\n }\n if (!isDelimiter && c !== LF && c !== CR) {\n this.reader.badQuote(this.startLine, this.count + 1);\n }\n this.state = AFTER_QUOTED;\n this.segment = i;\n // fall through to the delimiter / line-end handling below without consuming c\n }\n if (isDelimiter || c === LF || c === CR) {\n if (c === LF && this.lastWasCr) {\n // the second half of a CRLF already ended the record\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n if (this.state === UNQUOTED) {\n this.field = this.grow(this.field, chunk.slice(this.segment, i));\n }\n if (isDelimiter && this.collapse && this.state === START) {\n // a run of whitespace, or indentation: one separator\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n if (isDelimiter) {\n this.push();\n this.state = START;\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n // a line ending right after a whitespace run in the whitespace dialect ends no field\n if (!(this.state === START && (this.count === 0 || this.collapse))) {\n this.push();\n }\n if (this.count > 0) {\n this.ready = true;\n this.recordLine = this.startLine;\n }\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n i++;\n if (this.ready) {\n return i;\n }\n continue;\n }\n this.lastWasCr = false;\n if (this.state === START) {\n if (this.leading && this.count === 0 && this.commentCodes.includes(c)) {\n this.state = COMMENT;\n this.segment = i;\n i++;\n continue;\n }\n this.leading = false;\n if (c === quoteCode) {\n this.state = QUOTED;\n this.fieldQuoted = true;\n this.segment = i + 1;\n } else {\n this.state = UNQUOTED;\n this.segment = i;\n }\n } else if (c === quoteCode && this.state === UNQUOTED && this.reader.strayQuoteLine === 0) {\n this.reader.strayQuoteLine = this.startLine;\n }\n i++;\n }\n return i;\n }\n\n /**\n * Keep the tail of a chunk that belongs to an open field or comment.\n * @param chunk - the chunk just scanned to its end\n */\n endChunk(chunk: string): void {\n const n = chunk.length;\n if (this.segment >= n) {\n return;\n }\n if (this.state === COMMENT) {\n this.comment = this.grow(this.comment, chunk.slice(this.segment, n));\n } else if (this.state === QUOTED || this.state === UNQUOTED) {\n this.field = this.grow(this.field, chunk.slice(this.segment, n));\n }\n this.segment = n;\n }\n\n /**\n * The end of the input: an open comment is kept, an open quote is fatal, an open record\n * (no trailing line break) is completed.\n * @returns true when a last record is ready\n */\n finish(): boolean {\n const { state } = this;\n if (state === COMMENT) {\n this.reader.leadingComments.push(this.comment);\n this.reader.leadingCommentLines.push(this.line);\n return false;\n }\n if (state === QUOTED) {\n this.reader.unclosedQuote(this.startLine);\n }\n if (state !== START || this.count > 0) {\n if (!(state === START && this.collapse)) {\n this.push();\n }\n this.recordLine = this.startLine;\n return true;\n }\n return false;\n }\n\n /**\n * Count the line breaks of a run of quoted text (a CRLF counts once, like the record loop).\n * @param chunk - the chunk\n * @param from - the first index of the run\n * @param to - the index after the run\n */\n private countLineBreaks(chunk: string, from: number, to: number): void {\n // indexOf, not a charCodeAt loop: a quoted cell may be hundreds of MiB, and a per-character\n // loop over it is the whole cost of reading it (and many times that under coverage)\n const run = chunk.slice(from, to);\n let { line } = this;\n // the index of the last CR seen; -1 is a CR just before the run, -2 none\n let lastCr = this.lastWasCr ? -1 : -2;\n let lf = run.indexOf(\"\\n\");\n let cr = run.indexOf(\"\\r\");\n while (lf >= 0 || cr >= 0) {\n if (lf < 0 || (cr >= 0 && cr < lf)) {\n line++;\n lastCr = cr;\n cr = run.indexOf(\"\\r\", cr + 1);\n } else {\n if (lf !== lastCr + 1) {\n line++;\n }\n lf = run.indexOf(\"\\n\", lf + 1);\n }\n }\n this.line = line;\n this.lastWasCr = lastCr === run.length - 1;\n }\n\n /**\n * Append to the field or comment in progress, failing with E_TOO_LARGE instead of a RangeError\n * when the result would be longer than one JavaScript string can hold.\n * @param text - the text so far\n * @param piece - the text to append\n * @returns the joined text\n */\n private grow(text: string, piece: string): string {\n if (text.length + piece.length > MAX_TEXT_LENGTH) {\n tooLarge(\n this.reader.report,\n `a cell is longer than ${MAX_TEXT_LENGTH} characters, the most one JavaScript string holds`,\n this.startLine,\n );\n }\n return text + piece;\n }\n\n /** Store the field in progress as the next cell. */\n private push(): void {\n const { reader, count } = this;\n reader.cells[count] = this.field;\n reader.quoted[count] = this.fieldQuoted;\n this.count = count + 1;\n this.field = \"\";\n this.fieldQuoted = false;\n }\n\n /**\n * Count a line break that ends a record or a comment line.\n * @param c - the LF or CR\n */\n private endLine(c: number): void {\n if (!(c === LF && this.lastWasCr)) {\n this.line++;\n }\n this.startLine = this.line;\n this.lastWasCr = c === CR;\n }\n}\n\n/**\n * What the CSV importer's reader needs besides the input.\n * @category Plugin helpers\n */\nexport interface CsvReaderOptions extends ReadOptions {\n /** The delimiter; null or undefined sniffs it from the preview. */\n readonly delimiter?: string | null | undefined;\n /** The characters opening a leading comment line (RecordSyntax.comments); none by default. */\n readonly comments?: readonly string[] | undefined;\n /** RecordSyntax.skipQuoteErrors; false by default. */\n readonly skipQuoteErrors?: boolean | undefined;\n /** RecordSyntax.inspect; none by default. */\n readonly inspect?: ((preview: string, line: number) => void) | undefined;\n}\n\n/**\n * Records of a CSV input, one string array per row, streamed: iterate with\n * `for await (const row of reader)` and read `reader.line` for the 1-based line the row starts\n * on. The delimiter is known after the first row (`reader.delimiter`). Rows come out as fresh\n * arrays of cell texts exactly as written (no trimming, no typing); `reader.quoted` tells, for\n * the row just yielded, which cells were quoted (a quoted empty cell is the empty string, an\n * unquoted one is \"not set\"). Blank lines, whitespace-only lines and rows of empty unquoted cells\n * are skipped. A space delimiter reads the whitespace dialect (RecordSyntax.collapseSpaces), and an\n * Excel `sep=X` first line names the delimiter when none is given.\n * @category Plugin helpers\n */\nexport class CsvRecordReader implements AsyncIterable<string[]> {\n private readonly inner: RecordReader;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input\n * @param report - the report parse errors are recorded in\n * @param options - the delimiter, cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, options: CsvReaderOptions = {}) {\n this.inner = new RecordReader(\n input,\n report,\n {\n delimiter: options.delimiter ?? null,\n quote: '\"',\n comments: options.comments,\n skipQuoteErrors: options.skipQuoteErrors,\n collapseSpaces: true,\n sepDirective: true,\n inspect: options.inspect,\n },\n {\n signal: options.signal,\n onProgress: options.onProgress,\n encoding: options.encoding,\n allowEmpty: options.allowEmpty,\n nulIsBinary: true,\n },\n );\n }\n\n /**\n * The leading comment lines the reader skipped (SNAP `#` lines, the KONECT `%` header), in order.\n * @returns the lines without their line breaks\n */\n get leadingComments(): readonly string[] {\n return this.inner.leadingComments;\n }\n\n /**\n * The 1-based line of each leading comment, parallel to `leadingComments`.\n * @returns the lines\n */\n get leadingCommentLines(): readonly number[] {\n return this.inner.leadingCommentLines;\n }\n\n /**\n * The 1-based line the most recently yielded row starts on.\n * @returns the line; 0 before the first row\n */\n get line(): number {\n return this.inner.line;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.inner.delimiter;\n }\n\n /**\n * Whether each cell of the row most recently yielded was quoted.\n * @returns the flags (valid for the first `row.length` entries)\n */\n get quoted(): readonly boolean[] {\n return this.inner.quoted;\n }\n\n /**\n * The line of the first quote inside an unquoted field.\n * @returns the line, or 0 when there was none\n */\n get strayQuoteLine(): number {\n return this.inner.strayQuoteLine;\n }\n\n /**\n * Whether the first record is an Excel `sep=X` line the delimiter was taken from.\n * @returns true when it is\n */\n get sepDirective(): boolean {\n return this.inner.sepDirective;\n }\n\n /**\n * Iterate the rows.\n * @yields one row at a time as its cell texts\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<string[], void, undefined> {\n const { inner } = this;\n for await (const count of inner) {\n if (isBlankRecord(inner.cells, inner.quoted, count)) {\n continue;\n }\n yield inner.cells.slice(0, count);\n }\n }\n}\n\n/**\n * Whether a record holds nothing: every cell unquoted and blank (a blank line, a whitespace-only\n * line, or an Excel empty row `,,,`). A quoted empty cell is a value.\n * @param cells - the cells\n * @param quoted - whether each was quoted\n * @param count - the cell count\n * @returns true when the record carries no value\n */\nfunction isBlankRecord(cells: readonly string[], quoted: readonly boolean[], count: number): boolean {\n for (let k = 0; k < count; k++) {\n if (quoted[k] || cells[k].trim().length > 0) {\n return false;\n }\n }\n return true;\n}\n"],"names":[],"mappings":";;AA0BO,MAAM,sBA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cAAc,MAAM,OAAO,MAAM,QAAQ,KAAK,GAAG;AACjD;AAAA,MACJ;AACA,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK;AAAA,IACpC;AAAA,EACJ;AACJ;AAUA,SAAS,cAAc,OAA0B,QAA4B,OAAwB;AACjG,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK;AAC5B,QAAI,OAAO,CAAC,KAAK,MAAM,CAAC,EAAE,KAAA,EAAO,SAAS,GAAG;AACzC,aAAO;AAAA,IACX;AAAA,EACJ;AACA,SAAO;AACX;"}
|
|
1
|
+
{"version":3,"file":"records-BrfHycmg.js","sources":["../../src/formats/csv/records.ts"],"sourcesContent":["/**\n * The one streaming CSV record reader of the package (design sections 8.2 and 8.4: hand-written\n * tokenisers per format; CSV and Neo4j CSV are line-oriented over a byte stream): RFC 4180 records\n * with a configurable single-character delimiter and quote, a doubled quote inside a quoted field,\n * quoted fields spanning lines, LF / CRLF / lone-CR terminators, read from the common text reader\n * one chunk at a time as a character state machine. Only the open field is ever held, so a field\n * spanning many chunks costs its length once and a multi-gigabyte file is never buffered.\n *\n * `RecordReader` (used by the Neo4j importer) keeps one reusable cell array and one reusable\n * \"was quoted\" array: a quoted empty field (`\"\"`) is an empty string while an unquoted empty field\n * means \"not set\", and only the tokeniser can tell the two apart. `CsvRecordReader` (the CSV\n * importer) wraps it with delimiter sniffing over a bounded preview and yields a fresh cell array\n * per row. A malformed quoted field is fatal for both: an unterminated quote swallows the rest of\n * the file, and text after a closing quote makes every later cell boundary unreliable.\n */\n\nimport { GraphFormatError } from \"@graphty/graph-format\";\n\nimport { MAX_TEXT_LENGTH, type ReadOptions, textChunks, tooLarge } from \"../../common/input.js\";\nimport { type ImportReportBuilder } from \"../../common/report.js\";\nimport { type ImportInput } from \"../../types.js\";\n\n/**\n * A quoted field is never closed; the import aborts (everything after it would be one cell).\n * @category Issue and loss codes\n */\nexport const UNCLOSED_QUOTE_CODE = \"E_CSV_UNCLOSED_QUOTE\";\n\n/**\n * A closing quote is followed by text other than a delimiter or a line break; the import aborts.\n * @category Issue and loss codes\n */\nexport const BAD_QUOTE_CODE = \"E_CSV_QUOTE\";\n\n/**\n * The delimiters tried, in priority order, when none is given.\n * @category Plugin helpers\n */\nexport const DELIMITER_CANDIDATES: readonly string[] = Object.freeze([\",\", \"\\t\", \";\", \"|\", \" \"]);\n\n/** Rows the delimiter sniff looks at. */\nconst PREVIEW_ROWS = 10;\n\n/** Characters buffered for the sniff when the input has fewer than PREVIEW_ROWS line breaks. */\nconst PREVIEW_CHARS = 64 * 1024;\n\nconst LF = 10;\nconst CR = 13;\nconst TAB = 9;\nconst SPACE = 32;\n\n/** An Excel delimiter directive: a first line `sep=;` names the delimiter and is not a record. */\nconst SEP_DIRECTIVE = /^sep=([^\\r\\n])(?:\\r\\n|\\n|\\r|$)/i;\n\n/** Tokeniser state: at the start of a field. */\nconst START = 0;\n/** Tokeniser state: inside an unquoted field. */\nconst UNQUOTED = 1;\n/** Tokeniser state: inside a quoted field. */\nconst QUOTED = 2;\n/** Tokeniser state: just after a quote inside a quoted field (a second quote is a literal, anything else ends the field). */\nconst CLOSING = 3;\n/** Tokeniser state: after a closed quoted field, before the delimiter (text here is malformed). */\nconst AFTER_QUOTED = 4;\n/** Inside a leading comment line (skipped up to its line break). */\nconst COMMENT = 5;\n\ntype State = typeof START | typeof UNQUOTED | typeof QUOTED | typeof CLOSING | typeof AFTER_QUOTED | typeof COMMENT;\n\n/**\n * The delimiter and quote of a reader.\n * @category Plugin helpers\n */\nexport interface RecordSyntax {\n /** The field delimiter, one character; null sniffs it from the first rows. */\n readonly delimiter: string | null;\n /** The quote character, one character. */\n readonly quote: string;\n /** The delimiters tried when `delimiter` is null; DELIMITER_CANDIDATES by default. */\n readonly candidates?: readonly string[] | undefined;\n /**\n * Characters that open a comment line while no record has been read yet (SNAP `#`, KONECT\n * `%`): such leading lines are skipped, kept in `leadingComments` and left out of the delimiter\n * sniff. A later line starting with one of them is an ordinary record. Default: none.\n */\n readonly comments?: readonly string[] | undefined;\n /**\n * Whether the delimiter sniff skips a candidate under which a closing quote is followed by\n * other text (see sniffDelimiter). False by default: that text then aborts the read.\n */\n readonly skipQuoteErrors?: boolean | undefined;\n /**\n * Whether a space delimiter means the whitespace dialect of SNAP / KONECT edge lists: any run of\n * spaces and tabs separates two fields, and whitespace at the start and end of a line is\n * ignored. False by default (every space is a delimiter).\n */\n readonly collapseSpaces?: boolean | undefined;\n /** Whether an Excel `sep=X` first line names the delimiter for the sniff. False by default. */\n readonly sepDirective?: boolean | undefined;\n /**\n * Called with the sniff preview (leading comment lines removed) and the line it starts on,\n * before any record is scanned, so a caller can refuse input that is not delimited text at all.\n * Only called when the delimiter is sniffed.\n */\n readonly inspect?: ((preview: string, line: number) => void) | undefined;\n}\n\n/**\n * Check a delimiter or quote option: exactly one character that is not a line break, and the two\n * must differ.\n * @param syntax - the delimiter (or null for sniffing) and quote\n * @returns the syntax unchanged; E_UNSUPPORTED when invalid\n * @category Plugin helpers\n */\nexport function checkRecordSyntax(syntax: RecordSyntax): RecordSyntax {\n for (const [option, value] of [\n [\"delimiter\", syntax.delimiter],\n [\"quote\", syntax.quote],\n ] as const) {\n if (value === null) {\n continue;\n }\n if (value.length !== 1 || value === \"\\n\" || value === \"\\r\") {\n throw new GraphFormatError(\n \"E_UNSUPPORTED\",\n `option ${option}: ${JSON.stringify(value)} is not a single non-line-break character`,\n { option, found: value },\n );\n }\n }\n if (syntax.delimiter !== null && syntax.delimiter === syntax.quote) {\n throw new GraphFormatError(\"E_UNSUPPORTED\", \"options delimiter and quote must differ\", {\n option: \"delimiter\",\n found: syntax.delimiter,\n });\n }\n return syntax;\n}\n\n/**\n * Sniff the line terminator of a text: a lone `\\r` only when the text has `\\r` and no `\\n` at all\n * (classic Mac files); `\\n` otherwise.\n * @param text - the preview text\n * @returns \"\\n\" or \"\\r\"\n * @category Plugin helpers\n */\nexport function sniffNewline(text: string): \"\\n\" | \"\\r\" {\n return !text.includes(\"\\n\") && text.includes(\"\\r\") ? \"\\r\" : \"\\n\";\n}\n\n/**\n * Split a text into records synchronously (the first `maxRows` of them), honoring quotes; for\n * the delimiter sniff and the registry's head sniff, where the input is a bounded preview.\n * @param text - the text\n * @param delimiter - the delimiter\n * @param quote - the quote character\n * @param maxRows - the most rows to return\n * @param strictQuotes - return null when a closing quote is followed by text other than the\n * delimiter or a line break (the import would abort under this delimiter)\n * @param collapse - the whitespace dialect (RecordSyntax.collapseSpaces) for a space delimiter\n * @returns the rows as cell arrays (blank lines skipped), or null (see strictQuotes)\n * @category Plugin helpers\n */\nexport function splitRecords(\n text: string,\n delimiter: string,\n quote: string,\n maxRows: number,\n strictQuotes = false,\n collapse = false,\n): string[][] | null {\n const delimiterCode = delimiter.codePointAt(0);\n const splitter = new RecordSplitter(text, quote, delimiterCode, collapse && delimiterCode === SPACE, strictQuotes);\n let i = 0;\n while (i < text.length && splitter.rows.length < maxRows) {\n i = splitter.step(i);\n if (i < 0) {\n return null;\n }\n }\n if (splitter.rows.length < maxRows) {\n splitter.finish();\n }\n return splitter.rows;\n}\n\n/** The state machine of splitRecords(): one character at a time, quotes honored. */\nclass RecordSplitter {\n /** The rows read so far. */\n readonly rows: string[][] = [];\n\n private cells: string[] = [];\n\n private state: State = START;\n\n /** Where the unread part of the current field starts. */\n private segment = 0;\n\n private field = \"\";\n\n private readonly quoteCode: number | undefined;\n\n /**\n * Create a splitter.\n * @param text - the text\n * @param quote - the quote character\n * @param delimiterCode - the delimiter's code\n * @param whitespace - whether runs of spaces and tabs are one separator\n * @param strictQuotes - whether text after a closing quote gives up\n */\n constructor(\n private readonly text: string,\n private readonly quote: string,\n private readonly delimiterCode: number | undefined,\n private readonly whitespace: boolean,\n private readonly strictQuotes: boolean,\n ) {\n this.quoteCode = quote.codePointAt(0);\n }\n\n /**\n * Read one character.\n * @param i - its index\n * @returns the index of the next character to read, or -1 to give up (strictQuotes)\n */\n step(i: number): number {\n const c = this.text.codePointAt(i);\n if (this.state === QUOTED) {\n if (c === this.quoteCode) {\n this.field += this.text.slice(this.segment, i);\n this.state = CLOSING;\n }\n return i + 1;\n }\n const isDelimiter = c === this.delimiterCode || (this.whitespace && c === TAB);\n if (this.state === CLOSING) {\n const next = this.afterQuote(i, c, isDelimiter || c === LF || c === CR);\n if (next !== null) {\n return next;\n }\n }\n if (isDelimiter || c === LF || c === CR) {\n return this.separator(i, isDelimiter);\n }\n if (this.state === START) {\n const quoted = c === this.quoteCode;\n this.state = quoted ? QUOTED : UNQUOTED;\n this.segment = quoted ? i + 1 : i;\n }\n return i + 1;\n }\n\n /**\n * Read the character after a quote that may close a quoted field: a second quote is a quote\n * character in the field; anything else closes it.\n * @param i - its index\n * @param c - its code\n * @param separates - whether it is a delimiter or a line break\n * @returns the index of the next character to read, -1 to give up (strictQuotes), or null to\n * read this character as the one after the field\n */\n private afterQuote(i: number, c: number | undefined, separates: boolean): number | null {\n if (c === this.quoteCode) {\n this.field += this.quote;\n this.segment = i + 1;\n this.state = QUOTED;\n return i + 1;\n }\n if (this.strictQuotes && !separates) {\n return -1;\n }\n this.state = AFTER_QUOTED;\n this.segment = i;\n return null;\n }\n\n /**\n * Read a delimiter or a line break: end the field, and at a line break the row.\n * @param i - its index\n * @param isDelimiter - whether it is a delimiter\n * @returns the index of the next character to read\n */\n private separator(i: number, isDelimiter: boolean): number {\n if (this.state === UNQUOTED || this.state === AFTER_QUOTED) {\n this.field += this.text.slice(this.segment, i);\n }\n let next = i + 1;\n if (isDelimiter && this.whitespace && this.state === START) {\n // a run of whitespace, or indentation: one separator\n } else if (isDelimiter) {\n this.cells.push(this.field);\n this.field = \"\";\n this.state = START;\n } else {\n this.endRow();\n this.state = START;\n if (this.text.codePointAt(i) === CR && this.text.codePointAt(i + 1) === LF) {\n next = i + 2;\n }\n }\n this.segment = next;\n return next;\n }\n\n /** End the row at a line break; a blank line is no row. */\n private endRow(): void {\n if (this.state === START && this.cells.length === 0) {\n return;\n }\n if (!(this.whitespace && this.state === START)) {\n this.cells.push(this.field);\n }\n this.rows.push(this.cells);\n this.cells = [];\n this.field = \"\";\n }\n\n /** End the text: the last row, when it has no line break after it. */\n finish(): void {\n if (this.state === START && this.cells.length === 0) {\n return;\n }\n if (this.state === UNQUOTED || this.state === AFTER_QUOTED || this.state === QUOTED) {\n this.field += this.text.slice(this.segment);\n }\n if (!(this.whitespace && this.state === START)) {\n this.cells.push(this.field);\n }\n this.rows.push(this.cells);\n }\n}\n\n/**\n * The preview text without its leading comment lines (those starting with one of the comment\n * characters), so the sniff sees the records only.\n * @param text - the preview text\n * @param comments - the comment characters\n * @returns the text from the first non-comment line on\n * @category Plugin helpers\n */\nexport function stripLeadingComments(text: string, comments: readonly string[]): string {\n if (comments.length === 0) {\n return text;\n }\n let at = 0;\n while (at < text.length) {\n if (text[at] === \"\\n\" || text[at] === \"\\r\") {\n // a blank line among the leading comments (the scanner skips it too)\n at++;\n continue;\n }\n if (!comments.includes(text[at])) {\n break;\n }\n const lf = text.indexOf(\"\\n\", at);\n const cr = text.indexOf(\"\\r\", at);\n const end = Math.min(lf < 0 ? Infinity : lf, cr < 0 ? Infinity : cr);\n if (end === Infinity) {\n return \"\";\n }\n at = end;\n }\n return at === 0 ? text : text.slice(at);\n}\n\n/**\n * Sniff the delimiter of a text: every candidate is tried over the first rows and the one whose\n * field count is most consistent across rows wins (a tie goes to the earlier candidate, so a\n * space inside comma-separated cells never beats the comma); a\n * candidate that yields fewer than two fields per row on average is never chosen. `null` when no\n * candidate qualifies (a single-column file).\n * @param text - the preview text\n * @param newline - the sniffed line terminator (unused by the splitter, which reads every kind;\n * kept for callers that sniffed it)\n * @param candidates - the delimiters to try, in priority order\n * @param quote - the quote character\n * @param skipQuoteErrors - also never choose a candidate under which a closing quote is followed\n * by other text. Only for inputs whose field counts say nothing (an adjacency table's rows vary in\n * width): elsewhere a stray character after a quote would make a worse candidate win silently\n * instead of aborting the read\n * @param collapse - read a space candidate in the whitespace dialect (RecordSyntax.collapseSpaces)\n * @returns the delimiter, or null\n * @category Plugin helpers\n */\nexport function sniffDelimiter(\n text: string,\n newline: \"\\n\" | \"\\r\" = \"\\n\",\n candidates: readonly string[] = DELIMITER_CANDIDATES,\n quote = '\"',\n skipQuoteErrors = false,\n collapse = false,\n): string | null {\n let best: string | null = null;\n let bestDelta = Infinity;\n const terminated = text.endsWith(\"\\n\") || text.endsWith(\"\\r\");\n for (const delimiter of candidates) {\n if (delimiter === quote || delimiter === newline) {\n continue;\n }\n const split = splitRecords(text, delimiter, quote, PREVIEW_ROWS, skipQuoteErrors, collapse);\n if (split === null) {\n // a quoted cell this delimiter does not close: it is not the file's delimiter\n continue;\n }\n let rows = split.filter((row) => !isBlankRow(row));\n if (rows.length > 1 && !terminated) {\n // the preview is a prefix of the file: its last row may be cut short\n rows = rows.slice(0, -1);\n }\n if (rows.length === 0) {\n continue;\n }\n let total = 0;\n let delta = 0;\n for (let i = 0; i < rows.length; i++) {\n const count = rows[i].length;\n total += count;\n if (i > 0) {\n delta += Math.abs(count - rows[i - 1].length);\n }\n }\n const average = total / rows.length;\n if (average > 1.99 && delta < bestDelta) {\n best = delimiter;\n bestDelta = delta;\n }\n }\n return best;\n}\n\n/**\n * Whether a parsed row is a blank line: one cell holding only whitespace.\n * @param row - the row\n * @returns true for a blank line\n */\nfunction isBlankRow(row: readonly string[]): boolean {\n return row.length === 1 && row[0].trim().length === 0;\n}\n\n/**\n * Reads the records of one input. Iterate with `for await (const count of reader)`: each\n * iteration fills `reader.cells[0..count)` and `reader.quoted[0..count)` and sets `reader.line`\n * to the 1-based line the record started on. Blank lines (an empty unquoted record of one field)\n * are skipped. The arrays are reused between records. When the syntax gives no delimiter, the\n * first rows (PREVIEW_ROWS, or PREVIEW_CHARS characters) are buffered and the delimiter sniffed\n * from them before the first record is yielded.\n * @category Plugin helpers\n */\nexport class RecordReader implements AsyncIterable<number> {\n /** The cells of the record most recently yielded; only the first `count` entries are valid. */\n readonly cells: string[] = [];\n\n /** Whether each cell of the record most recently yielded was quoted. */\n readonly quoted: boolean[] = [];\n\n /** The leading comment lines (without their line breaks), in order; empty without `syntax.comments`. */\n readonly leadingComments: string[] = [];\n\n /** The 1-based line of each leading comment, parallel to `leadingComments`. */\n readonly leadingCommentLines: number[] = [];\n\n /** The line of the first quote inside an unquoted field (kept as text, RFC 4180 forbids it); 0 for none. */\n strayQuoteLine = 0;\n\n /** Whether the sniff took the delimiter from an Excel `sep=X` first line (yielded as the first record). */\n sepDirective = false;\n\n private readonly input: ImportInput;\n\n readonly report: ImportReportBuilder;\n\n private readonly readOptions: ReadOptions;\n\n /** The delimiter (null while unsniffed), quote and comment characters. */\n readonly syntax: RecordSyntax;\n\n private delimiterText: string | null;\n\n private recordLine = 0;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input (or an async iterable of already decoded text chunks)\n * @param report - the report decode and quoting errors are recorded in\n * @param syntax - the delimiter (null to sniff) and quote (already checked)\n * @param readOptions - cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, syntax: RecordSyntax, readOptions: ReadOptions) {\n this.input = input;\n this.report = report;\n this.readOptions = readOptions;\n this.syntax = syntax;\n this.delimiterText = syntax.delimiter;\n }\n\n /**\n * The 1-based line the most recently yielded record started on.\n * @returns the line number; 0 before the first record\n */\n get line(): number {\n return this.recordLine;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.delimiterText;\n }\n\n /**\n * Iterate the records.\n * @yields the number of cells of each record\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<number, void, undefined> {\n const scanner = new RecordScanner(this);\n for await (const chunk of this.chunks()) {\n // the first chunk arrives after the sniff (or with the given delimiter)\n scanner.setDelimiter((this.delimiterText ?? \",\").charCodeAt(0));\n let i = 0;\n while (i < chunk.length) {\n i = scanner.scan(chunk, i);\n if (scanner.ready) {\n scanner.ready = false;\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n scanner.count = 0;\n }\n }\n scanner.endChunk(chunk);\n }\n if (scanner.finish()) {\n this.recordLine = scanner.recordLine;\n yield scanner.count;\n }\n }\n\n /**\n * Record a text-after-quote error (fatal).\n * @param line - the line the field started on\n * @param field - the 1-based position of the field in its record\n * @returns never\n */\n badQuote(line: number, field: number): never {\n return this.report.fail(\n BAD_QUOTE_CODE,\n `text after the closing quote of quoted field ${field} (a quote inside a quoted field is written as two quotes)`,\n { line },\n );\n }\n\n /**\n * Record an unclosed-quote error (fatal).\n * @param line - the line the field started on\n * @returns never\n */\n unclosedQuote(line: number): never {\n return this.report.fail(UNCLOSED_QUOTE_CODE, `a quoted field starting on line ${line} is never closed`, {\n line,\n });\n }\n\n /**\n * The decoded text chunks of the input; when the delimiter is to be sniffed, the first rows\n * are buffered (bounded by PREVIEW_ROWS line breaks or PREVIEW_CHARS characters), the sniff\n * runs, and the buffered text is yielded as one chunk before the rest streams through.\n * @yields the text chunks\n * @returns nothing\n */\n private async *chunks(): AsyncGenerator<string, void, undefined> {\n const source = textChunks(this.input, this.report, this.readOptions);\n if (this.delimiterText !== null) {\n yield* source;\n return;\n }\n const pieces: string[] = [];\n let length = 0;\n let breaks = 0;\n let lastWasCr = false;\n let sniffed = false;\n // the leading comment lines are left out of the sniff, so they do not count toward its rows\n const commentCodes = (this.syntax.comments ?? []).map((c) => c.codePointAt(0));\n let leading = commentCodes.length > 0;\n let lineStart = true;\n let inComment = false;\n for await (const chunk of source) {\n if (sniffed) {\n yield chunk;\n continue;\n }\n pieces.push(chunk);\n length += chunk.length;\n for (let i = 0; i < chunk.length && breaks < PREVIEW_ROWS; i++) {\n const c = chunk.charCodeAt(i);\n if (c === LF || c === CR) {\n if (!(c === LF && lastWasCr) && !inComment) {\n breaks++;\n }\n inComment = false;\n lineStart = true;\n } else {\n if (lineStart && leading) {\n inComment = commentCodes.includes(c);\n leading = inComment;\n }\n lineStart = false;\n }\n lastWasCr = c === CR;\n }\n if (breaks < PREVIEW_ROWS && length < PREVIEW_CHARS) {\n continue;\n }\n const text = pieces.join(\"\");\n pieces.length = 0;\n this.sniff(text);\n sniffed = true;\n yield text;\n }\n if (!sniffed) {\n const text = pieces.join(\"\");\n if (text.length > 0) {\n this.sniff(text);\n yield text;\n }\n }\n }\n\n /**\n * Sniff the delimiter from the preview text and record it.\n * @param text - the preview\n */\n private sniff(text: string): void {\n // the sniff is a heuristic over the first rows: a single chunk holding a huge quoted cell\n // is capped so the candidate scans stay bounded\n const preview = text.slice(0, PREVIEW_CHARS);\n const body = stripLeadingComments(preview, this.syntax.comments ?? []);\n if (this.syntax.inspect !== undefined) {\n const skipped = preview.slice(0, preview.length - body.length).match(/\\r\\n|\\r|\\n/g)?.length ?? 0;\n this.syntax.inspect(body, skipped + 1);\n }\n const directive = this.syntax.sepDirective === true ? SEP_DIRECTIVE.exec(text) : null;\n if (directive !== null && directive[1] !== this.syntax.quote) {\n this.delimiterText = directive[1];\n this.sepDirective = true;\n return;\n }\n const candidates = this.syntax.candidates ?? DELIMITER_CANDIDATES;\n this.delimiterText =\n sniffDelimiter(\n body,\n sniffNewline(body),\n candidates,\n this.syntax.quote,\n this.syntax.skipQuoteErrors,\n this.syntax.collapseSpaces,\n ) ?? candidates[0];\n }\n}\n\n/**\n * The record state machine of RecordReader, resumable at every record end so the reader can\n * yield a record before the next one overwrites the shared cell arrays. Every state lives on the\n * instance; `scan()` runs the per-character loop over one chunk from a position and returns where\n * it stopped (after the character that completed a record, with `ready` set, or the chunk end).\n */\nclass RecordScanner {\n /** Whether a record just completed. */\n ready = false;\n\n /** The cell count of the record in progress (the completed one while `ready`). */\n count = 0;\n\n /** The line the completed record started on (valid while `ready`, and after finish()). */\n recordLine = 1;\n\n /** The line the record in progress started on. */\n private startLine = 1;\n\n private readonly reader: RecordReader;\n\n private readonly quoteCode: number;\n\n private readonly quoteText: string;\n\n private readonly commentCodes: readonly number[];\n\n private delimiterCode = -1;\n\n /** The whitespace dialect: the delimiter is a space and RecordSyntax.collapseSpaces is set. */\n private collapse = false;\n\n private state: State = START;\n\n private field = \"\";\n\n private fieldQuoted = false;\n\n private line = 1;\n\n private lastWasCr = false;\n\n /** Whether no record has started yet (comment lines are recognized until one does). */\n private leading: boolean;\n\n private comment = \"\";\n\n /** The start of the unconsumed run of the current chunk that belongs to the field or comment. */\n private segment = 0;\n\n /**\n * Create a scanner over a reader's cell arrays.\n * @param reader - the reader\n */\n constructor(reader: RecordReader) {\n this.reader = reader;\n this.quoteCode = reader.syntax.quote.charCodeAt(0);\n this.quoteText = reader.syntax.quote;\n this.commentCodes = (reader.syntax.comments ?? []).map((c) => c.charCodeAt(0));\n this.leading = this.commentCodes.length > 0;\n }\n\n /**\n * Set the delimiter once it is known (before the first chunk is scanned).\n * @param code - the delimiter's character code\n */\n setDelimiter(code: number): void {\n if (this.delimiterCode < 0) {\n this.delimiterCode = code;\n this.collapse = code === SPACE && this.reader.syntax.collapseSpaces === true;\n }\n }\n\n /**\n * Scan one chunk from a position until a record completes or the chunk ends.\n * @param chunk - the chunk\n * @param from - where to start\n * @returns the position after the last character consumed\n */\n scan(chunk: string, from: number): number {\n const { quoteCode, delimiterCode } = this;\n const n = chunk.length;\n let i = from;\n this.segment = from;\n while (i < n) {\n const c = chunk.charCodeAt(i);\n if (this.state === COMMENT) {\n if (c === LF || c === CR) {\n this.comment = this.grow(this.comment, chunk.slice(this.segment, i));\n this.reader.leadingComments.push(this.comment);\n this.reader.leadingCommentLines.push(this.line);\n this.comment = \"\";\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n }\n i++;\n continue;\n }\n if (this.state === QUOTED) {\n // jump to the next quote; the run in between is field text whose line breaks are counted\n const q = chunk.indexOf(this.quoteText, i);\n const end = q < 0 ? n : q;\n if (end > i) {\n this.countLineBreaks(chunk, i, end);\n }\n if (q < 0) {\n i = n;\n break;\n }\n this.field = this.grow(this.field, chunk.slice(this.segment, q));\n this.state = CLOSING;\n this.lastWasCr = false;\n i = q + 1;\n continue;\n }\n const isDelimiter = c === delimiterCode || (this.collapse && c === TAB);\n if (this.state === CLOSING) {\n if (c === quoteCode) {\n this.field = this.grow(this.field, this.quoteText);\n this.segment = i + 1;\n this.state = QUOTED;\n this.lastWasCr = false;\n i++;\n continue;\n }\n if (!isDelimiter && c !== LF && c !== CR) {\n this.reader.badQuote(this.startLine, this.count + 1);\n }\n this.state = AFTER_QUOTED;\n this.segment = i;\n // fall through to the delimiter / line-end handling below without consuming c\n }\n if (isDelimiter || c === LF || c === CR) {\n if (c === LF && this.lastWasCr) {\n // the second half of a CRLF already ended the record\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n if (this.state === UNQUOTED) {\n this.field = this.grow(this.field, chunk.slice(this.segment, i));\n }\n if (isDelimiter && this.collapse && this.state === START) {\n // a run of whitespace, or indentation: one separator\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n if (isDelimiter) {\n this.push();\n this.state = START;\n this.lastWasCr = false;\n this.segment = i + 1;\n i++;\n continue;\n }\n // a line ending right after a whitespace run in the whitespace dialect ends no field\n if (!(this.state === START && (this.count === 0 || this.collapse))) {\n this.push();\n }\n if (this.count > 0) {\n this.ready = true;\n this.recordLine = this.startLine;\n }\n this.state = START;\n this.endLine(c);\n this.segment = i + 1;\n i++;\n if (this.ready) {\n return i;\n }\n continue;\n }\n this.lastWasCr = false;\n if (this.state === START) {\n if (this.leading && this.count === 0 && this.commentCodes.includes(c)) {\n this.state = COMMENT;\n this.segment = i;\n i++;\n continue;\n }\n this.leading = false;\n if (c === quoteCode) {\n this.state = QUOTED;\n this.fieldQuoted = true;\n this.segment = i + 1;\n } else {\n this.state = UNQUOTED;\n this.segment = i;\n }\n } else if (c === quoteCode && this.state === UNQUOTED && this.reader.strayQuoteLine === 0) {\n this.reader.strayQuoteLine = this.startLine;\n }\n i++;\n }\n return i;\n }\n\n /**\n * Keep the tail of a chunk that belongs to an open field or comment.\n * @param chunk - the chunk just scanned to its end\n */\n endChunk(chunk: string): void {\n const n = chunk.length;\n if (this.segment >= n) {\n return;\n }\n if (this.state === COMMENT) {\n this.comment = this.grow(this.comment, chunk.slice(this.segment, n));\n } else if (this.state === QUOTED || this.state === UNQUOTED) {\n this.field = this.grow(this.field, chunk.slice(this.segment, n));\n }\n this.segment = n;\n }\n\n /**\n * The end of the input: an open comment is kept, an open quote is fatal, an open record\n * (no trailing line break) is completed.\n * @returns true when a last record is ready\n */\n finish(): boolean {\n const { state } = this;\n if (state === COMMENT) {\n this.reader.leadingComments.push(this.comment);\n this.reader.leadingCommentLines.push(this.line);\n return false;\n }\n if (state === QUOTED) {\n this.reader.unclosedQuote(this.startLine);\n }\n if (state !== START || this.count > 0) {\n if (!(state === START && this.collapse)) {\n this.push();\n }\n this.recordLine = this.startLine;\n return true;\n }\n return false;\n }\n\n /**\n * Count the line breaks of a run of quoted text (a CRLF counts once, like the record loop).\n * @param chunk - the chunk\n * @param from - the first index of the run\n * @param to - the index after the run\n */\n private countLineBreaks(chunk: string, from: number, to: number): void {\n // indexOf, not a charCodeAt loop: a quoted cell may be hundreds of MiB, and a per-character\n // loop over it is the whole cost of reading it (and many times that under coverage)\n const run = chunk.slice(from, to);\n let { line } = this;\n // the index of the last CR seen; -1 is a CR just before the run, -2 none\n let lastCr = this.lastWasCr ? -1 : -2;\n let lf = run.indexOf(\"\\n\");\n let cr = run.indexOf(\"\\r\");\n while (lf >= 0 || cr >= 0) {\n if (lf < 0 || (cr >= 0 && cr < lf)) {\n line++;\n lastCr = cr;\n cr = run.indexOf(\"\\r\", cr + 1);\n } else {\n if (lf !== lastCr + 1) {\n line++;\n }\n lf = run.indexOf(\"\\n\", lf + 1);\n }\n }\n this.line = line;\n this.lastWasCr = lastCr === run.length - 1;\n }\n\n /**\n * Append to the field or comment in progress, failing with E_TOO_LARGE instead of a RangeError\n * when the result would be longer than one JavaScript string can hold.\n * @param text - the text so far\n * @param piece - the text to append\n * @returns the joined text\n */\n private grow(text: string, piece: string): string {\n if (text.length + piece.length > MAX_TEXT_LENGTH) {\n tooLarge(\n this.reader.report,\n `a cell is longer than ${MAX_TEXT_LENGTH} characters, the most one JavaScript string holds`,\n this.startLine,\n );\n }\n return text + piece;\n }\n\n /** Store the field in progress as the next cell. */\n private push(): void {\n const { reader, count } = this;\n reader.cells[count] = this.field;\n reader.quoted[count] = this.fieldQuoted;\n this.count = count + 1;\n this.field = \"\";\n this.fieldQuoted = false;\n }\n\n /**\n * Count a line break that ends a record or a comment line.\n * @param c - the LF or CR\n */\n private endLine(c: number): void {\n if (!(c === LF && this.lastWasCr)) {\n this.line++;\n }\n this.startLine = this.line;\n this.lastWasCr = c === CR;\n }\n}\n\n/**\n * What the CSV importer's reader needs besides the input.\n * @category Plugin helpers\n */\nexport interface CsvReaderOptions extends ReadOptions {\n /** The delimiter; null or undefined sniffs it from the preview. */\n readonly delimiter?: string | null | undefined;\n /** The characters opening a leading comment line (RecordSyntax.comments); none by default. */\n readonly comments?: readonly string[] | undefined;\n /** RecordSyntax.skipQuoteErrors; false by default. */\n readonly skipQuoteErrors?: boolean | undefined;\n /** RecordSyntax.inspect; none by default. */\n readonly inspect?: ((preview: string, line: number) => void) | undefined;\n}\n\n/**\n * Records of a CSV input, one string array per row, streamed: iterate with\n * `for await (const row of reader)` and read `reader.line` for the 1-based line the row starts\n * on. The delimiter is known after the first row (`reader.delimiter`). Rows come out as fresh\n * arrays of cell texts exactly as written (no trimming, no typing); `reader.quoted` tells, for\n * the row just yielded, which cells were quoted (a quoted empty cell is the empty string, an\n * unquoted one is \"not set\"). Blank lines, whitespace-only lines and rows of empty unquoted cells\n * are skipped. A space delimiter reads the whitespace dialect (RecordSyntax.collapseSpaces), and an\n * Excel `sep=X` first line names the delimiter when none is given.\n * @category Plugin helpers\n */\nexport class CsvRecordReader implements AsyncIterable<string[]> {\n private readonly inner: RecordReader;\n\n /**\n * Create a reader; nothing is read until iteration starts.\n * @param input - the input\n * @param report - the report parse errors are recorded in\n * @param options - the delimiter, cancellation and progress\n */\n constructor(input: ImportInput, report: ImportReportBuilder, options: CsvReaderOptions = {}) {\n this.inner = new RecordReader(\n input,\n report,\n {\n delimiter: options.delimiter ?? null,\n quote: '\"',\n comments: options.comments,\n skipQuoteErrors: options.skipQuoteErrors,\n collapseSpaces: true,\n sepDirective: true,\n inspect: options.inspect,\n },\n {\n signal: options.signal,\n onProgress: options.onProgress,\n encoding: options.encoding,\n allowEmpty: options.allowEmpty,\n nulIsBinary: true,\n },\n );\n }\n\n /**\n * The leading comment lines the reader skipped (SNAP `#` lines, the KONECT `%` header), in order.\n * @returns the lines without their line breaks\n */\n get leadingComments(): readonly string[] {\n return this.inner.leadingComments;\n }\n\n /**\n * The 1-based line of each leading comment, parallel to `leadingComments`.\n * @returns the lines\n */\n get leadingCommentLines(): readonly number[] {\n return this.inner.leadingCommentLines;\n }\n\n /**\n * The 1-based line the most recently yielded row starts on.\n * @returns the line; 0 before the first row\n */\n get line(): number {\n return this.inner.line;\n }\n\n /**\n * The delimiter in use.\n * @returns the given or sniffed delimiter; null before the sniff ran\n */\n get delimiter(): string | null {\n return this.inner.delimiter;\n }\n\n /**\n * Whether each cell of the row most recently yielded was quoted.\n * @returns the flags (valid for the first `row.length` entries)\n */\n get quoted(): readonly boolean[] {\n return this.inner.quoted;\n }\n\n /**\n * The line of the first quote inside an unquoted field.\n * @returns the line, or 0 when there was none\n */\n get strayQuoteLine(): number {\n return this.inner.strayQuoteLine;\n }\n\n /**\n * Whether the first record is an Excel `sep=X` line the delimiter was taken from.\n * @returns true when it is\n */\n get sepDirective(): boolean {\n return this.inner.sepDirective;\n }\n\n /**\n * Iterate the rows.\n * @yields one row at a time as its cell texts\n * @returns nothing\n */\n async *[Symbol.asyncIterator](): AsyncGenerator<string[], void, undefined> {\n const { inner } = this;\n for await (const count of inner) {\n if (isBlankRecord(inner.cells, inner.quoted, count)) {\n continue;\n }\n yield inner.cells.slice(0, count);\n }\n }\n}\n\n/**\n * Whether a record holds nothing: every cell unquoted and blank (a blank line, a whitespace-only\n * line, or an Excel empty row `,,,`). A quoted empty cell is a value.\n * @param cells - the cells\n * @param quoted - whether each was quoted\n * @param count - the cell count\n * @returns true when the record carries no value\n */\nfunction isBlankRecord(cells: readonly string[], quoted: readonly boolean[], count: number): boolean {\n for (let k = 0; k < count; k++) {\n if (quoted[k] || cells[k].trim().length > 0) {\n return false;\n }\n }\n return true;\n}\n"],"names":[],"mappings":";;AA0BO,MAAM,sBAAsB;AAM5B,MAAM,iBAAiB;AAMvB,MAAM,uBAA0C,OAAO,OAAO,CAAC,KAAK,KAAM,KAAK,KAAK,GAAG,CAAC;AAG/F,MAAM,eAAe;AAGrB,MAAM,gBAAgB,KAAK;AAE3B,MAAM,KAAK;AACX,MAAM,KAAK;AACX,MAAM,MAAM;AACZ,MAAM,QAAQ;AAGd,MAAM,gBAAgB;AAGtB,MAAM,QAAQ;AAEd,MAAM,WAAW;AAEjB,MAAM,SAAS;AAEf,MAAM,UAAU;AAEhB,MAAM,eAAe;AAErB,MAAM,UAAU;AAiDT,SAAS,kBAAkB,QAAoC;AAClE,aAAW,CAAC,QAAQ,KAAK,KAAK;AAAA,IAC1B,CAAC,aAAa,OAAO,SAAS;AAAA,IAC9B,CAAC,SAAS,OAAO,KAAK;AAAA,EAAA,GACd;AACR,QAAI,UAAU,MAAM;AAChB;AAAA,IACJ;AACA,QAAI,MAAM,WAAW,KAAK,UAAU,QAAQ,UAAU,MAAM;AACxD,YAAM,IAAI;AAAA,QACN;AAAA,QACA,UAAU,MAAM,KAAK,KAAK,UAAU,KAAK,CAAC;AAAA,QAC1C,EAAE,QAAQ,OAAO,MAAA;AAAA,MAAM;AAAA,IAE/B;AAAA,EACJ;AACA,MAAI,OAAO,cAAc,QAAQ,OAAO,cAAc,OAAO,OAAO;AAChE,UAAM,IAAI,iBAAiB,iBAAiB,2CAA2C;AAAA,MACnF,QAAQ;AAAA,MACR,OAAO,OAAO;AAAA,IAAA,CACjB;AAAA,EACL;AACA,SAAO;AACX;AASO,SAAS,aAAa,MAA2B;AACpD,SAAO,CAAC,KAAK,SAAS,IAAI,KAAK,KAAK,SA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A;AAAA;AAAA;AAAA,EAMA,IAAI,eAAwB;AACxB,WAAO,KAAK,MAAM;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAQ,OAAO,aAAa,IAA+C;AACvE,UAAM,EAAE,UAAU;AAClB,qBAAiB,SAAS,OAAO;AAC7B,UAAI,cAAc,MAAM,OAAO,MAAM,QAAQ,KAAK,GAAG;AACjD;AAAA,MACJ;AACA,YAAM,MAAM,MAAM,MAAM,GAAG,KAAK;AAAA,IACpC;AAAA,EACJ;AACJ;AAUA,SAAS,cAAc,OAA0B,QAA4B,OAAwB;AACjG,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK;AAC5B,QAAI,OAAO,CAAC,KAAK,MAAM,CAAC,EAAE,KAAA,EAAO,SAAS,GAAG;AACzC,aAAO;AAAA,IACX;AAAA,EACJ;AACA,SAAO;AACX;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { INVALID_INDEX, GraphFormatError } from "@graphty/graph-format";
|
|
2
|
-
import { P as PRECISION_CODE } from "./export-
|
|
3
|
-
const I32_TEXT = /^-?(0|[1-9]
|
|
4
|
-
const F64_TEXT = /^[+-]?((0|[1-9]
|
|
2
|
+
import { P as PRECISION_CODE } from "./export-Cbt4h_0n.js";
|
|
3
|
+
const I32_TEXT = /^-?(0|[1-9]\d*)$/;
|
|
4
|
+
const F64_TEXT = /^[+-]?((0|[1-9]\d*)(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
|
|
5
5
|
const I32_MIN = -2147483648;
|
|
6
6
|
const I32_MAX = 2147483647;
|
|
7
7
|
function trimTrailingZeros(digits) {
|
|
@@ -204,4 +204,4 @@ export {
|
|
|
204
204
|
parseTextCell as p,
|
|
205
205
|
trimTrailingZeros as t
|
|
206
206
|
};
|
|
207
|
-
//# sourceMappingURL=text-
|
|
207
|
+
//# sourceMappingURL=text-BD-TzLNm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text-BD-TzLNm.js","sources":["../../src/common/text.ts"],"sourcesContent":["/**\n * The fixed lexical grammar of design section 5.1 for untyped text sources (CSV cells, GML\n * values, DOT strings, Pajek tokens), reproduced from the core's reference implementation so the\n * two agree (invariant I15). Text importers parse each cell with parseTextCell() and push the JS\n * value; the sink's per-column inference then widens `bool -> i32 -> f64 -> string` and never per\n * cell, so a column that saw `1` and then `\"01\"` becomes string for all rows.\n *\n * - `bool` is exactly `true` / `false` (case-sensitive);\n * - `i32` is `/^-?(0|[1-9][0-9]*)$/` within `[-2^31, 2^31)`; `0` / `1` are i32, never bool;\n * - `f64` is a decimal or exponent literal accepted by `Number()` that is not empty, not\n * whitespace, not `Infinity` / `NaN`, not a hex / octal / binary form, has no leading zeros in\n * its integer part, and whose value is finite (an integer literal outside i32 range is f64);\n * - everything else is `string`.\n */\n\nimport { type ColumnHandle, GraphFormatError, type GraphSink, INVALID_INDEX } from \"@graphty/graph-format\";\n\nimport { PRECISION_CODE } from \"./codes.js\";\nimport { type ImportReportBuilder } from \"./report.js\";\n\nconst I32_TEXT = /^-?(0|[1-9]\\d*)$/;\nconst F64_TEXT = /^[+-]?((0|[1-9]\\d*)(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$/;\nconst I32_MIN = -2147483648;\nconst I32_MAX = 2147483647;\n\n/**\n * The dtype a text cell parses as under the fixed text grammar.\n * @public\n * @category Plugin helpers\n */\nexport type TextDtype = \"bool\" | \"i32\" | \"f64\" | \"string\";\n\n/**\n * A digit string without its trailing zeros (`\"1200\"` becomes `\"12\"`).\n * @param digits - the digits\n * @returns the digits up to the last one that is not 0\n */\nexport function trimTrailingZeros(digits: string): string {\n let end = digits.length;\n while (end > 0 && digits[end - 1] === \"0\") {\n end--;\n }\n return digits.slice(0, end);\n}\n\n/**\n * Classify one text cell by the fixed grammar.\n * @param text - the cell text, exactly as read (no trimming)\n * @returns bool, i32, f64 or string\n * @category Plugin helpers\n */\nexport function inferTextDtype(text: string): TextDtype {\n if (text === \"true\" || text === \"false\") {\n return \"bool\";\n }\n if (I32_TEXT.test(text)) {\n const n = Number(text);\n if (n >= I32_MIN && n <= I32_MAX) {\n return \"i32\";\n }\n return Number.isFinite(n) ? \"f64\" : \"string\";\n }\n if (F64_TEXT.test(text) && Number.isFinite(Number(text))) {\n return \"f64\";\n }\n return \"string\";\n}\n\n/**\n * Parse one text cell into the JS value its grammar class implies: a boolean for bool, a number for\n * i32 / f64, the text itself for string. The sink infers the column dtype from the value.\n * @param text - the cell text, exactly as read\n * @returns the value\n * @category Plugin helpers\n */\nexport function parseTextCell(text: string): boolean | number | string {\n switch (inferTextDtype(text)) {\n case \"bool\":\n return text === \"true\";\n case \"i32\":\n case \"f64\":\n return Number(text);\n case \"string\":\n return text;\n default:\n return text;\n }\n}\n\n/**\n * Whether a text cell is a number under the f64 grammar (an i32 or f64 literal).\n * @param text - the cell text\n * @returns true when parseTextCell(text) returns a number\n * @category Plugin helpers\n */\nexport function isNumericText(text: string): boolean {\n const dtype = inferTextDtype(text);\n return dtype === \"i32\" || dtype === \"f64\";\n}\n\n/**\n * Whether a numeric cell text is the canonical spelling of its value (`String(value) === text`),\n * so that the sink's own re-formatting of the value would reproduce it.\n * @param text - the cell text\n * @param value - the parsed value\n * @returns true when the lexical form survives a widening to string\n */\nfunction isCanonicalNumberText(text: string, value: number): boolean {\n return String(value) === text;\n}\n\n/**\n * The widening rank of a text dtype in the design section 5.1 order.\n * @param dtype - the text dtype\n * @returns 0 for bool, 1 for i32, 2 for f64, 3 for string\n */\nfunction textDtypeRank(dtype: TextDtype): number {\n switch (dtype) {\n case \"bool\":\n return 0;\n case \"i32\":\n return 1;\n case \"f64\":\n return 2;\n case \"string\":\n return 3;\n default: {\n const name: string = dtype;\n throw new GraphFormatError(\"E_UNSUPPORTED\", `unknown text dtype ${name}`, { dtype: name });\n }\n }\n}\n\n/**\n * Writes the cells of one attribute of a text format whose values carry no type (CSV, DOT, Pajek):\n * you hand it each cell's text and it stores a number, a boolean or text, choosing one type for the\n * whole attribute. A column of `2.0`, `3.5` stays a number column with decimals even though `2.0`\n * alone looks like an integer, and once one cell turns out to be text, earlier cells such as `1e5`\n * are kept as written instead of as `100000`. Create one writer per attribute name and per kind\n * (\"node\" or \"edge\"), and call `write(index, text)` with the node or edge index the sink gave you:\n *\n * ```ts\n * const color = new TextCellWriter(\"color\", \"node\", sink, report);\n * color.write(sink.addNode(\"a\"), \"red\");\n * ```\n *\n * A sink that cannot change a column's type after the fact (one of your own without\n * `widenNodeColumn` / `widenEdgeColumn`) keeps the type the first values implied, with one W_WIDENING_UNSUPPORTED warning\n * per attribute.\n * @public\n * @category Writing a format\n */\nexport class TextCellWriter {\n /** The column name in the sink. */\n readonly name: string;\n\n private readonly domain: \"node\" | \"edge\";\n\n private readonly sink: GraphSink;\n\n private readonly report: ImportReportBuilder;\n\n private handle: ColumnHandle = INVALID_INDEX as ColumnHandle;\n\n /** The widest text dtype seen (the column's dtype under the 5.1 grammar). */\n private textDtype: TextDtype | null = null;\n\n /** The widest dtype the pushed values imply (what the sink inferred on its own). */\n private valueDtype: TextDtype | null = null;\n\n private readonly keptRows: number[] = [];\n\n private readonly keptTexts: string[] = [];\n\n /**\n * Create a writer. The attribute is added to the sink on the first write.\n * @param name - the attribute name\n * @param domain - \"node\" for a node attribute, \"edge\" for an edge attribute\n * @param sink - the sink the importer fills\n * @param report - the import report, for warnings about the values\n */\n constructor(name: string, domain: \"node\" | \"edge\", sink: GraphSink, report: ImportReportBuilder) {\n this.name = name;\n this.domain = domain;\n this.sink = sink;\n this.report = report;\n }\n\n /**\n * The sink's handle of the attribute's column, for reading it back.\n * @returns the handle, or INVALID_INDEX before the first write\n */\n get column(): ColumnHandle {\n return this.handle;\n }\n\n /**\n * Write one cell.\n * @param row - the node or edge index, as the sink's addNode() or addEdge() returned it\n * @param text - the cell text, exactly as read from the file\n */\n write(row: number, text: string): void {\n const kind = inferTextDtype(text);\n const value = parseTextCell(text);\n if (\n typeof value === \"number\" &&\n !Number.isSafeInteger(value) &&\n I32_TEXT.test(text) &&\n BigInt(text) !== BigInt(value)\n ) {\n // an integer beyond 2^53 is stored as the nearest double; say so once per column\n this.report.warnOnce(\n \"precision\",\n PRECISION_CODE,\n `${this.domain} column \"${this.name}\": integers beyond 2^53 are stored as the nearest double (first: ${text})`,\n { element: this.name },\n `${PRECISION_CODE}:${this.domain}:${this.name}`,\n );\n }\n const wasString = this.textDtype === \"string\";\n const textDtype =\n this.textDtype === null || textDtypeRank(kind) > textDtypeRank(this.textDtype) ? kind : this.textDtype;\n // a string column keeps every cell's lexical form; a numeric text is never re-spelled. The\n // sink may refuse the value (a declared column of another dtype): the state advances only\n // once the cell is written, so a refused cell leaves the writer as it was.\n this.set(row, textDtype === \"string\" ? text : value);\n this.textDtype = textDtype;\n const valueKind = kindOfValue(value);\n if (this.valueDtype === null || textDtypeRank(valueKind) > textDtypeRank(this.valueDtype)) {\n this.valueDtype = valueKind;\n }\n if (this.textDtype === \"string\") {\n if (!wasString && this.keptRows.length > 0) {\n // the sink just widened the column to string from the values; restore the texts\n // whose lexical form the values did not carry\n for (let i = 0; i < this.keptRows.length; i++) {\n this.set(this.keptRows[i], this.keptTexts[i]);\n }\n this.keptRows.length = 0;\n this.keptTexts.length = 0;\n }\n return;\n }\n if (typeof value === \"number\" && !isCanonicalNumberText(text, value)) {\n this.keptRows.push(row);\n this.keptTexts.push(text);\n }\n if (this.textDtype === \"f64\" && this.valueDtype !== \"f64\") {\n this.widen(\"f64\");\n }\n }\n\n /**\n * Write a value (the parsed scalar, or a text into a widened column).\n * @param row - the row\n * @param value - the value\n */\n private set(row: number, value: unknown): void {\n if (this.handle === INVALID_INDEX) {\n if (this.domain === \"node\") {\n this.sink.setNodeValue(this.name, row, value);\n this.handle = this.sink.nodeColumn(this.name);\n } else {\n this.sink.setEdgeValue(this.name, row, value);\n this.handle = this.sink.edgeColumn(this.name);\n }\n return;\n }\n if (this.domain === \"node\") {\n this.sink.setNodeValue(this.handle, row, value);\n } else {\n this.sink.setEdgeValue(this.handle, row, value);\n }\n }\n\n /**\n * Widen the column to the dtype the text grammar implies, through the sink's optional call.\n * @param dtype - the dtype\n */\n private widen(dtype: \"f64\"): void {\n const { sink } = this;\n const supported =\n this.domain === \"node\" ? sink.widenNodeColumn !== undefined : sink.widenEdgeColumn !== undefined;\n if (!supported) {\n this.report.warnOnce(\n \"coercion\",\n WIDENING_UNSUPPORTED_CODE,\n `column \"${this.name}\" holds ${dtype} text but the sink cannot widen an inferred column; it keeps the value-inferred dtype`,\n { element: this.name },\n );\n this.valueDtype = dtype;\n return;\n }\n try {\n if (this.domain === \"node\") {\n sink.widenNodeColumn?.(this.handle, dtype);\n } else {\n sink.widenEdgeColumn?.(this.handle, dtype);\n }\n this.valueDtype = dtype;\n } catch (err) {\n if (!(err instanceof GraphFormatError) || err.code !== \"E_COLUMN_TYPE\") {\n throw err;\n }\n // a caller's declared column of the name: its dtype stands\n this.valueDtype = dtype;\n }\n }\n}\n\n/**\n * Your graph builder cannot change an attribute's type after its first value, so a text column keeps the type of its\n * first values.\n * @category Issue and loss codes\n */\nexport const WIDENING_UNSUPPORTED_CODE = \"W_WIDENING_UNSUPPORTED\";\n\n/**\n * The text dtype a parsed cell value implies on its own (what the sink's inference sees). It must\n * be graph-format's inference rule exactly: -0 is an integer there, so a column holding only\n * `-0.0` is inferred i32 and must be widened to f64, or the sign is lost.\n * @param value - the parsed value\n * @returns the dtype\n */\nfunction kindOfValue(value: boolean | number | string): TextDtype {\n if (typeof value === \"boolean\") {\n return \"bool\";\n }\n if (typeof value === \"string\") {\n return \"string\";\n }\n return Number.isInteger(value) && value >= -2147483648 && value <= 2147483647 ? \"i32\" : \"f64\";\n}\n"],"names":[],"mappings":";;AAoBA,MAAM,WAAW;AACjB,MAAM,WAAW;AACjB,MAAM,UAAU;AAChB,MAAM,UAAU;AAcT,SAAS,kBAAkB,QAAwB;AACtD,MAAI,MAAM,OAAO;AACjB,SAAO,MAAM,KAAK,OAAO,MAAM,CAAC,MAA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A,QAAI;AACA,UAAI,KAAK,WAAW,QAAQ;AACxB,aAAK,kBAAkB,KAAK,QAAQ,KAAK;AAAA,MAC7C,OAAO;AACH,aAAK,kBAAkB,KAAK,QAAQ,KAAK;AAAA,MAC7C;AACA,WAAK,aAAa;AAAA,IACtB,SAAS,KAAK;AACV,UAAI,EAAE,eAAe,qBAAqB,IAAI,SAAS,iBAAiB;AACpE,cAAM;AAAA,MACV;AAEA,WAAK,aAAa;AAAA,IACtB;AAAA,EACJ;AACJ;AAOO,MAAM,4BAA4B;AASzC,SAAS,YAAY,OAA6C;AAC9D,MAAI,OAAO,UAAU,WAAW;AAC5B,WAAO;AAAA,EACX;AACA,MAAI,OAAO,UAAU,UAAU;AAC3B,WAAO;AAAA,EACX;AACA,SAAO,OAAO,UAAU,KAAK,KAAK,SAAS,eAAe,SAAS,aAAa,QAAQ;AAC5F;"}
|
package/dist/csv.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { b as plural, bU as DICT_SAMPLE_ROWS, ac as DictHeuristic, R as ROLE_TAKEN_CODE$1, I as ID_MERGED_CODE$1, m as DUPLICATE_EDGE_ID_CODE$1, n as DUPLICATE_NODE_CODE$1, t as MISSING_ID_CODE$1, s as MISSING_ENDPOINT_CODE$1, E as EMPTY_INPUT_CODE$1, al as resolveImportOptions, a8 as ImportReportBuilder, ao as reportSinkOptions, an as reportUnusedOptions, aq as DirectionResolver, ar as IdCoercer, am as throwIfAborted, O as OPTION_IGNORED_CODE, aK as parseWeightText, a0 as uniqueColumnName, ay as RENAMED_CODE, a1 as declareResolved, c as capabilities, L as LOSS, a as checkCapabilities, r as resolveExportOptions, p as pairFolding, bD as countMixedEdges, $ as agree, e as explicitWeights, b_ as otherFormatDialect, bS as joinListText, aG as formatInteger, aF as formatDecimal, aH as canonicalId, M as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, d as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, C as COLUMN_RENAMED_CODE, w as UNKNOWN_ENCODING_CODE, x as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, P as PRECISION_CODE, F as ELEMENT_ISSUE, G as INPUT_ISSUE } from "./chunks/export-
|
|
2
|
-
import { i as inferTextDtype, T as TextCellWriter, p as parseTextCell, W as WIDENING_UNSUPPORTED_CODE } from "./chunks/text-
|
|
1
|
+
import { b as plural, bU as DICT_SAMPLE_ROWS, ac as DictHeuristic, R as ROLE_TAKEN_CODE$1, I as ID_MERGED_CODE$1, m as DUPLICATE_EDGE_ID_CODE$1, n as DUPLICATE_NODE_CODE$1, t as MISSING_ID_CODE$1, s as MISSING_ENDPOINT_CODE$1, E as EMPTY_INPUT_CODE$1, al as resolveImportOptions, a8 as ImportReportBuilder, ao as reportSinkOptions, an as reportUnusedOptions, aq as DirectionResolver, ar as IdCoercer, am as throwIfAborted, O as OPTION_IGNORED_CODE, aK as parseWeightText, a0 as uniqueColumnName, ay as RENAMED_CODE, a1 as declareResolved, c as capabilities, L as LOSS, a as checkCapabilities, r as resolveExportOptions, p as pairFolding, bD as countMixedEdges, $ as agree, e as explicitWeights, b_ as otherFormatDialect, bS as joinListText, aG as formatInteger, aF as formatDecimal, aH as canonicalId, M as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, d as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, C as COLUMN_RENAMED_CODE, w as UNKNOWN_ENCODING_CODE, x as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, P as PRECISION_CODE, F as ELEMENT_ISSUE, G as INPUT_ISSUE } from "./chunks/export-Cbt4h_0n.js";
|
|
2
|
+
import { i as inferTextDtype, T as TextCellWriter, p as parseTextCell, W as WIDENING_UNSUPPORTED_CODE } from "./chunks/text-BD-TzLNm.js";
|
|
3
3
|
import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
|
|
4
|
-
import { s as stripLeadingComments, a as sniffNewline, b as sniffDelimiter, D as DELIMITER_CANDIDATES, c as checkRecordSyntax, C as CsvRecordReader, d as splitRecords, B as BAD_QUOTE_CODE, U as UNCLOSED_QUOTE_CODE } from "./chunks/records-
|
|
5
|
-
import { o as quoteCsvCell } from "./chunks/escape-
|
|
4
|
+
import { s as stripLeadingComments, a as sniffNewline, b as sniffDelimiter, D as DELIMITER_CANDIDATES, c as checkRecordSyntax, C as CsvRecordReader, d as splitRecords, B as BAD_QUOTE_CODE, U as UNCLOSED_QUOTE_CODE } from "./chunks/records-BrfHycmg.js";
|
|
5
|
+
import { o as quoteCsvCell } from "./chunks/escape-wVIEtLv6.js";
|
|
6
6
|
import { j as joinText, e as encodeChunks } from "./chunks/writer-DxjgHwSe.js";
|
|
7
7
|
const SOURCE_NAMES = Object.freeze([
|
|
8
8
|
"source",
|
package/dist/cx.js
CHANGED
package/dist/cx2.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C, a, c } from "./chunks/exporter-
|
|
2
|
-
import { C as C2, c as c2 } from "./chunks/importer-
|
|
1
|
+
import { C, a, c } from "./chunks/exporter-DMxRy-0l.js";
|
|
2
|
+
import { C as C2, c as c2 } from "./chunks/importer-BTSvNJUB.js";
|
|
3
3
|
export {
|
|
4
4
|
C as CX2_CAPABILITIES,
|
|
5
5
|
C2 as CX2_ISSUE,
|
package/dist/cys.js
CHANGED
package/dist/dot.js
CHANGED
package/dist/gexf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { bF as TIME_TEXT_ROLE, bG as TIME_TEXT_SUFFIX, al as resolveImportOptions, a8 as ImportReportBuilder, ao as reportSinkOptions, an as reportUnusedOptions, a4 as textChunks, E as EMPTY_INPUT_CODE, X as XML_SYNTAX_CODE, am as throwIfAborted, ar as IdCoercer, aq as DirectionResolver, f as STRAY_TEXT_CODE, N as NO_GRAPH_CODE, h as UNKNOWN_XML_ATTRIBUTE_CODE, l as MULTIPLE_GRAPHS_CODE, j as COUNT_MISMATCH_CODE, k as COUNT_HINT_CODE, o as DUPLICATE_ATTRIBUTE_CODE, aJ as isWeightField, bH as declareAttribute, a1 as declareResolved, t as MISSING_ID_CODE, n as DUPLICATE_NODE_CODE, q as UNKNOWN_PARENT_CODE, ai as PARENT_CYCLE_CODE, s as MISSING_ENDPOINT_CODE, m as DUPLICATE_EDGE_ID_CODE, aK as parseWeightText, bI as overflowsToInfinity, P as PRECISION_CODE, bJ as parseDeclaredTemporal, br as declareCompanion, bK as parseDeclaredValue, bL as losesPrecision, bM as parseTimeText, a3 as BAD_VALUE_CODE, bN as splitListText, g as UNKNOWN_ELEMENT_CODE, I as ID_MERGED_CODE, bO as timeTextCompanion, bP as parseDecimalText, c as capabilities, L as LOSS, aE as sanitizeIds, p as pairFolding, e as explicitWeights, r as resolveExportOptions, a as checkCapabilities, bQ as formatTimeValue, aa as formatF32, ab as formatF64, bR as mapDeclaredType, bS as joinListText, bT as formatTemporal, aG as formatInteger, b as plural, $ as agree, bx as isCanonicalIntegerText, M as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, d as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, O as OPTION_IGNORED_CODE, R as ROLE_TAKEN_CODE, C as COLUMN_RENAMED_CODE, aZ as BAD_OPTIONS_CODE, B as BAD_DEFAULT_CODE, U as UNKNOWN_ATTR_TYPE_CODE, v as ENCODING_CONFLICT_CODE, w as UNKNOWN_ENCODING_CODE, x as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, A as COLUMN_TYPE_CODE, F as ELEMENT_ISSUE, G as INPUT_ISSUE } from "./chunks/export-
|
|
1
|
+
import { bF as TIME_TEXT_ROLE, bG as TIME_TEXT_SUFFIX, al as resolveImportOptions, a8 as ImportReportBuilder, ao as reportSinkOptions, an as reportUnusedOptions, a4 as textChunks, E as EMPTY_INPUT_CODE, X as XML_SYNTAX_CODE, am as throwIfAborted, ar as IdCoercer, aq as DirectionResolver, f as STRAY_TEXT_CODE, N as NO_GRAPH_CODE, h as UNKNOWN_XML_ATTRIBUTE_CODE, l as MULTIPLE_GRAPHS_CODE, j as COUNT_MISMATCH_CODE, k as COUNT_HINT_CODE, o as DUPLICATE_ATTRIBUTE_CODE, aJ as isWeightField, bH as declareAttribute, a1 as declareResolved, t as MISSING_ID_CODE, n as DUPLICATE_NODE_CODE, q as UNKNOWN_PARENT_CODE, ai as PARENT_CYCLE_CODE, s as MISSING_ENDPOINT_CODE, m as DUPLICATE_EDGE_ID_CODE, aK as parseWeightText, bI as overflowsToInfinity, P as PRECISION_CODE, bJ as parseDeclaredTemporal, br as declareCompanion, bK as parseDeclaredValue, bL as losesPrecision, bM as parseTimeText, a3 as BAD_VALUE_CODE, bN as splitListText, g as UNKNOWN_ELEMENT_CODE, I as ID_MERGED_CODE, bO as timeTextCompanion, bP as parseDecimalText, c as capabilities, L as LOSS, aE as sanitizeIds, p as pairFolding, e as explicitWeights, r as resolveExportOptions, a as checkCapabilities, bQ as formatTimeValue, aa as formatF32, ab as formatF64, bR as mapDeclaredType, bS as joinListText, bT as formatTemporal, aG as formatInteger, b as plural, $ as agree, bx as isCanonicalIntegerText, M as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, d as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, O as OPTION_IGNORED_CODE, R as ROLE_TAKEN_CODE, C as COLUMN_RENAMED_CODE, aZ as BAD_OPTIONS_CODE, B as BAD_DEFAULT_CODE, U as UNKNOWN_ATTR_TYPE_CODE, v as ENCODING_CONFLICT_CODE, w as UNKNOWN_ENCODING_CODE, x as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, A as COLUMN_TYPE_CODE, F as ELEMENT_ISSUE, G as INPUT_ISSUE } from "./chunks/export-Cbt4h_0n.js";
|
|
2
2
|
import { GraphFormatError, INVALID_INDEX, MAX_COUNT } from "@graphty/graph-format";
|
|
3
|
-
import { t as tokenizeXml, f as xmlDeclaredEncoding, g as XmlEmptyInputError, X as XmlSyntaxError, s as sniffXmlText, l as localName, j as isWhitespace, x as xmlIllegalTextNotes, a as escapeXmlText, e as escapeXmlAttribute } from "./chunks/escape-
|
|
3
|
+
import { t as tokenizeXml, f as xmlDeclaredEncoding, g as XmlEmptyInputError, X as XmlSyntaxError, s as sniffXmlText, l as localName, j as isWhitespace, x as xmlIllegalTextNotes, a as escapeXmlText, e as escapeXmlAttribute } from "./chunks/escape-wVIEtLv6.js";
|
|
4
4
|
import { j as joinText, e as encodeChunks } from "./chunks/writer-DxjgHwSe.js";
|
|
5
5
|
const GEXF_FORMAT = "gexf";
|
|
6
6
|
const GEXF_NAMESPACES = {
|
package/dist/gml.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ak as SYNTAX_CODE, b as plural, a as checkCapabilities, L as LOSS, p as pairFolding, $ as agree, c as capabilities, r as resolveExportOptions, ac as DictHeuristic, aG as formatInteger, bv as formatGmlReal, aE as sanitizeIds, bD as countMixedEdges, e as explicitWeights, bU as DICT_SAMPLE_ROWS, R as ROLE_TAKEN_CODE$1, aj as WIDENED_CODE$1, P as PRECISION_CODE$1, n as DUPLICATE_NODE_CODE$1, s as MISSING_ENDPOINT_CODE$1, t as MISSING_ID_CODE$1, l as MULTIPLE_GRAPHS_CODE, N as NO_GRAPH_CODE$1, al as resolveImportOptions, a8 as ImportReportBuilder, an as reportUnusedOptions, bB as readText, am as throwIfAborted, ao as reportSinkOptions, ap as graphChosen, ar as IdCoercer, aq as DirectionResolver, a0 as uniqueColumnName, C as COLUMN_RENAMED_CODE, as as weightFromValue, bV as reportWeightPrecision, aK as parseWeightText, a1 as declareResolved, M as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, d as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, O as OPTION_IGNORED_CODE, I as ID_MERGED_CODE, ae as AMBIGUOUS_GRAPH_NAME_CODE, af as GRAPH_NOT_FOUND_CODE, w as UNKNOWN_ENCODING_CODE, x as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, F as ELEMENT_ISSUE, G as INPUT_ISSUE } from "./chunks/export-
|
|
1
|
+
import { ak as SYNTAX_CODE, b as plural, a as checkCapabilities, L as LOSS, p as pairFolding, $ as agree, c as capabilities, r as resolveExportOptions, ac as DictHeuristic, aG as formatInteger, bv as formatGmlReal, aE as sanitizeIds, bD as countMixedEdges, e as explicitWeights, bU as DICT_SAMPLE_ROWS, R as ROLE_TAKEN_CODE$1, aj as WIDENED_CODE$1, P as PRECISION_CODE$1, n as DUPLICATE_NODE_CODE$1, s as MISSING_ENDPOINT_CODE$1, t as MISSING_ID_CODE$1, l as MULTIPLE_GRAPHS_CODE, N as NO_GRAPH_CODE$1, al as resolveImportOptions, a8 as ImportReportBuilder, an as reportUnusedOptions, bB as readText, am as throwIfAborted, ao as reportSinkOptions, ap as graphChosen, ar as IdCoercer, aq as DirectionResolver, a0 as uniqueColumnName, C as COLUMN_RENAMED_CODE, as as weightFromValue, bV as reportWeightPrecision, aK as parseWeightText, a1 as declareResolved, M as MIXED_DIRECTION_CODE, D as DIRECTION_FORCED_CODE, d as DIRECTION_REFUSED_CODE, S as SINK_OPTION_CODE, O as OPTION_IGNORED_CODE, I as ID_MERGED_CODE, ae as AMBIGUOUS_GRAPH_NAME_CODE, af as GRAPH_NOT_FOUND_CODE, w as UNKNOWN_ENCODING_CODE, x as ENCODING_FALLBACK_CODE, y as INVALID_ENCODING_CODE, z as INVALID_UTF8_CODE, F as ELEMENT_ISSUE, G as INPUT_ISSUE } from "./chunks/export-Cbt4h_0n.js";
|
|
2
2
|
import { GraphFormatError, INVALID_INDEX } from "@graphty/graph-format";
|
|
3
|
-
import { k as decodeGmlString, m as quoteGmlString } from "./chunks/escape-
|
|
3
|
+
import { k as decodeGmlString, m as quoteGmlString } from "./chunks/escape-wVIEtLv6.js";
|
|
4
4
|
import { j as joinText, e as encodeChunks } from "./chunks/writer-DxjgHwSe.js";
|
|
5
|
-
import { i as importChosenGraph } from "./chunks/choose-
|
|
5
|
+
import { i as importChosenGraph } from "./chunks/choose-494CpuXQ.js";
|
|
6
6
|
const TOKEN_WORD = 0;
|
|
7
7
|
const TOKEN_INT = 1;
|
|
8
8
|
const TOKEN_REAL = 2;
|
|
@@ -17,10 +17,10 @@ const SYNTAX_STRUCTURE_CODE = SYNTAX_CODE;
|
|
|
17
17
|
const SYNTAX_TOKEN_CODE = SYNTAX_CODE;
|
|
18
18
|
const SYNTAX_STRING_CODE = SYNTAX_CODE;
|
|
19
19
|
const SYNTAX_BRACKET_CODE = SYNTAX_CODE;
|
|
20
|
-
const KEY_TEXT = /^[A-Za-z_]
|
|
21
|
-
const STRICT_KEY_TEXT = /^[A-Za-z]
|
|
22
|
-
const INT_TEXT = /^[+-]
|
|
23
|
-
const REAL_TEXT = /^[+-]?(?:(
|
|
20
|
+
const KEY_TEXT = /^[A-Za-z_]\w*$/;
|
|
21
|
+
const STRICT_KEY_TEXT = /^[A-Za-z]\w*$/;
|
|
22
|
+
const INT_TEXT = /^[+-]?\d+$/;
|
|
23
|
+
const REAL_TEXT = /^[+-]?(?:(?:\d+\.\d*|\.\d+)(?:[eE][+-]?\d+)?|\d+[eE][+-]?\d+)$/;
|
|
24
24
|
const NON_FINITE_TEXT = /^[+-]?(?:inf|infinity|nan)$/i;
|
|
25
25
|
const NON_FINITE_WORD = /^(?:inf|infinity|nan)$/i;
|
|
26
26
|
class GmlSyntaxError extends Error {
|
|
@@ -427,7 +427,7 @@ const NODE_RESERVED = /* @__PURE__ */ new Set(["id"]);
|
|
|
427
427
|
const EDGE_RESERVED = /* @__PURE__ */ new Set(["source", "target", "directed"]);
|
|
428
428
|
const GRAPH_RESERVED = /* @__PURE__ */ new Set(["node", "edge", "directed", "multigraph"]);
|
|
429
429
|
const TOP_RESERVED = /* @__PURE__ */ new Set(["graph"]);
|
|
430
|
-
const NUMBER_TEXT = /^[+-]?(
|
|
430
|
+
const NUMBER_TEXT = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
431
431
|
function planOf(snapshot, options) {
|
|
432
432
|
const common = resolveExportOptions(options);
|
|
433
433
|
const mode = options?.sanitizeKeys ?? "error";
|
|
@@ -1391,7 +1391,7 @@ const REPEATED_KEY_CODE = "E_GML_REPEATED_KEY";
|
|
|
1391
1391
|
const ELEMENT_TYPE_CODE = "E_GML_ELEMENT_TYPE";
|
|
1392
1392
|
const FLAG_TYPE_CODE = "E_GML_FLAG_TYPE";
|
|
1393
1393
|
const FLAG_VALUE_CODE = "W_GML_FLAG_VALUE";
|
|
1394
|
-
const QUOTED_INT = /^\s*[+-]
|
|
1394
|
+
const QUOTED_INT = /^\s*[+-]?\d+\s*$/;
|
|
1395
1395
|
const UNKNOWN_ENTITY_CODE = "W_GML_UNKNOWN_ENTITY";
|
|
1396
1396
|
const GRAPHICS_CODE = "W_GML_GRAPHICS";
|
|
1397
1397
|
const NESTED_ELEMENT_CODE = "W_GML_NESTED_ELEMENT";
|
|
@@ -2784,7 +2784,7 @@ function describeValue(t, v) {
|
|
|
2784
2784
|
}
|
|
2785
2785
|
const SNIFF_GRAPH_START = /^(?:\s|#[^\n]*\n)*graph\s*\[/;
|
|
2786
2786
|
const SNIFF_GRAPH_ANYWHERE = /(?:^|\s)graph\s*\[/;
|
|
2787
|
-
const SNIFF_KEY_START = /^(?:\s|#[^\n]*\n)*[A-Za-z_]
|
|
2787
|
+
const SNIFF_KEY_START = /^(?:\s|#[^\n]*\n)*[A-Za-z_]\w*\s+(?:"|[+-]?[0-9.]|\[)/;
|
|
2788
2788
|
function sniffGml(head) {
|
|
2789
2789
|
let text = new TextDecoder("utf-8", { fatal: false }).decode(head);
|
|
2790
2790
|
if (text.charCodeAt(0) === 65279) {
|