Skip to content

Commit

Permalink
[#IP-342] update utils/types.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
gquadrati committed Sep 3, 2021
1 parent 7999013 commit 398ecd5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { tryCatch2v } from "fp-ts/lib/Either";
import { identity } from "fp-ts/lib/function";
import * as E from "fp-ts/lib/Either";
import { identity, pipe } from "fp-ts/lib/function";
import * as t from "io-ts";
import { NonEmptyString } from "@pagopa/ts-commons/lib/strings";

Expand All @@ -11,11 +11,17 @@ export const jsonFromString = new t.Type<object, string>( // eslint-disable-line
"JSONFromString",
t.UnknownRecord.is,
(m, c) =>
t.string.validate(m, c).chain(s =>
tryCatch2v(
() => t.success(JSON.parse(s)),
_ => t.failure(s, c)
).fold(identity, identity)
pipe(
t.string.validate(m, c),
E.chain(s =>
pipe(
E.tryCatch(
() => t.success(JSON.parse(s)),
_ => t.failure(s, c)
),
E.fold(identity, identity)
)
)
),
String
);
Expand Down

0 comments on commit 398ecd5

Please sign in to comment.