New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

parser-ts

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parser-ts - npm Package Compare versions

Comparing version 0.4.3 to 0.5.0

5

CHANGELOG.md

@@ -16,2 +16,7 @@ # Changelog

# 0.5.0
* **Breaking Change**
* upgrade to `fp-ts@1.x.x` (@gcanti)
# 0.4.3

@@ -18,0 +23,0 @@

12

lib/char.d.ts
import { Parser } from '.';
export declare type Char = string;
/** The `char` parser constructor returns a parser which matches only the
/**
* The `char` parser constructor returns a parser which matches only the
* specified single character
*/
export declare function char(c: Char): Parser<Char>;
/** Takes a `Parser<string>` and matches it zero or more times, returning
/**
* Takes a `Parser<string>` and matches it zero or more times, returning
* a `String` of what was matched.
*/
export declare function many(parser: Parser<Char>): Parser<string>;
/** Takes a `Parser<string>` and matches it one or more times, returning
/**
* Takes a `Parser<string>` and matches it one or more times, returning
* a `String` of what was matched.
*/
export declare function many1(parser: Parser<Char>): Parser<string>;
/** The `notChar` parser constructor makes a parser which will match any
/**
* The `notChar` parser constructor makes a parser which will match any
* single character other than the one provided.

@@ -17,0 +21,0 @@ */

@@ -5,3 +5,4 @@ "use strict";

var p = require(".");
/** The `char` parser constructor returns a parser which matches only the
/**
* The `char` parser constructor returns a parser which matches only the
* specified single character

@@ -13,3 +14,4 @@ */

exports.char = char;
/** Takes a `Parser<string>` and matches it zero or more times, returning
/**
* Takes a `Parser<string>` and matches it zero or more times, returning
* a `String` of what was matched.

@@ -21,3 +23,4 @@ */

exports.many = many;
/** Takes a `Parser<string>` and matches it one or more times, returning
/**
* Takes a `Parser<string>` and matches it one or more times, returning
* a `String` of what was matched.

@@ -29,3 +32,4 @@ */

exports.many1 = many1;
/** The `notChar` parser constructor makes a parser which will match any
/**
* The `notChar` parser constructor makes a parser which will match any
* single character other than the one provided.

@@ -32,0 +36,0 @@ */

import { Monoid } from 'fp-ts/lib/Monoid';
import { Monad, FantasyMonad } from 'fp-ts/lib/Monad';
import { Alternative, FantasyAlternative } from 'fp-ts/lib/Alternative';
import { Monad1 } from 'fp-ts/lib/Monad';
import { Alternative1 } from 'fp-ts/lib/Alternative';
import { Either } from 'fp-ts/lib/Either';

@@ -21,3 +21,3 @@ import { Predicate } from 'fp-ts/lib/function';

export declare type ParseResult<A> = Either<ParseFailure, ParseSuccess<A>>;
export declare class Parser<A> implements FantasyMonad<URI, A>, FantasyAlternative<URI, A> {
export declare class Parser<A> {
readonly run: (s: string) => ParseResult<A>;

@@ -30,15 +30,5 @@ readonly _A: A;

chain<B>(f: (a: A) => Parser<B>): Parser<B>;
zero<B>(): Parser<B>;
alt(fa: Parser<A>): Parser<A>;
}
export declare const map: <A, B>(f: (a: A) => B, fa: Parser<A>) => Parser<B>;
export declare const of: <A>(a: A) => Parser<A>;
export declare const ap: <A, B>(fab: Parser<(a: A) => B>, fa: Parser<A>) => Parser<B>;
export declare const chain: <A, B>(f: (a: A) => Parser<B>, fa: Parser<A>) => Parser<B>;
export declare const alt: <A>(fx: Parser<A>, fy: Parser<A>) => Parser<A>;
export declare const alts: <A>(...fs: Parser<A>[]) => Parser<A>;
export declare const zero: <A>() => Parser<A>;
export declare const emptyString: Parser<string>;
export declare const empty: () => Parser<string>;
export declare const concat: (x: Parser<string>) => (y: Parser<string>) => Parser<string>;
export declare const createParseFailure: <A>(remaining: string, message: string) => Either<ParseFailure, [A, string]>;

@@ -59,8 +49,2 @@ export declare const createParseSuccess: <A>(a: A, s: string) => Either<ParseFailure, [A, string]>;

/**
* A parser combinator which returns the provided parser unchanged, except
* that if it fails, the provided error message will be returned in the
* `ParseFailure`.
*/
export declare const expected: <A>(parser: Parser<A>, message: string) => Parser<A>;
/**
* The `succeed` parser constructor creates a parser which will simply

@@ -72,2 +56,8 @@ * return the value provided as its argument, without consuming any input.

export declare const succeed: <A>(a: A) => Parser<A>;
/**
* A parser combinator which returns the provided parser unchanged, except
* that if it fails, the provided error message will be returned in the
* `ParseFailure`.
*/
export declare const expected: <A>(parser: Parser<A>, message: string) => Parser<A>;
/** The `item` parser consumes a single value, regardless of what it is,

@@ -86,3 +76,3 @@ * and returns it as its result.

*/
export declare const seq: <A, B>(f: (a: A) => Parser<B>, fa: Parser<A>) => Parser<B>;
export declare const seq: <A, B>(fa: Parser<A>, f: (a: A) => Parser<B>) => Parser<B>;
/**

@@ -113,3 +103,2 @@ * The `either` combinator takes two parsers, runs the first on the input

export declare const eof: Parser<undefined>;
export declare const fold: (ps: Parser<string>[]) => Parser<string>;
/**

@@ -145,2 +134,3 @@ * The `many` combinator takes a parser, and returns a new parser which will

export declare const sepBy1: <A, B>(sep: Parser<A>, parser: Parser<B>) => Parser<NonEmptyArray<B>>;
export declare const parser: Monad<URI> & Alternative<URI> & Monoid<Parser<string>>;
export declare const parser: Monad1<URI> & Alternative1<URI> & Monoid<Parser<string>>;
export declare const fold: (ps: Array<Parser<string>>) => Parser<string>;

@@ -32,5 +32,2 @@ "use strict";

};
Parser.prototype.zero = function () {
return exports.zero();
};
Parser.prototype.alt = function (fa) {

@@ -46,7 +43,10 @@ var _this = this;

exports.Parser = Parser;
exports.map = function (f, fa) { return fa.map(f); };
exports.of = function (a) { return new Parser(function (s) { return exports.createParseSuccess(a, s); }); };
exports.ap = function (fab, fa) { return fa.ap(fab); };
exports.chain = function (f, fa) { return fa.chain(f); };
exports.alt = function (fx, fy) { return fx.alt(fy); };
var map = function (fa, f) { return fa.map(f); };
var of = function (a) { return new Parser(function (s) { return exports.createParseSuccess(a, s); }); };
var ap = function (fab, fa) { return fa.ap(fab); };
var chain = function (fa, f) { return fa.chain(f); };
var alt = function (fx, fy) { return fx.alt(fy); };
var zero = function () { return exports.fail; };
var empty = of('');
var concat = function (x, y) { return y.ap(x.map(function (a) { return function (b) { return a + b; }; })); };
exports.alts = function () {

@@ -59,8 +59,2 @@ var fs = [];

};
exports.zero = function () { return exports.fail; };
exports.emptyString = exports.of('');
exports.empty = function () { return exports.emptyString; };
exports.concat = function (x) { return function (y) {
return y.ap(x.map(function (a) { return function (b) { return a + b; }; }));
}; };
//

@@ -97,2 +91,9 @@ // helpers

/**
* The `succeed` parser constructor creates a parser which will simply
* return the value provided as its argument, without consuming any input.
*
* This is equivalent to the monadic `of`
*/
exports.succeed = of;
/**
* A parser combinator which returns the provided parser unchanged, except

@@ -108,9 +109,2 @@ * that if it fails, the provided error message will be returned in the

};
/**
* The `succeed` parser constructor creates a parser which will simply
* return the value provided as its argument, without consuming any input.
*
* This is equivalent to the monadic `of`
*/
exports.succeed = exports.of;
/** The `item` parser consumes a single value, regardless of what it is,

@@ -120,3 +114,3 @@ * and returns it as its result.

exports.item = new Parser(function (s) {
return exports.getAndNext(s).fold(function () { return exports.createParseFailure(s, 'Parse failed on item'); }, function (_a) {
return exports.getAndNext(s).foldL(function () { return exports.createParseFailure(s, 'Parse failed on item'); }, function (_a) {
var c = _a[0], s = _a[1];

@@ -135,3 +129,3 @@ return exports.createParseSuccess(c, s);

*/
exports.seq = exports.chain;
exports.seq = chain;
/**

@@ -144,3 +138,3 @@ * The `either` combinator takes two parsers, runs the first on the input

*/
exports.either = exports.alt;
exports.either = alt;
/**

@@ -156,3 +150,3 @@ * The `sat` parser constructor takes a predicate function, and will consume

.chain(function (x) { return (predicate(x[0]) ? Option_1.some(x) : Option_1.none); })
.fold(function () { return exports.createParseFailure(s, 'Parse failed on sat'); }, function (_a) {
.foldL(function () { return exports.createParseFailure(s, 'Parse failed on sat'); }, function (_a) {
var c = _a[0], s = _a[1];

@@ -168,3 +162,3 @@ return exports.createParseSuccess(c, s);

*/
exports.maybe = function (parser) { return parser.alt(exports.empty()); };
exports.maybe = function (parser) { return parser.alt(empty); };
/**

@@ -174,3 +168,2 @@ * Matches the end of the input

exports.eof = new Parser(function (s) { return (s === '' ? exports.createParseSuccess(undefined, '') : exports.createParseFailure(s, 'end of file')); });
exports.fold = function (ps) { return Monoid_1.fold(exports.parser)(ps); };
/**

@@ -185,3 +178,3 @@ * The `many` combinator takes a parser, and returns a new parser which will

*/
exports.many = function (parser) { return exports.alt(exports.many1(parser).map(function (a) { return a.toArray(); }), exports.of([])); };
exports.many = function (parser) { return alt(exports.many1(parser).map(function (a) { return a.toArray(); }), of([])); };
/**

@@ -193,3 +186,3 @@ * The `many1` combinator is just like the `many` combinator, except it

exports.many1 = function (parser) {
return parser.chain(function (head) { return exports.many(parser).chain(function (tail) { return exports.of(new NonEmptyArray_1.NonEmptyArray(head, tail)); }); });
return parser.chain(function (head) { return exports.many(parser).chain(function (tail) { return of(new NonEmptyArray_1.NonEmptyArray(head, tail)); }); });
};

@@ -202,7 +195,7 @@ /**

exports.sepBy = function (sep, parser) {
return exports.alt(exports.sepBy1(sep, parser).map(function (a) { return a.toArray(); }), exports.alt(parser.map(function (a) { return [a]; }), exports.of([])));
return alt(exports.sepBy1(sep, parser).map(function (a) { return a.toArray(); }), alt(parser.map(function (a) { return [a]; }), of([])));
};
/** Matches both parsers and return the value of the second */
exports.second = function (pa) { return function (pb) {
return new Parser(function (s) { return Apply_1.applySecond(exports.parser)(pa)(pb).run(s); });
return new Parser(function (s) { return applySecondParser(pa, pb).run(s); });
}; };

@@ -215,15 +208,17 @@ /**

exports.sepBy1 = function (sep, parser) {
return parser.chain(function (head) { return exports.alt(exports.many(exports.second(sep)(parser)), exports.of([])).chain(function (tail) { return exports.of(new NonEmptyArray_1.NonEmptyArray(head, tail)); }); });
return parser.chain(function (head) { return alt(exports.many(exports.second(sep)(parser)), of([])).chain(function (tail) { return of(new NonEmptyArray_1.NonEmptyArray(head, tail)); }); });
};
exports.parser = {
URI: exports.URI,
map: exports.map,
of: exports.of,
ap: exports.ap,
chain: exports.chain,
zero: exports.zero,
alt: exports.alt,
empty: exports.empty,
concat: exports.concat
map: map,
of: of,
ap: ap,
chain: chain,
zero: zero,
alt: alt,
empty: empty,
concat: concat
};
exports.fold = Monoid_1.fold(exports.parser);
var applySecondParser = Apply_1.applySecond(exports.parser);
//# sourceMappingURL=index.js.map

@@ -1,10 +0,10 @@

import { HKT } from 'fp-ts/lib/HKT';
import { Option } from 'fp-ts/lib/Option';
import { Foldable } from 'fp-ts/lib/Foldable';
import { Parser } from '.';
/** Matches the given parser zero or more times, returning a string of the
/**
* Matches the given parser zero or more times, returning a string of the
* entire match
*/
export declare function many(parser: Parser<string>): Parser<string>;
/** Matches the given parser one or more times, returning a string of the
/**
* Matches the given parser one or more times, returning a string of the
* entire match

@@ -16,3 +16,2 @@ */

export declare function string(prefix: string): Parser<string>;
export declare function oneOfF<F>(foldable: Foldable<F>): (fs: HKT<F, string>) => Parser<string>;
/** Matches one of a list of strings. */

@@ -31,3 +30,4 @@ export declare function oneOf(ss: Array<string>): Parser<string>;

export declare const doubleQuote: Parser<string>;
/** Parses a double quoted string, with support for escaping double quotes
/**
* Parses a double quoted string, with support for escaping double quotes
* inside it, and returns the inner string. Does not perform any other form

@@ -34,0 +34,0 @@ * of string escaping.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Option_1 = require("fp-ts/lib/Option");
var array = require("fp-ts/lib/Array");
var _1 = require(".");
var p = require(".");
var c = require("./char");
/** Matches the given parser zero or more times, returning a string of the
/**
* Matches the given parser zero or more times, returning a string of the
* entire match

@@ -15,3 +15,4 @@ */

exports.many = many;
/** Matches the given parser one or more times, returning a string of the
/**
* Matches the given parser one or more times, returning a string of the
* entire match

@@ -34,3 +35,3 @@ */

return new _1.Parser(function (s) {
return getAndNext(s, prefix).fold(function () { return p.createParseFailure(s, JSON.stringify(prefix)); }, function (_a) {
return getAndNext(s, prefix).foldL(function () { return p.createParseFailure(s, JSON.stringify(prefix)); }, function (_a) {
var c = _a[0], s = _a[1];

@@ -42,9 +43,5 @@ return p.createParseSuccess(c, s);

exports.string = string;
function oneOfF(foldable) {
return function (fs) { return foldable.reduce(function (p, s) { return p.alt(string(s)); }, p.zero(), fs); };
}
exports.oneOfF = oneOfF;
/** Matches one of a list of strings. */
function oneOf(ss) {
return p.expected(oneOfF(array)(ss), "one of " + JSON.stringify(ss));
return p.expected(p.alts.apply(p, ss.map(string)), "one of " + JSON.stringify(ss));
}

@@ -65,7 +62,8 @@ exports.oneOf = oneOf;

var intParsers = [p.maybe(c.char('-')), c.many1(c.digit)];
exports.int = p.expected(p.fold(intParsers).chain(function (s) { return fromString(s).fold(function () { return p.fail; }, function (n) { return p.of(n); }); }), 'an integer');
exports.int = p.expected(p.fold(intParsers).chain(function (s) { return fromString(s).fold(p.fail, p.succeed); }), 'an integer');
var floatParsers = [p.maybe(c.char('-')), c.many(c.digit), p.maybe(p.fold([c.char('.'), c.many1(c.digit)]))];
exports.float = p.expected(p.fold(floatParsers).chain(function (s) { return fromString(s).fold(function () { return p.fail; }, function (n) { return p.of(n); }); }), 'an integer');
exports.float = p.expected(p.fold(floatParsers).chain(function (s) { return fromString(s).fold(p.fail, p.succeed); }), 'a float');
exports.doubleQuote = c.char('"');
/** Parses a double quoted string, with support for escaping double quotes
/**
* Parses a double quoted string, with support for escaping double quotes
* inside it, and returns the inner string. Does not perform any other form

@@ -76,3 +74,3 @@ * of string escaping.

.chain(function () { return many(p.either(string('\\"'), c.notChar('"'))); })
.chain(function (s) { return exports.doubleQuote.chain(function () { return p.of(s); }); });
.chain(function (s) { return exports.doubleQuote.chain(function () { return p.succeed(s); }); });
//# sourceMappingURL=string.js.map
{
"name": "parser-ts",
"version": "0.4.3",
"version": "0.5.0",
"description": "String parser combinators for TypeScript",

@@ -12,3 +12,3 @@ "files": ["lib"],

"typings-checker --allow-expect-error --project typings-checker/tsconfig.json typings-checker/index.ts",
"mocha": "TS_NODE_CACHE=false mocha -r ts-node/register test/*.ts",
"mocha": "TS_NODE_CACHE=false TS_NODE_PROJECT=test/tsconfig.json mocha -r ts-node/register test/*.ts",
"prettier":

@@ -33,3 +33,3 @@ "prettier --no-semi --single-quote --print-width 120 --parser typescript --list-different \"{src,test}/**/*.ts\"",

"dependencies": {
"fp-ts": "^0.6.0"
"fp-ts": "^1.0.1"
},

@@ -36,0 +36,0 @@ "devDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc