Giter Club home page Giter Club logo

parseurl's Introduction

parseurl

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Parse a URL with memoization.

Install

$ npm install parseurl

API

var parseurl = require('parseurl')

parseurl(req)

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.

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

$ npm run-script bench

> [email protected] bench nodejs-parseurl
> node benchmark/index.js

  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  [email protected]
  modules@46
  [email protected]

> node benchmark/fullurl.js

  Parsing URL "http://localhost:8888/foo/bar?user=tj&pet=fluffy"

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x 1,126,841 ops/sec ±1.87% (185 runs sampled)
  nativeurl x    86,169 ops/sec ±0.65% (187 runs sampled)
  parseurl  x    80,604 ops/sec ±1.80% (186 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,942,484 ops/sec ±0.69% (188 runs sampled)
  nativeurl x   719,094 ops/sec ±0.93% (187 runs sampled)
  parseurl  x 2,592,042 ops/sec ±0.82% (189 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  1,917,012 ops/sec ±1.26% (187 runs sampled)
  nativeurl x    720,034 ops/sec ±0.90% (187 runs sampled)
  parseurl  x 10,788,929 ops/sec ±0.59% (187 runs sampled)

> node benchmark/simplepath.js

  Parsing URL "/foo/bar"

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x 5,040,171 ops/sec ±1.47% (187 runs sampled)
  nativeurl x 1,048,939 ops/sec ±1.06% (188 runs sampled)
  parseurl  x 5,071,671 ops/sec ±1.73% (184 runs sampled)

> node benchmark/slash.js

  Parsing URL "/"

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x 4,113,868 ops/sec ±1.22% (187 runs sampled)
  nativeurl x   994,455 ops/sec ±2.00% (188 runs sampled)
  parseurl  x 5,732,749 ops/sec ±0.74% (189 runs sampled)

License

MIT

parseurl's People

Contributors

dougwilson avatar fengmk2 avatar jonathanong avatar nook-scheel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.