Comparing version 1.1.3 to 1.2.0
@@ -0,1 +1,8 @@ | ||
1.2.0 / 2014-07-21 | ||
================== | ||
* Cache URLs based on original value | ||
* Remove no-longer-needed URL mis-parse work-around | ||
* Simplify the "fast-path" `RegExp` | ||
1.1.3 / 2014-07-08 | ||
@@ -2,0 +9,0 @@ ================== |
59
index.js
@@ -15,4 +15,3 @@ | ||
var simplePathRegExp = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/ | ||
var tryFastRegExp = /^\/[^\\#]*$/ | ||
var simplePathRegExp = /^(\/\/?(?!\/)[^\?#\s]*)(\?[^#\s]*)?$/ | ||
@@ -29,14 +28,13 @@ /** | ||
var parsed = req._parsedUrl | ||
var url = req.url | ||
if (fresh(req, parsed)) { | ||
if (fresh(url, parsed)) { | ||
// Return cached URL parse | ||
return parsed | ||
} | ||
parsed = fastparse(req.url) | ||
// Parse the URL | ||
parsed = fastparse(url) | ||
parsed._raw = url | ||
if (parsed.auth && !parsed.protocol && parsed.href.indexOf('//') !== -1) { | ||
// This parses pathnames, and a strange pathname like //r@e should work | ||
parsed = fastparse(req.url.replace(/@/g, '%40')) | ||
} | ||
return req._parsedUrl = parsed | ||
@@ -54,23 +52,20 @@ }; | ||
function fastparse(str) { | ||
if (typeof str === 'string' && tryFastRegExp.test(str)) { | ||
// Try fast path regexp | ||
// See: https://github.com/joyent/node/pull/7878 | ||
var simplePath = simplePathRegExp.exec(str) | ||
// Try fast path regexp | ||
// See: https://github.com/joyent/node/pull/7878 | ||
var simplePath = typeof str === 'string' && simplePathRegExp.exec(str) | ||
// Construct simple URL | ||
if (simplePath) { | ||
var url = Url !== undefined | ||
? new Url() | ||
: {} | ||
url.path = str | ||
url.href = str | ||
url.pathname = simplePath[1] | ||
// Construct simple URL | ||
if (simplePath) { | ||
var pathname = simplePath[1] | ||
var search = simplePath[2] || null | ||
var url = Url !== undefined | ||
? new Url() | ||
: {} | ||
url.path = str | ||
url.href = str | ||
url.pathname = pathname | ||
url.search = search | ||
url.query = search && search.substr(1) | ||
if (simplePath[2]) { | ||
url.search = simplePath[2]; | ||
url.query = url.search.substr(1); | ||
} | ||
return url | ||
} | ||
return url | ||
} | ||
@@ -82,5 +77,5 @@ | ||
/** | ||
* Determine if parsed is still fresh for req. | ||
* Determine if parsed is still fresh for url. | ||
* | ||
* @param {ServerRequest} req | ||
* @param {string} url | ||
* @param {object} parsedUrl | ||
@@ -91,7 +86,7 @@ * @return {boolean} | ||
function fresh(req, parsedUrl) { | ||
function fresh(url, parsedUrl) { | ||
return typeof parsedUrl === 'object' | ||
&& parsedUrl !== null | ||
&& (Url === undefined || parsedUrl instanceof Url) | ||
&& parsedUrl.href === req.url | ||
&& parsedUrl._raw === url | ||
} |
{ | ||
"name": "parseurl", | ||
"description": "parse a url with memoization", | ||
"version": "1.1.3", | ||
"author": { | ||
"name": "Jonathan Ong", | ||
"email": "me@jongleberry.com", | ||
"url": "http://jongleberry.com", | ||
"twitter": "https://twitter.com/jongleberry" | ||
"version": "1.2.0", | ||
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)", | ||
"contributors": [ | ||
"Douglas Christopher Wilson <doug@somethingdoug.com>" | ||
], | ||
"repository": "expressjs/parseurl", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"benchmark": "1.0.0", | ||
"beautify-benchmark": "0.2.4", | ||
"fast-url-parser": "~1.0.0", | ||
"istanbul": "0.3.0", | ||
"mocha": "~1.20.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/expressjs/parseurl.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/expressjs/parseurl/issues", | ||
"email": "me@jongleberry.com" | ||
}, | ||
"license": "MIT" | ||
"scripts": { | ||
"bench": "node benchmark/index.js", | ||
"test": "mocha --check-leaks --bail --reporter spec test/", | ||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot test/", | ||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec test/" | ||
} | ||
} |
107
README.md
# parseurl | ||
[![NPM version](https://badge.fury.io/js/parseurl.svg)](http://badge.fury.io/js/parseurl) | ||
[![Build Status](https://travis-ci.org/expressjs/parseurl.svg?branch=master)](https://travis-ci.org/expressjs/parseurl) | ||
[![Coverage Status](https://img.shields.io/coveralls/expressjs/parseurl.svg?branch=master)](https://coveralls.io/r/expressjs/parseurl) | ||
Parse a URL with memoization. | ||
## Install | ||
```bash | ||
$ npm install parseurl | ||
``` | ||
## API | ||
### var parsedUrl = parseurl(req) | ||
```js | ||
var parseurl = require('parseurl') | ||
``` | ||
`parsedUrl` is basically a `url.parse()` object. | ||
### parseurl(req) | ||
## LICENSE | ||
Parse the URL of the given request object (looks at the `req.url` property) | ||
and return the result. The result is the same as `url.parse` in Node.js core. | ||
Calling this function multiple times on the same `req` where `req.url` does | ||
not change will return a cached parsed object, rather than parsing again. | ||
(The MIT License) | ||
## Benchmark | ||
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com> | ||
```bash | ||
$ npm run-script bench | ||
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: | ||
> parseurl@1.2.0 bench nodejs-parseurl | ||
> node benchmark/index.js | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
> node benchmark/fullurl.js | ||
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. | ||
Parsing URL "http://localhost:8888/foo/bar?user=tj&pet=fluffy" | ||
1 test completed. | ||
2 tests completed. | ||
3 tests completed. | ||
fasturl x 1,290,780 ops/sec ±0.46% (195 runs sampled) | ||
nativeurl x 56,401 ops/sec ±0.22% (196 runs sampled) | ||
parseurl x 55,231 ops/sec ±0.22% (194 runs sampled) | ||
> node benchmark/pathquery.js | ||
Parsing URL "/foo/bar?user=tj&pet=fluffy" | ||
1 test completed. | ||
2 tests completed. | ||
3 tests completed. | ||
fasturl x 1,986,668 ops/sec ±0.27% (190 runs sampled) | ||
nativeurl x 98,740 ops/sec ±0.21% (195 runs sampled) | ||
parseurl x 2,628,171 ops/sec ±0.36% (195 runs sampled) | ||
> node benchmark/samerequest.js | ||
Parsing URL "/foo/bar?user=tj&pet=fluffy" on same request object | ||
1 test completed. | ||
2 tests completed. | ||
3 tests completed. | ||
fasturl x 2,184,468 ops/sec ±0.40% (194 runs sampled) | ||
nativeurl x 99,437 ops/sec ±0.71% (194 runs sampled) | ||
parseurl x 10,498,005 ops/sec ±0.61% (186 runs sampled) | ||
> node benchmark/simplepath.js | ||
Parsing URL "/foo/bar" | ||
1 test completed. | ||
2 tests completed. | ||
3 tests completed. | ||
fasturl x 4,535,825 ops/sec ±0.27% (191 runs sampled) | ||
nativeurl x 98,769 ops/sec ±0.54% (191 runs sampled) | ||
parseurl x 4,164,865 ops/sec ±0.34% (192 runs sampled) | ||
> node benchmark/slash.js | ||
Parsing URL "/" | ||
1 test completed. | ||
2 tests completed. | ||
3 tests completed. | ||
fasturl x 4,908,405 ops/sec ±0.42% (191 runs sampled) | ||
nativeurl x 100,945 ops/sec ±0.59% (188 runs sampled) | ||
parseurl x 4,333,208 ops/sec ±0.27% (194 runs sampled) | ||
``` | ||
## License | ||
[MIT](LICENSE) |
Sorry, the diff of this file is not supported yet
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
6747
6
100
5
71
2
1