gridmd 1.0.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,34 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ lint
4
+ } from "./chunk-jz0c1a5d.js";
5
+
6
+ // bin/gridmd-lint.ts
7
+ import { readFileSync } from "node:fs";
8
+ var argv = process.argv.slice(2);
9
+ var lenient = argv.includes("--lenient");
10
+ var files = argv.filter((a) => !a.startsWith("--"));
11
+ if (files.length === 0) {
12
+ console.error("usage: gridmd-lint [--lenient] <file.gmd> …");
13
+ process.exit(2);
14
+ }
15
+ var failed = false;
16
+ for (const file of files) {
17
+ let source;
18
+ try {
19
+ source = readFileSync(file, "utf8");
20
+ } catch (e) {
21
+ console.error(`${file}: ${e instanceof Error ? e.message : String(e)}`);
22
+ failed = true;
23
+ continue;
24
+ }
25
+ const res = lint(source, { mode: lenient ? "lenient" : "strict" });
26
+ for (const w of res.warnings)
27
+ console.log(`${file}:${w.line}: warning: ${w.msg}`);
28
+ for (const e of res.errors)
29
+ console.log(`${file}:${e.line}: error: ${e.msg}`);
30
+ console.log(`${file}: ${res.errors.length} error(s), ${res.warnings.length} warning(s) — ` + `${res.sheets} sheet(s), ${res.cells} defined cell(s), ${res.blocks} block(s)`);
31
+ if (res.errors.length)
32
+ failed = true;
33
+ }
34
+ process.exit(failed ? 1 : 0);
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ buildWorkbookModel,
4
+ lint,
5
+ writeXlsx
6
+ } from "./chunk-jz0c1a5d.js";
7
+
8
+ // bin/gridmd2xlsx.ts
9
+ import { readFileSync, writeFileSync } from "node:fs";
10
+ import { dirname } from "node:path";
11
+ var argv = process.argv.slice(2);
12
+ var strict = argv.includes("--strict");
13
+ var files = argv.filter((a) => !a.startsWith("-"));
14
+ var oIdx = argv.indexOf("-o");
15
+ var outArg = oIdx !== -1 ? argv[oIdx + 1] : null;
16
+ var input = files.filter((f) => f !== outArg)[0];
17
+ if (!input) {
18
+ console.error("usage: gridmd2xlsx <file.gmd> [-o out.xlsx] [--strict]");
19
+ process.exit(2);
20
+ }
21
+ var source = readFileSync(input, "utf8");
22
+ var res = lint(source, { mode: "strict" });
23
+ if (res.errors.length) {
24
+ for (const e of res.errors)
25
+ console.error(`${input}:${e.line}: error: ${e.msg}`);
26
+ console.error(`${input}: ${res.errors.length} error(s) — fix the document before converting`);
27
+ process.exit(1);
28
+ }
29
+ var model = buildWorkbookModel(res.doc, { baseDir: dirname(input) });
30
+ var { buffer, report } = writeXlsx(model);
31
+ var out = outArg ?? input.replace(/\.gmd$/, "") + ".xlsx";
32
+ writeFileSync(out, buffer);
33
+ var notEmitted = report.filter((r) => r.action === "not-emitted");
34
+ var carried = report.filter((r) => r.action === "carried");
35
+ var partial = report.filter((r) => r.action === "partial");
36
+ for (const r of report) {
37
+ console.log(`${input}:${r.line}: ${r.action}: ${r.feature}${r.note ? ` (${r.note})` : ""}`);
38
+ }
39
+ console.log(`${out}: written (${buffer.length} bytes) — ${carried.length} carried, ${partial.length} partial, ${notEmitted.length} not emitted`);
40
+ if (notEmitted.length) {
41
+ console.log("fidelity: the features above are NOT in the .xlsx — v0 emits the worksheet core only (see INTEROP.md §2)");
42
+ }
43
+ process.exit(strict && notEmitted.length ? 1 : 0);
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ lint,
4
+ xlsxToGridmd
5
+ } from "./chunk-jz0c1a5d.js";
6
+
7
+ // bin/xlsx2gridmd.ts
8
+ import { readFileSync, writeFileSync } from "node:fs";
9
+ var argv = process.argv.slice(2);
10
+ var files = argv.filter((a) => !a.startsWith("-"));
11
+ var oIdx = argv.indexOf("-o");
12
+ var outArg = oIdx !== -1 ? argv[oIdx + 1] : null;
13
+ var input = files.filter((f) => f !== outArg)[0];
14
+ if (!input) {
15
+ console.error("usage: xlsx2gridmd <file.xlsx> [-o out.gmd]");
16
+ process.exit(2);
17
+ }
18
+ var { gmd, report } = xlsxToGridmd(readFileSync(input));
19
+ for (const r of report)
20
+ console.log(`${input}: ${r.action}: ${r.feature}${r.note ? ` (${r.note})` : ""}`);
21
+ var res = lint(gmd, { mode: "strict" });
22
+ for (const e of res.errors)
23
+ console.error(`self-check:${e.line}: error: ${e.msg}`);
24
+ var out = outArg ?? input.replace(/\.(xlsx|xlsm)$/, "") + ".gmd";
25
+ writeFileSync(out, gmd);
26
+ console.log(`${out}: written — ${res.sheets} sheet(s), ${res.cells} defined cell(s); self-check ${res.errors.length === 0 ? "clean" : `FAILED (${res.errors.length} error(s))`}`);
27
+ process.exit(res.errors.length ? 1 : 0);
package/dist/calc.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { WorkbookModel } from './types';
2
+ export declare class Unsupported extends Error {
3
+ }
4
+ declare const BLANK: unique symbol;
5
+ type Blank = typeof BLANK;
6
+ interface ErrVal {
7
+ err: string;
8
+ }
9
+ type Value = number | string | boolean | ErrVal | Blank | Value[];
10
+ interface Ctx {
11
+ sheet: string;
12
+ col?: number;
13
+ row?: number;
14
+ env?: Map<string, Value>;
15
+ }
16
+ export interface Evaluator {
17
+ evaluateCell: (sheetName: string, ref: string) => Value;
18
+ evaluateFormula: (formula: string, ctx: Ctx) => Value;
19
+ BLANK: Blank;
20
+ }
21
+ export declare function createEvaluator(model: WorkbookModel): Evaluator;
22
+ export interface Mismatch {
23
+ where: string;
24
+ formula: string;
25
+ cached: Value | null;
26
+ computed: Value;
27
+ }
28
+ export interface UnsupportedItem {
29
+ where: string;
30
+ formula: string;
31
+ reason: string;
32
+ }
33
+ export interface VerifyResult {
34
+ checked: number;
35
+ mismatches: Mismatch[];
36
+ unsupported: UnsupportedItem[];
37
+ }
38
+ export declare function verifyCachedValues(model: WorkbookModel, { tolerance }?: {
39
+ tolerance?: number;
40
+ }): VerifyResult;
41
+ export {};
package/dist/dump.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import type { WorkbookModel } from './types';
2
+ export declare function dumpModel(model: WorkbookModel): string;
@@ -0,0 +1,16 @@
1
+ import type { LintResult } from './types';
2
+ export { parseDocument } from './parser';
3
+ export { validateDocument, isValidPartPath } from './validate';
4
+ export { parseScalar, splitCached, ERROR_VALUES } from './scalar';
5
+ export { parseTarget, parseCell, colToNum, numToCol, MAX_COL, MAX_ROW } from './refs';
6
+ export { findPropsSplit, tryProps, splitPipeRow, parseInfoArgs, parseYaml, RESERVED_KINDS } from './parser';
7
+ export { buildWorkbookModel, translateFormula } from './xlsx/model';
8
+ export { writeXlsx } from './xlsx/write';
9
+ export { xlsxToGridmd } from './xlsx/read';
10
+ export { dumpModel } from './dump';
11
+ export { verifyCachedValues, createEvaluator, Unsupported } from './calc';
12
+ export { zipRead, zipWrite, crc32 } from './xlsx/zip';
13
+ export type * from './types';
14
+ export declare function lint(source: string, opts?: {
15
+ mode?: string;
16
+ }): LintResult;