Path matching utility based on the RAML spec
npm install raml-path-match[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]

Path matching utility based on the RAML spec.
``shell`
npm install raml-path-match --save
You must require the module and call it as a function with options to get the path matching utility back.
`javascript
const ramlPathMatch = require('raml-path-match')
const utils = require('./utils')
// Initialization Options
const options = {}
// Array
const parameters = utils.getPathParameters()
// Create a simple path matching instance.
const pathMatch = ramlPathMatch('/{route}', parameters, options)
pathMatch('/test'); //=> { match: '/test', params: { route: 'test' } }
`
* end - When set to false, the route will only match the beginning of paths.true
* strict - When set to , the route must match exactly without trailing slash.true
* sensitive - When set to , the route will be case-sensitive.
The route is a string that can be interpolated with parameters. E.g. /{route}.
Parameters in the route string must be defined as an array of webapi-parser Parameter objects.
#### Optional parameters
Parameters can be optional according to the RAML spec. With optional parameters, /{route} will match just /. When the parameter is optional and not matched, the parameter value will be set to undefined.
The path matching instance will return a function after you give it the route template. This function is used to match the current path against the route template. If the route does not match, false is returned. If it does match, an object will be returned.
`javascript`
{
match: '/123',
params: {
route: 123
}
}
The above is an example of passing the path /123 to the result of the previous example. Notice that parameters will be automatically sanitized to the native JavaScript types.
You can merge more parameters into the path after creation using pathMatch.update(params)`. It'll return a new patch matching function.
Apache 2.0
[npm-image]: https://img.shields.io/npm/v/raml-path-match.svg?style=flat
[npm-url]: https://npmjs.org/package/raml-path-match
[travis-image]: https://img.shields.io/travis/mulesoft-labs/raml-path-match.svg?style=flat
[travis-url]: https://travis-ci.org/mulesoft-labs/raml-path-match
[coveralls-image]: https://img.shields.io/coveralls/mulesoft-labs/raml-path-match.svg?style=flat
[coveralls-url]: https://coveralls.io/r/mulesoft-labs/raml-path-match?branch=master