Effect-friendly helpers for @parseysharp/parseyscript.
This package exports a small ParseEffect helper object that:
- Lifts optional values from
Maybe<A>toOption.Option<A>. - Converts parse results from
ParseResult<A, E>toEither.Either<A, E>. - Provides pipeable combinators that match the core library's pipeable style.
For details on Parse, Navigator, Maybe, and ParseResult, see the core ParseyScript README.
Install the core library, this extension, and effect:
npm install @parseysharp/parseyscript @parseysharp/parseyscript-effect effect@parseysharp/parseyscript and effect are peer dependencies of this package; your application should depend on them directly.
The main export is a ParseEffect helper object composed of pipeable functions:
-
ParseEffect.optionParseEffect.option: <A>(p: Parse<A>) => Parse<Option.Option<A>>
Lifts a
Parse<A>intoParse<Option.Option<A>>by delegating toParse.maybeand converting theMayberesult into anOption. -
ParseEffect.optionAt(head, tail)ParseEffect.optionAt: (head: string | number, tail: (string | number)[]) => <A>(p: Parse<A>) => Parse<Option.Option<A>>
Like calling
p.maybeAt(head, tail)and then mappingMaybe<A>toOption.Option<A>, but as a pipeable combinator. -
ParseEffect.parseEither(nav, x)ParseEffect.parseEither: <B>(nav: Navigator<B>, x: Maybe<B>) => <A>(p: Parse<A>) => Either.Either<A, FmtParseError[]>
Runs a
Parse<A>and converts theParseResult<A, FmtParseError[]>into anEitherfromeffect.
All helpers are designed to be used with the pipeable Parse API in the core library.
import * as P from "@parseysharp/parseyscript";
import { ParseEffect } from "@parseysharp/parseyscript-effect";
const parser = P.Parse.zip4(
P.Parse.string().pipe(ParseEffect.optionAt("some", ["nested", "path"])),
P.Parse.dateTimeOffsetFlex({ epochIsMilliseconds: true }).at("some", [
"other",
"path",
]),
P.Parse.bool().at("the", ["flag"]),
P.Parse.floatFlex().at("the", ["number"])
);
const input = {
the: {
number: 23,
flag: "false",
},
some: {
other: { path: "1762912054467" },
nested: { path: "hello" },
},
};
const result = parser.pipe(
ParseEffect.parseEither(P.Navigator.unknown(), P.Maybe.fromNullable(input))
);You can also use these helpers directly on smaller parsers and then compose with the rest of the fluent Parse API.