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

parseurl

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parseurl - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

6

HISTORY.md

@@ -0,1 +1,7 @@

1.3.2 / 2017-09-09
==================
* perf: reduce overhead for full URLs
* perf: unroll the "fast-path" `RegExp`
1.3.1 / 2016-01-17

@@ -2,0 +8,0 @@ ==================

96

index.js
/*!
* parseurl
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2014 Douglas Christopher Wilson
* Copyright(c) 2014-2017 Douglas Christopher Wilson
* MIT Licensed

@@ -12,2 +12,3 @@ */

* Module dependencies.
* @private
*/

@@ -20,12 +21,6 @@

/**
* Pattern for a simple path case.
* See: https://github.com/joyent/node/pull/7878
* Module exports.
* @public
*/
var simplePathRegExp = /^(\/\/?(?!\/)[^\?#\s]*)(\?[^#\s]*)?$/
/**
* Exports.
*/
module.exports = parseurl

@@ -39,6 +34,6 @@ module.exports.original = originalurl

* @return {Object}
* @api public
* @public
*/
function parseurl(req) {
function parseurl (req) {
var url = req.url

@@ -62,3 +57,3 @@

return req._parsedUrl = parsed
return (req._parsedUrl = parsed)
};

@@ -71,6 +66,6 @@

* @return {Object}
* @api public
* @public
*/
function originalurl(req) {
function originalurl (req) {
var url = req.originalUrl

@@ -94,3 +89,3 @@

return req._parsedOriginalUrl = parsed
return (req._parsedOriginalUrl = parsed)
};

@@ -103,27 +98,48 @@

* @return {Object}
* @api private
* @private
*/
function fastparse(str) {
// Try fast path regexp
// See: https://github.com/joyent/node/pull/7878
var simplePath = typeof str === 'string' && simplePathRegExp.exec(str)
function fastparse (str) {
if (typeof str !== 'string' || str.charCodeAt(0) !== 0x2f /* / */) {
return parse(str)
}
// 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)
var pathname = str
var query = null
var search = null
return url
// This takes the regexp from https://github.com/joyent/node/pull/7878
// Which is /^(\/[^?#\s]*)(\?[^#\s]*)?$/
// And unrolls it into a for loop
for (var i = 1; i < str.length; i++) {
switch (str.charCodeAt(i)) {
case 0x3f: /* ? */
if (search === null) {
pathname = str.substring(0, i)
query = str.substring(i + 1)
search = str.substring(i)
}
break
case 0x09: /* \t */
case 0x0a: /* \n */
case 0x0c: /* \f */
case 0x0d: /* \r */
case 0x20: /* */
case 0x23: /* # */
case 0xa0:
case 0xfeff:
return parse(str)
}
}
return parse(str)
var url = Url !== undefined
? new Url()
: {}
url.path = str
url.href = str
url.pathname = pathname
url.query = query
url.search = search
return url
}

@@ -137,10 +153,10 @@

* @return {boolean}
* @api private
* @private
*/
function fresh(url, parsedUrl) {
return typeof parsedUrl === 'object'
&& parsedUrl !== null
&& (Url === undefined || parsedUrl instanceof Url)
&& parsedUrl._raw === url
function fresh (url, parsedUrl) {
return typeof parsedUrl === 'object' &&
parsedUrl !== null &&
(Url === undefined || parsedUrl instanceof Url) &&
parsedUrl._raw === url
}
{
"name": "parseurl",
"description": "parse a url with memoization",
"version": "1.3.1",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",
"version": "1.3.2",
"contributors": [
"Douglas Christopher Wilson <doug@somethingdoug.com>"
"Douglas Christopher Wilson <doug@somethingdoug.com>",
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
],

@@ -12,7 +12,13 @@ "repository": "pillarjs/parseurl",

"devDependencies": {
"benchmark": "2.0.0",
"beautify-benchmark": "0.2.4",
"benchmark": "2.1.4",
"eslint": "3.19.0",
"eslint-config-standard": "10.2.1",
"eslint-plugin-import": "2.7.0",
"eslint-plugin-node": "5.1.1",
"eslint-plugin-promise": "3.5.0",
"eslint-plugin-standard": "3.0.1",
"fast-url-parser": "1.1.3",
"istanbul": "0.4.2",
"mocha": "~1.21.5"
"istanbul": "0.4.5",
"mocha": "2.5.3"
},

@@ -30,2 +36,3 @@ "files": [

"bench": "node benchmark/index.js",
"lint": "eslint .",
"test": "mocha --check-leaks --bail --reporter spec test/",

@@ -32,0 +39,0 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot test/",

@@ -13,3 +13,7 @@ # parseurl

```bash
This is a [Node.js](https://nodejs.org/en/) module available through the
[npm registry](https://www.npmjs.com/). Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):
```sh
$ npm install parseurl

@@ -44,5 +48,15 @@ ```

> parseurl@1.3.1 bench nodejs-parseurl
> parseurl@1.3.2 bench nodejs-parseurl
> node benchmark/index.js
http_parser@2.7.0
node@4.8.4
v8@4.5.103.47
uv@1.9.1
zlib@1.2.11
ares@1.10.1-DEV
icu@56.1
modules@46
openssl@1.0.2k
> node benchmark/fullurl.js

@@ -52,9 +66,7 @@

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)
fasturl x 1,246,766 ops/sec ±0.74% (188 runs sampled)
nativeurl x 91,536 ops/sec ±0.54% (189 runs sampled)
parseurl x 90,645 ops/sec ±0.38% (189 runs sampled)

@@ -65,9 +77,7 @@ > node benchmark/pathquery.js

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)
fasturl x 2,077,650 ops/sec ±0.69% (186 runs sampled)
nativeurl x 638,669 ops/sec ±0.67% (189 runs sampled)
parseurl x 2,431,842 ops/sec ±0.71% (189 runs sampled)

@@ -78,9 +88,7 @@ > node benchmark/samerequest.js

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)
fasturl x 2,135,391 ops/sec ±0.69% (188 runs sampled)
nativeurl x 672,809 ops/sec ±3.83% (186 runs sampled)
parseurl x 11,604,947 ops/sec ±0.70% (189 runs sampled)

@@ -91,9 +99,7 @@ > node benchmark/simplepath.js

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)
fasturl x 4,961,391 ops/sec ±0.97% (186 runs sampled)
nativeurl x 914,931 ops/sec ±0.83% (186 runs sampled)
parseurl x 7,559,196 ops/sec ±0.66% (188 runs sampled)

@@ -104,9 +110,7 @@ > node benchmark/slash.js

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)
fasturl x 4,053,379 ops/sec ±0.91% (187 runs sampled)
nativeurl x 963,999 ops/sec ±0.58% (189 runs sampled)
parseurl x 11,516,143 ops/sec ±0.58% (188 runs sampled)
```

@@ -121,3 +125,3 @@

[node-version-image]: https://img.shields.io/node/v/parseurl.svg
[node-version-url]: http://nodejs.org/download/
[node-version-url]: https://nodejs.org/en/download/
[travis-image]: https://img.shields.io/travis/pillarjs/parseurl/master.svg

@@ -124,0 +128,0 @@ [travis-url]: https://travis-ci.org/pillarjs/parseurl

Sorry, the diff of this file is not supported yet

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