0.0.1 • Published 8 years ago
payload-parser v0.0.1
What is it?
A isomorphic, bullet-proof, ninja-ready payload parsing, matching, and reversing library for Javascript in Node and the browser.
Based on route-parser.
Is it any good?
Yes.
Why do I want it?
You want to write string payloads in a way that makes sense, capture named parameters, add additional constraints, and be able to easily generate payloads.
How do I install it?
npm install --save payload-parser
How do I use it?
Payload = require('payload-parser');
var payload = new Payload('MY_FANCY_PAYLOAD_:id');
payload.match('MY_FANCY_PAYLOAD_7') // { id: 7 }
payload.reverse({id: 3}) // -> 'MY_FANCY_PAYLOAD_3'
What can I use in my routes?
Example | Description |
---|---|
:name | a parameter to capture from the payload up to / , ? , or end of string |
*splat | a splat to capture from the payload up to ? or end of string |
() | Optional group that doesn't have to be part of the query. Can contain nested optional groups, params, and splats |
anything else | free form literals |
Some examples:
SOME_(optional_):thing
ITEM_ID_:id
0.0.1
8 years ago