Socket
Socket
Sign inDemoInstall

trouter

Package Overview
Dependencies
2
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 2.0.1

index.js

5

package.json
{
"name": "trouter",
"version": "1.1.0",
"version": "2.0.1",
"description": "🐟 A fast, small-but-mighty, familiar ~fish~ router",
"repository": "lukeed/trouter",
"main": "lib/index.js",
"license": "MIT",
"files": [
"lib"
"index.js"
],

@@ -11,0 +10,0 @@ "author": {

57

readme.md

@@ -34,6 +34,8 @@ # trouter [![Build Status](https://travis-ci.org/lukeed/trouter.svg?branch=master)](https://travis-ci.org/lukeed/trouter)

//=> obj.params ~> { id:123 }
//=> obj.handler ~> Function
//=> obj.handlers ~> Array<Function>
// Execute the handler, pass value
obj.handler( obj.params.id );
// Execute the handlers, passing value
obj.handlers.forEach(fn => {
fn(obj.params.id);
});
//=> ~> Getting user with ID: 123

@@ -52,6 +54,6 @@

### trouter.add(method, pattern, handler)
### trouter.add(method, pattern, ...handlers)
Returns: `self`
Stores a `method` + `pattern` pairing internally, along with its handler.
Stores a `method` + `pattern` pairing internally, along with its handler(s).

@@ -61,4 +63,8 @@ #### method

Any valid HTTP method name.
Any lowercased, [valid HTTP/1.1 verb](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods#Specifications) &mdash; choose from one of the following:
```
GET HEAD PATCH OPTIONS CONNECT DELETE TRACE POST PUT
```
#### pattern

@@ -77,13 +83,15 @@ Type: `String`

#### handler
Type: `Function`
#### handlers
Type: `Array|Function`
The function that should be tied to this `pattern`.
The function(s) that should be tied to this `pattern`.
> **Important:** Trouter does not care what your function signature looks like!<br> You are not bound to the `(req, res)` standard.
Because this is a [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters), whatever you pass will _always_ be cast to an Array.
### trouter.all(pattern, handler)
> **Important:** Trouter does not care what your function signature looks like!<br> You are not bound to the `(req, res)` standard, or even passing a `Function` at all!
### trouter.all(pattern, ...handlers)
Returns: `self`
This is an alias for [`trouter.add('*', pattern, handler)`](#trouteraddmethod-pattern-handler), matching **all** HTTP methods.
This is an alias for [`trouter.add('*', pattern, ...handlers)`](#trouteraddmethod-pattern-handlers), matching **all** HTTP methods.

@@ -97,15 +105,19 @@ > **Important:** If the `pattern` used within `all()` exists for a specific `method` as well, then **only** the method-specific entry will be returned!

router.find('GET', '/hello').handler();
let { handlers } = router.find('GET', '/hello');
handlers[0]();
//=> 'FROM GET'
router.find('POST', '/hello').handler();
router.find('POST', '/hello').handlers[0]();
//=> 'FROM POST'
router.find('DELETE', '/hello').handler();
router.find('DELETE', '/hello').handlers[0]();
//=> 'FROM ALL'
router.find('PUT', '/hello').handler();
router.find('PUT', '/hello').handlers[0]();
//=> 'FROM ALL'
```
### trouter.METHOD(pattern, handler)
### trouter.METHOD(pattern, ...handlers)
This is an alias for [`trouter.add(METHOD, pattern, handler)`](#trouteraddmethod-pattern-handler), where `METHOD` is **any** lowercased HTTP method name.
This is an alias for [`trouter.add(METHOD, pattern, ...handlers)`](#trouteraddmethod-pattern-handlers), where `METHOD` is any lowercased HTTP verb.

@@ -122,4 +134,3 @@ ```js

app.trace('/foo', noop);
app.purge('/bar', noop);
app.copy('/baz', noop);
app.connect('/bar', noop);
```

@@ -131,4 +142,8 @@

This method will return `false` if no match is found. Otherwise it returns an Object with `params` and `handler` keys.
This method will return `false` if no match is found. Otherwise it returns an Object with `params` and `handlers` keys.
* `params` &mdash; Object whose keys are the named parameters of your route pattern.
* `handlers` &mdash; Array containing the `...handlers` provided to [`.add()`](#trouteraddmethod-pattern-handlers) or [`.METHOD()`](#troutermethodpattern-handlers)
#### method

@@ -135,0 +150,0 @@ Type: `String`

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc