-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from fslaborg/json
Added json IO
- Loading branch information
Showing
45 changed files
with
713 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace FsSpreadsheet.Js | ||
|
||
open FsSpreadsheet | ||
open Fable.ExcelJs | ||
open Fable.Core | ||
open Fable.Core.JsInterop | ||
open Fable.Core.JS | ||
|
||
open Thoth.Json.JavaScript | ||
|
||
|
||
|
||
|
||
/// This does currently not correctly work if you want to use this from js | ||
/// https://github.com/fable-compiler/Fable/issues/3498 | ||
[<AttachMembers>] | ||
type Json = | ||
|
||
static member tryFromJsonString (json:string) : Result<FsWorkbook, string> = | ||
match Thoth.Json.JavaScript.Decode.fromString FsSpreadsheet.Json.Workbook.decode json with | ||
| Ok wb -> Ok wb | ||
| Error e -> Error e | ||
|
||
static member fromJsonString (json:string) : FsWorkbook = | ||
match Json.tryFromJsonString json with | ||
| Ok wb -> wb | ||
| Error e -> failwithf "Could not deserialize json Workbook: \n%s" e | ||
|
||
static member toJsonString (wb:FsWorkbook, ?spaces) : string = | ||
let spaces = defaultArg spaces 2 | ||
FsSpreadsheet.Json.Workbook.encode wb | ||
|> Thoth.Json.JavaScript.Encode.toString spaces | ||
|
||
//static member fromJsonFile (path:string) : Promise<FsWorkbook> = | ||
// promise { | ||
// let! json = Fable.Core.JS. path | ||
// return Json.fromJsonString json | ||
// } | ||
|
||
//static member toJsonFile (path:string) (wb:FsWorkbook) : Promise<unit> = | ||
// let json = Json.toJsonString wb | ||
// Fable.Core.JS.writeFile path json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.