routington
Advanced tools
Comparing version 0.1.3 to 1.0.0
@@ -0,1 +1,4 @@ | ||
var flatten = require('flatten') | ||
var Routington = require('./routington') | ||
@@ -11,4 +14,3 @@ | ||
Routington.prototype.define = function (route) { | ||
if (typeof route !== 'string') | ||
throw new TypeError('Only strings can be defined.') | ||
if (typeof route !== 'string') throw new TypeError('Only strings can be defined.') | ||
@@ -54,15 +56,1 @@ try { | ||
} | ||
function flatten(arr, tmp) { | ||
tmp = tmp || [] | ||
if (Array.isArray(arr)) { | ||
arr.forEach(function (x) { | ||
flatten(x, tmp) | ||
}) | ||
} else { | ||
tmp.push(arr) | ||
} | ||
return tmp | ||
} |
@@ -30,3 +30,3 @@ var Routington = require('./routington') | ||
frag = decode(frags.shift()) | ||
if (frag === -1) malformed() | ||
if (frag === -1) malformed(url) | ||
length = frags.length | ||
@@ -36,4 +36,3 @@ | ||
if (node = root.child[frag]) { | ||
if (name = node.name) | ||
match.param[name] = frag | ||
if (name = node.name) match.param[name] = frag | ||
@@ -55,4 +54,3 @@ if (!length) { | ||
if (!(regex = node.regex) || regex.test(frag)) { | ||
if (name = node.name) | ||
match.param[name] = frag | ||
if (name = node.name) match.param[name] = frag | ||
@@ -82,6 +80,6 @@ if (!length) { | ||
function malformed() { | ||
var err = new Error('malformed url') | ||
function malformed(url) { | ||
var err = new Error('malformed url: ' + url) | ||
err.status = 400 | ||
throw err | ||
} | ||
} |
@@ -5,5 +5,3 @@ var Routington = require('./routington') | ||
var options = Parse(string) | ||
if (!options) | ||
throw new Error('Invalid parsed string: ' + string) | ||
if (!options) throw new Error('Invalid parsed string: ' + string) | ||
return options | ||
@@ -40,4 +38,3 @@ } | ||
// Return if the string is now empty | ||
if (!string) | ||
return options | ||
if (!string) return options | ||
@@ -65,2 +62,2 @@ // Assume the capture is a regex if there are | ||
return /^[\w\.\-][\w\.\-\|]+[\w\.\-]$/.test(x) | ||
} | ||
} |
@@ -1,21 +0,4 @@ | ||
var inherits = require('util').inherits | ||
module.exports = Routington | ||
Routington.extend = function () { | ||
function Routington(options) { | ||
if (!(this instanceof Routington)) | ||
return new Routington(options) | ||
this._init(options) | ||
} | ||
inherits(Routington, this) | ||
Object.keys(this).forEach(function (key) { | ||
Routington[key] = this[key] | ||
}, this) | ||
return Routington | ||
} | ||
function Routington(options) { | ||
@@ -55,4 +38,3 @@ if (!(this instanceof Routington)) | ||
// Find by string | ||
if (typeof options.string === 'string') | ||
return this.child[options.string] | ||
if (typeof options.string === 'string') return this.child[options.string] | ||
@@ -72,13 +54,10 @@ var child | ||
Routington.prototype._attach = function (node) { | ||
if (!(node instanceof Routington)) | ||
node = new Routington(node) | ||
if (!(node instanceof Routington)) node = new Routington(node) | ||
node.parent = this | ||
if (node.string == null) | ||
this.children.push(node) | ||
else | ||
this.child[node.string] = node | ||
if (node.string == null) this.children.push(node) | ||
else this.child[node.string] = node | ||
return node | ||
} | ||
} |
{ | ||
"name": "routington", | ||
"description": "Trie-based URL Routing", | ||
"version": "0.1.3", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"flatten": "0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*", | ||
"matcha": "*" | ||
"mocha": "1", | ||
"should": "4", | ||
"matcha": "0", | ||
"istanbul": "0" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
"bench": "matcha benchmark", | ||
"test": "mocha --reporter spec --require should", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should", | ||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --require should" | ||
}, | ||
@@ -19,11 +26,14 @@ "author": { | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jonathanong/routington.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jonathanong/routington/issues", | ||
"email": "me@jongleberry.com" | ||
}, | ||
"license": "MIT" | ||
"repository": "jonathanong/routington", | ||
"license": "MIT", | ||
"main": "lib", | ||
"files": [ | ||
"lib" | ||
], | ||
"keywords": [ | ||
"router", | ||
"routes", | ||
"routing", | ||
"trie" | ||
] | ||
} |
@@ -1,3 +0,8 @@ | ||
## Routington [![Build Status](https://travis-ci.org/jonathanong/routington.png)](https://travis-ci.org/jonathanong/routington) | ||
## Routington | ||
[![NPM version][npm-image]][npm-url] | ||
[![build status][travis-image]][travis-url] | ||
[![Test coverage][coveralls-image]][coveralls-url] | ||
[![Gittip][gittip-image]][gittip-url] | ||
Routington is a [trie](http://en.wikipedia.org/wiki/Trie)-based URL router. | ||
@@ -16,2 +21,3 @@ Its goal is only to define and match URLs. | ||
- [koa-trie-router](https://github.com/koajs/trie-router) - for [koa](https://github.com/koajs) | ||
- [wayfarer](https://github.com/yoshuawuyts/wayfarer) | ||
@@ -161,24 +167,9 @@ ### API | ||
### License | ||
The MIT License (MIT) | ||
Copyright (c) 2013 Jonathan Ong me@jongleberry.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
[npm-image]: https://img.shields.io/npm/v/routington.svg?style=flat | ||
[npm-url]: https://npmjs.org/package/routington | ||
[travis-image]: https://img.shields.io/travis/jonathanong/routington.svg?style=flat | ||
[travis-url]: https://travis-ci.org/jonathanong/routington | ||
[coveralls-image]: https://img.shields.io/coveralls/jonathanong/routington.svg?style=flat | ||
[coveralls-url]: https://coveralls.io/r/jonathanong/routington?branch=master | ||
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat | ||
[gittip-url]: https://www.gittip.com/jonathanong/ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
11451
1
4
7
205
2
174
1
+ Addedflatten@0
+ Addedflatten@0.0.1(transitive)