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

find-my-way

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-my-way - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

4

index.js

@@ -198,3 +198,3 @@ 'use strict'

while (i < pathLen && path[i] !== '/') i++
params[pindex++] = path.slice(0, i)
params[pindex++] = decodeURIComponent(path.slice(0, i))
path = path.slice(i)

@@ -207,3 +207,3 @@ continue

if (node) {
params[pindex] = path
params[pindex] = decodeURIComponent(path)
currentNode = node

@@ -210,0 +210,0 @@ path = ''

{
"name": "find-my-way",
"version": "0.2.0",
"version": "0.2.1",
"description": "Crazy fast http radix based router",

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

@@ -51,3 +51,3 @@ # find-my-way

#### on(method, path, handler, [store])
Register a new route, `store` is an object that you can access later inside the handler function.
Register a new route, `store` is an object that you can access later inside the handler function.
```js

@@ -60,6 +60,13 @@ router.on('GET', '/', (req, res, params) => {

router.on('GET', '/store', (req, res, params, store) => {
// the store can be updated
assert.equal(store, { hello: 'world' })
}, { hello: 'world' })
```
If you want to register a **parametric** path, just use the *colon* before the parameter name, if you need a **wildcard** use the *star*.
```js
// parametric
router.on('GET', '/example/:name', () => {}))
// wildcard
router.on('GET', '/other-example/*', () => {}))
```
<a name="lookup"></a>

@@ -69,3 +76,3 @@ #### lookup(request, response)

If a route is found it will automatically called the handler, otherwise the default route will be called.
The url is sanitized internally.
The url is sanitized internally, all the parameters and wildcards are decoded automatically.
```js

@@ -78,3 +85,3 @@ router.lookup(req, res)

Return (if present) the route registered in *method:path*.
The path must be sanitized.
The path must be sanitized, all the parameters and wildcards are decoded automatically.
```js

@@ -81,0 +88,0 @@ router.find('GET', '/example')

@@ -227,1 +227,21 @@ 'use strict'

})
test('should decode the uri - parametric', t => {
t.plan(1)
const findMyWay = FindMyWay()
const fn = () => {}
findMyWay.on('GET', '/test/:id', fn)
t.deepEqual(findMyWay.find('GET', '/test/he%2Fllo'), { handler: fn, params: { id: 'he/llo' }, store: null })
})
test('should decode the uri - wildcard', t => {
t.plan(1)
const findMyWay = FindMyWay()
const fn = () => {}
findMyWay.on('GET', '/test/*', fn)
t.deepEqual(findMyWay.find('GET', '/test/he%2Fllo'), { handler: fn, params: { '*': 'he/llo' }, store: null })
})

@@ -31,1 +31,20 @@ 'use strict'

})
test('update the store', t => {
t.plan(2)
const findMyWay = FindMyWay()
var bool = false
findMyWay.on('GET', '/test', (req, res, params, store) => {
if (!bool) {
t.is(store.hello, 'world')
store.hello = 'hello'
bool = true
findMyWay.lookup({ method: 'GET', url: '/test' }, null)
} else {
t.is(store.hello, 'hello')
}
}, { hello: 'world' })
findMyWay.lookup({ method: 'GET', url: '/test' }, null)
})
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