0.0.2 • Published 7 years ago

js-parser-combinators v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

js-parser-combinators

Building blocks to write your own tiny and fast parsers.

CircleCI

const P = require('js-parser-combinators')

// A parser that can parse paths such as:
//    /user/1234
//    /user/1234/details

const parser = P.exhaustive(
    P.and(
        P.and(
            P.literal('/user/'),
            P.param('userid', /^\d+/, parseInt)
        ),
        P.optional(P.literal('/details'))
    )
);

parser({ input: '/user/1234/details' }).ast
// => { userid: 1234 }

Run this example on RunKit

0.0.2

7 years ago

0.0.1

7 years ago

0.0.0

7 years ago