Socket
Socket
Sign inDemoInstall

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 1.2.1 to 1.3.0

test/regex.test.js

36

index.js

@@ -8,2 +8,3 @@ 'use strict'

matchAll: 2,
regex: 3

@@ -55,3 +56,7 @@ Char codes:

while (i < len && path.charCodeAt(i) !== 47) i++
params.push(path.slice(j, i))
var parameter = path.slice(j, i)
var isRegex = parameter.indexOf('(') > -1
var regex = isRegex ? parameter.slice(parameter.indexOf('('), i) : null
if (isRegex) regex = new RegExp(regex)
params.push(parameter.slice(0, isRegex ? parameter.indexOf('(') : i))

@@ -64,5 +69,5 @@ path = path.slice(0, j) + path.slice(i)

if (i === len) {
return this._insert(method, path.slice(0, i), 1, params, handler, store)
return this._insert(method, path.slice(0, i), regex ? 3 : 1, params, handler, store, regex)
}
this._insert(method, path.slice(0, i), 1, params, null, null)
this._insert(method, path.slice(0, i), regex ? 3 : 1, params, null, null, regex)

@@ -80,3 +85,3 @@ // wildcard route

Router.prototype._insert = function (method, path, kind, params, handler, store) {
Router.prototype._insert = function (method, path, kind, params, handler, store, regex) {
var prefix = ''

@@ -102,3 +107,3 @@ var pathLen = 0

// split the node in the radix tree and add it to the parent
node = new Node(prefix.slice(len), currentNode.children, currentNode.kind, currentNode.map)
node = new Node(prefix.slice(len), currentNode.children, currentNode.kind, currentNode.map, currentNode.regex)

@@ -112,2 +117,3 @@ // reset the parent

currentNode.kind = 0
currentNode.regex = null

@@ -121,3 +127,3 @@ if (len === pathLen) {

// create a child node and add an handler to it
node = new Node(path.slice(len), [], kind)
node = new Node(path.slice(len), [], kind, null, regex)
node.setHandler(method, handler, params, store)

@@ -136,3 +142,3 @@ // add the child to the parent

// create a new child node
node = new Node(path, [], kind)
node = new Node(path, [], kind, null, regex)
node.setHandler(method, handler, params, store)

@@ -234,2 +240,18 @@ // add the child to the parent

// parametric(regex) route
node = currentNode.findByKind(3)
if (node) {
currentNode = node
i = 0
while (i < pathLen && path.charCodeAt(i) !== 47) i++
decoded = fastDecode(path.slice(0, i))
if (errored) {
return null
}
if (!node.regex.test(decoded)) return
params[pindex++] = decoded
path = path.slice(i)
continue
}
// route not found

@@ -236,0 +258,0 @@ if (len !== prefixLen) return null

4

node.js

@@ -8,5 +8,6 @@ 'use strict'

matchAll: 2,
regex: 3
*/
function Node (prefix, children, kind, map) {
function Node (prefix, children, kind, map, regex) {
this.prefix = prefix || '/'

@@ -18,2 +19,3 @@ this.label = this.prefix[0]

this.map = map || null
this.regex = regex || null
}

@@ -20,0 +22,0 @@

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

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

@@ -71,2 +71,8 @@ # find-my-way

Regex routes are supported as well, but pay attention, regex are very expensive!
```js
// parametric with regex
router.on('GET', '/test/:file(^\\d+).png', () => {}))
```
<a name="shorthand-methods"></a>

@@ -73,0 +79,0 @@ ##### Shorthand methods

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