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

parseurl

Package Overview
Dependencies
Maintainers
6
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.2.0 to 1.3.0

6

HISTORY.md

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

1.3.0 / 2014-08-09
==================
* Add `parseurl.original` for parsing `req.originalUrl` with fallback
* Return `undefined` if `req.url` is `undefined`
1.2.0 / 2014-07-21

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

53

index.js

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

/*!
* parseurl
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/

@@ -18,2 +24,9 @@ /**

/**
* Exports.
*/
module.exports = parseurl
module.exports.original = originalurl
/**
* Parse the `req` url with memoization.

@@ -26,6 +39,12 @@ *

module.exports = function parseUrl(req){
var parsed = req._parsedUrl
function parseurl(req) {
var url = req.url
if (url === undefined) {
// URL is undefined
return undefined
}
var parsed = req._parsedUrl
if (fresh(url, parsed)) {

@@ -44,2 +63,32 @@ // Return cached URL parse

/**
* Parse the `req` original url with fallback and memoization.
*
* @param {ServerRequest} req
* @return {Object}
* @api public
*/
function originalurl(req) {
var url = req.originalUrl
if (typeof url !== 'string') {
// Fallback
return parseurl(req)
}
var parsed = req._parsedOriginalUrl
if (fresh(url, parsed)) {
// Return cached URL parse
return parsed
}
// Parse the URL
parsed = fastparse(url)
parsed._raw = url
return req._parsedOriginalUrl = parsed
};
/**
* Parse the `str` url with fast-path short-cut.

@@ -46,0 +95,0 @@ *

4

package.json
{
"name": "parseurl",
"description": "parse a url with memoization",
"version": "1.2.0",
"version": "1.3.0",
"author": "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)",

@@ -16,3 +16,3 @@ "contributors": [

"istanbul": "0.3.0",
"mocha": "~1.20.0"
"mocha": "~1.21.4"
},

@@ -19,0 +19,0 @@ "scripts": {

@@ -28,2 +28,10 @@ # parseurl

### parseurl.original(req)
Parse the original URL of the given request object and return the result.
This works by trying to parse `req.originalUrl` if it is a string, otherwise
parses `req.url`. The result is the same as `url.parse` in Node.js core.
Calling this function multiple times on the same `req` where `req.originalUrl`
does not change will return a cached parsed object, rather than parsing again.
## Benchmark

@@ -34,3 +42,3 @@

> parseurl@1.2.0 bench nodejs-parseurl
> parseurl@1.3.0 bench nodejs-parseurl
> node benchmark/index.js

@@ -37,0 +45,0 @@

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