Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

raml-path-match

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raml-path-match

Path matching utility based on the RAML spec

  • 2.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
increased by37.1%
Maintainers
4
Weekly downloads
 
Created
Source

RAML Path Match

NPM version Build status Test coverage Greenkeeper badge

Path matching utility based on the RAML spec.

Installation

npm install raml-path-match --save

Usage

You must require the module and call it as a function with options to get the path matching utility back.

var pathMatch = require('raml-path-match')({ ... });

// Create a simple path matching instance.
var match = patchMatch('/{route}', { route: { type: 'string' } });

match('/test'); //=> { match: '/test', params: { route: 'test' } }

Initialization Options

  • end - When set to false, the route will only match the beginning of paths.
  • strict - When set to true, the route must match exactly without trailing slash.
  • sensitive - When set to true, the route will be case-sensitive.
  • RAMLVersion - The RAML version passed to raml-validate (default: 'RAML08')

Routes

The route is a string that can be interpolated with parameters. E.g. /{route}.

Parameters

Parameters in the route string can be defined by passing in an object definition adhering to the RAML spec. For example, to specify that {route} is a integer greater than 5 we would pass in:

pathMatch('/{route}', {
  route: {
    type: 'integer',
    minimum: 6
  }
}); //=> [Function]
Optional parameters

Parameters can be optional according to the RAML spec. To set the parameter to be optional, you must set required: false. With this option set, /{route} will match just /. When the parameter is optional and not matched, the parameter value will be set to undefined.

Matching the path

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.

{
  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.

Immutable Updates

You can merge more parameters into the path after creation using pathMatch.update(params). It'll return a new function, or reuse the current function if there's no functional difference with the new parameters.

License

Apache 2.0

Keywords

FAQs

Package last updated on 17 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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