diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-12-19 21:04:23 +0100 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-12-19 21:04:23 +0100 |
| commit | 44ff6231441024d16fddc2b7cb648539522b04cb (patch) | |
| tree | 8302d0734f4ce931631ffe6d43af5b9a5da284a0 /src/lib/Saving.ts | |
| parent | 9f4618c5ef618521ce1ab680d82ed9cc941d10d8 (diff) | |
| download | digit-single-44ff6231441024d16fddc2b7cb648539522b04cb.tar.gz digit-single-44ff6231441024d16fddc2b7cb648539522b04cb.tar.zst digit-single-44ff6231441024d16fddc2b7cb648539522b04cb.zip | |
v1.0.0
Added everything that's in the spec
Diffstat (limited to 'src/lib/Saving.ts')
| -rw-r--r-- | src/lib/Saving.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/lib/Saving.ts b/src/lib/Saving.ts index 0d71057..8017fd1 100644 --- a/src/lib/Saving.ts +++ b/src/lib/Saving.ts @@ -8,18 +8,19 @@ export function save(grid: Grid) { a.download = "sudoku-save.json"; a.click(); } -export function readGridFromFile(f: File): Promise<string[][] | null> { +export function readGridFromFile(f?: File): Promise<string[][] | null> { return new Promise(res => { let reader = new FileReader(); reader.onload = e => { try { - //@ts-expect-error - const json = JSON.parse(e.target.result); - res(json) + if (typeof e.target?.result === "string") + res(JSON.parse(e.target.result)) + else + res(null) } catch (error) { res(null) } }; - reader.readAsText(f); + f ? reader.readAsText(f) : f; }) } |
