@ricsam/excel-to-formula-engine 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Delimited-text parsing: CSV, TSV, and the semicolon-separated files a
3
+ * comma-decimal locale produces.
4
+ *
5
+ * Follows RFC 4180 for quoting — a field wrapped in double quotes may contain
6
+ * the delimiter, line breaks, and doubled quotes standing for one — because that
7
+ * is what every spreadsheet writes and the naive `split(",")` gets wrong on the
8
+ * first address field it meets.
9
+ */
10
+ /** Delimiters worth guessing between. */
11
+ export declare const CANDIDATE_DELIMITERS: readonly [",", "\t", ";", "|"];
12
+ export type Delimiter = string;
13
+ /**
14
+ * Split delimited text into rows of raw string fields.
15
+ *
16
+ * Values keep the exact text they had: trimming and type conversion are separate
17
+ * decisions made later, where the caller's options are in scope.
18
+ */
19
+ export declare function parseDelimitedText(text: string, delimiter: Delimiter): string[][];
20
+ /**
21
+ * Guess the delimiter from the text itself.
22
+ *
23
+ * Scores each candidate on how *consistently* it splits the first several lines
24
+ * rather than on how often it appears: prose full of commas scores badly because
25
+ * its lines disagree about the field count, while a two-column TSV scores
26
+ * perfectly on one tab per line. Quoted sections are skipped, so a comma inside
27
+ * `"Smith, J"` never votes for comma.
28
+ *
29
+ * Falls back to comma, which is both the commonest and the least surprising
30
+ * thing to be wrong about.
31
+ */
32
+ export declare function detectDelimiter(text: string, candidates?: readonly string[]): Delimiter;
33
+ /**
34
+ * Strip a UTF-8 byte-order mark.
35
+ *
36
+ * Excel writes one on every CSV it exports, and left in place it becomes part of
37
+ * the first header cell — where it is invisible, so the column looks right and
38
+ * every lookup against its name silently misses.
39
+ */
40
+ export declare function stripBom(text: string): string;
@@ -12,6 +12,15 @@ import type { Diagnostic } from "../types";
12
12
  export interface TranslateFormulaOptions {
13
13
  sheetName?: string;
14
14
  cellReference?: string;
15
+ /**
16
+ * The table the formula's own cell sits inside, when it sits inside one.
17
+ *
18
+ * Excel drops the table name from a current-row reference that points at the
19
+ * table the formula is already in, so `[@Payload]` is what the author sees.
20
+ * Supplying it here reproduces that, and leaving it out keeps the name — which
21
+ * is still correct, just more verbose than Excel would be.
22
+ */
23
+ containingTableName?: string;
15
24
  }
16
25
  export interface TranslatedFormula {
17
26
  /** Engine formula text, including the leading `=`. */
@@ -35,3 +44,8 @@ export declare function findUnsupportedFunctions(formulaBody: string): string[];
35
44
  * (`$A$1`) stay put.
36
45
  */
37
46
  export declare function offsetFormulaReferences(formulaBody: string, deltaCols: number, deltaRows: number): string;
47
+ /**
48
+ * `Table[[#This Row],[Col]]` → `Table[@Col]`, or `[@Col]` when the formula is
49
+ * already inside that table.
50
+ */
51
+ export declare function contractThisRowReferences(formulaBody: string, containingTableName?: string): string;
@@ -21,7 +21,9 @@ export type DiagnosticCode =
21
21
  /** A table could not be created. */
22
22
  | "skipped-table"
23
23
  /** A sheet was skipped, for example a chart sheet. */
24
- | "skipped-sheet";
24
+ | "skipped-sheet"
25
+ /** A delimiter had to be guessed from the text. */
26
+ | "guessed-delimiter";
25
27
  export interface Diagnostic {
26
28
  severity: DiagnosticSeverity;
27
29
  code: DiagnosticCode;
@@ -113,6 +115,45 @@ export interface ConvertOptions {
113
115
  */
114
116
  sheets?: string[];
115
117
  }
118
+ /**
119
+ * Options for reading delimited text (CSV, TSV).
120
+ *
121
+ * The parsing defaults match what a spreadsheet does with the same file, on the
122
+ * grounds that the file usually came out of one.
123
+ *
124
+ * There is deliberately no option to keep `=`-leading fields as text. The engine
125
+ * stores a formula as a string beginning with `=` and has no escape for text
126
+ * that merely looks like one, so such an option could only be honoured by
127
+ * altering the value — which is worse than not offering it.
128
+ */
129
+ export interface CsvConvertOptions {
130
+ /** Name for the single sheet the file becomes. @default "Sheet1" */
131
+ sheetName?: string;
132
+ /** Recorded in workbook metadata. */
133
+ fileName?: string;
134
+ /**
135
+ * Field separator. Detected from the text when omitted, which is the right
136
+ * choice for `.csv` — the extension says nothing about the separator, and a
137
+ * comma-decimal locale writes semicolons.
138
+ */
139
+ delimiter?: string;
140
+ /**
141
+ * Convert plain decimals to numbers. Leading-zero strings and integers too
142
+ * long to survive as floats are kept as text either way.
143
+ * @default true
144
+ */
145
+ parseNumbers?: boolean;
146
+ /** Convert `TRUE` / `FALSE` (any case) to booleans. @default true */
147
+ parseBooleans?: boolean;
148
+ /**
149
+ * Strip surrounding whitespace from every field.
150
+ *
151
+ * Off by default because the whitespace may be data, and a quoted field that
152
+ * carries it meant to.
153
+ * @default false
154
+ */
155
+ trimFields?: boolean;
156
+ }
116
157
  export interface ConvertResult {
117
158
  data: ExcelWorkbookData;
118
159
  diagnostics: Diagnostic[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/excel-to-formula-engine",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Convert an Excel .xlsx file into FormulaEngine WorkbookData, in the browser",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",