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

wayfarer

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wayfarer - npm Package Compare versions

Comparing version 4.3.1 to 5.0.0

17

index.js

@@ -14,7 +14,10 @@ const routington = require('routington')

dft = sanitizeUri(dft) || ''
const router = routington()
const mounts = routington()
const routes = routington()
const subrouters = routington()
emit._subrouters = subrouters
emit._default = defaultFn
emit._routes = routes
emit[sym] = true
emit.default = defaultFn
emit.emit = emit

@@ -31,3 +34,3 @@ emit.on = on

path = sanitizeUri(path) || ''
const node = cb[sym] ? mounts.define(path)[0] : router.define(path)[0]
const node = cb[sym] ? subrouters.define(path)[0] : routes.define(path)[0]
if (Array.isArray(node.cb)) node.cb.push(cb)

@@ -47,4 +50,4 @@ else node.cb = [cb]

const localDft = router.match(dft) || parentDefault
const match = sub ? sub.matched : router.match(path) || localDft
const localDft = routes.match(dft) || parentDefault
const match = sub ? sub.matched : routes.match(path) || localDft
assert.ok(match, 'path ' + path + ' did not match')

@@ -83,3 +86,3 @@ params = xtend(params, match.param)

var nw = arr.join('/')
var imatch = mounts.match(nw)
var imatch = subrouters.match(nw)
if (imatch) {

@@ -86,0 +89,0 @@ match = imatch

{
"name": "wayfarer",
"version": "4.3.1",
"version": "5.0.0",
"description": "Composable trie based router",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -59,19 +59,29 @@ # wayfarer

### router.default(params)
Trigger the default route. Useful to trigger errors externally.
### router(route)
Match a route and execute the corresponding callback. Alias: `router.emit()`.
## Why?
## Internals
__Warning__: these methods are considered internal and should only be used when
extending wayfarer.
- `router._default(params)`: Trigger the default route. Useful to propagate
error states.
- `routes = router._routes`: Expose the mounted routes.
- `subrouters = router._subrouters`: Expose the mounted subrouters.
## FAQ
### Why did you build this?
Routers like [react-router](https://github.com/rackt/react-router) are
complicated solutions for a simple problem. All I want is a
complicated solutions for a simple problem. In reality all that's needed is a
[methodless](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html) router
that's as simple as `EventEmitter` and allows composition by mounting
subrouters as handlers.
that can define + match paths and can mount other routers to delegate requests.
### Why isn't my route matching?
Wayfarer only compares strings. Before you pass in an url you probably want to
strip it of querystrings and hashes using the
[pathname-match](https://github.com/yoshuawuyts/pathname-match) module.
## See Also
- [hash-match](https://github.com/sethvincent/hash-match) - easy `window.location.hash` matching
- [pathname-match](https://github.com/yoshuawuyts/pathname-match) - strip querystrings and hashes from a url
- [methodist](https://github.com/yoshuawuyts/methodist) - HTTP method matching
- [wayfarer-to-server](https://github.com/yoshuawuyts/wayfarer-to-server) - Wrap wayfarer to provide HTTP method matching and `req, res` delegation

@@ -78,0 +88,0 @@ ## License

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