Passed
Push — master ( 850f91...109844 )
by Alberto
04:39 queued 02:29
created

lib/Json.js   A

Complexity

Total Complexity 8
Complexity/F 1.14

Size

Lines of Code 18
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 17
mnd 1
bc 1
fnc 7
dl 0
loc 18
bpm 0.1428
cpm 1.1428
noi 0
c 0
b 0
f 0
rs 10
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