Code Monkey home page Code Monkey logo

parseurl's Introduction

parseurl

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

Parse a URL with memoization.

用缓存解析 URL

Install(安装)

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

这是一个在 npm 网站可用的 Node.js 模块,通过键入 npm 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.

解析 request 对象的 URL(查看 req.url 属性),并返回结果

The result is the same as url.parse in Node.js core.

这个结果和 node.js 中的 url.parse 类似

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.

req.url 没有改变时,在同一个 req 上调用这个函数多次,会返回一个已经解析过的缓存的对象,而不是再一次进行解析

parseurl.original(req)

Parse the original URL of the given request object and return the result.

解析 request 对象的原始 URL 并返回结果

This works by trying to parse req.originalUrl if it is a string, otherwise parses req.url.

如果他是个字符串就尝试解析 req.originalUrl,否则解析 req.url

The result is the same as url.parse in Node.js core.

这个结果跟 node.js 中的 url.parse 类似

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.

req.originalUrl 没有改变时,在同一个 req 上调用这个函数多次,会返回一个已经解析过的缓存的对象,而不是再一次进行解析

Benchmark(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"

  3 tests completed.

  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)

> node benchmark/pathquery.js

  Parsing URL "/foo/bar?user=tj&pet=fluffy"

  3 tests completed.

  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)

> node benchmark/samerequest.js

  Parsing URL "/foo/bar?user=tj&pet=fluffy" on same request object

  3 tests completed.

  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)

> node benchmark/simplepath.js

  Parsing URL "/foo/bar"

  3 tests completed.

  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)

> node benchmark/slash.js

  Parsing URL "/"

  3 tests completed.

  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)

License

MIT

parseurl's People

Contributors

wangding avatar

Watchers

James Cloos avatar  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.