| Total Complexity | 8 |
| Complexity/F | 1.14 |
| Lines of Code | 18 |
| Function Count | 7 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | "use strict"; |
||
| 2 | Object.defineProperty(exports, "__esModule", { value: true }); |
||
| 3 | var Either_1 = require("fp-ts/lib/Either"); |
||
| 4 | var pipeable_1 = require("fp-ts/lib/pipeable"); |
||
| 5 | var TaskEither_1 = require("fp-ts/lib/TaskEither"); |
||
| 6 | var fs_1 = require("fs"); |
||
| 7 | var TE = pipeable_1.pipeable(TaskEither_1.taskEither); |
||
| 8 | var fromString = function (s) { return Either_1.tryCatch(function () { return JSON.parse(s); }, function (error) { return error instanceof Error |
||
| 9 | ? error |
||
| 10 | : Error('Cannot parse JSON data'); }); }; |
||
| 11 | var fromFile = function (path) { return pipeable_1.pipe(TaskEither_1.taskify(fs_1.readFile)(path), TE.mapLeft(function (_a) { |
||
| 12 | var message = _a.message; |
||
| 13 | return Error(message); |
||
| 14 | }), TE.map(function (b) { return b.toString(); }), TE.chain(function (s) { return TaskEither_1.fromEither(fromString(s)); })); }; |
||
| 15 | exports.Json = { |
||
| 16 | fromFile: fromFile, |
||
| 17 | fromString: fromString |
||
| 18 | }; |
||
| 19 |