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

byway

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

byway

yet another router; match a string by :sinatra/:express style named-params, or regex, and get something back.

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

byway Build Status

Match a string by sinatra/express style named-params, or regexes, and get something back.

install

npm i --save byway

usage

Starting with:

var Byway = require('byway'),
    routes = require('someroutes'), //json, or js, that exports an array of objects
    byway = new Byway(routes);

Here the value of routes is an array of objects, with the following properties:

  • pattern - required string to convert to a regular expression, or a literal RegExp
  • isregex - optional true if pattern is a string you want to convert to a regex
  • param - optional anything; this is returned as part of a match, if truthy.

Once you've created a byway object, determine if a string matches any of the routes.patterns like:

var match = byway.of(some_string);

If some_string wasn't matched by any routes.patterns match is false. Otherwise, the return value is an object with the following properties:

  • input - the original string that was passed to of()
  • param - the value of the param property defined in the corresponding route
  • parts - an object with key/value pairs corresponding to the matched named patterns, or an array containing the text captured by your regex subpatterns, if any.

See tests/examples.js.

named patterns

foo/bar/:somedir/booyah/:afile.:extension

n.b. unachored.

named spot patterns

named spot patterns do a non-greedy match for any characters within the p

foo/•subpath/:afile.:extension

regex patterns

can either be strings (be carefull to escape backslashes for the string and regex) or literal javascript RegExp objects.

test

npm test

Tests use James Halliday's tape test harness. If you have Krishnan Anantheswaran's istanbul, or Jarrod Overson's plato installed globally you can do these things too, respectively:

npm run-script cover
npm run-script plato

license

MIT licensed by permission from my employer. See LICENSE.txt.

Keywords

FAQs

Package last updated on 12 Feb 2013

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