Initial commit
[yaffs-website] / node_modules / parseurl / README.md
1 # parseurl
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
8
9 Parse a URL with memoization.
10
11 ## Install
12
13 ```bash
14 $ npm install parseurl
15 ```
16
17 ## API
18
19 ```js
20 var parseurl = require('parseurl')
21 ```
22
23 ### parseurl(req)
24
25 Parse the URL of the given request object (looks at the `req.url` property)
26 and return the result. The result is the same as `url.parse` in Node.js core.
27 Calling this function multiple times on the same `req` where `req.url` does
28 not change will return a cached parsed object, rather than parsing again.
29
30 ### parseurl.original(req)
31
32 Parse the original URL of the given request object and return the result.
33 This works by trying to parse `req.originalUrl` if it is a string, otherwise
34 parses `req.url`. The result is the same as `url.parse` in Node.js core.
35 Calling this function multiple times on the same `req` where `req.originalUrl`
36 does not change will return a cached parsed object, rather than parsing again.
37
38 ## Benchmark
39
40 ```bash
41 $ npm run-script bench
42
43 > parseurl@1.3.1 bench nodejs-parseurl
44 > node benchmark/index.js
45
46 > node benchmark/fullurl.js
47
48   Parsing URL "http://localhost:8888/foo/bar?user=tj&pet=fluffy"
49
50   1 test completed.
51   2 tests completed.
52   3 tests completed.
53
54   fasturl   x 1,290,780 ops/sec ±0.46% (195 runs sampled)
55   nativeurl x    56,401 ops/sec ±0.22% (196 runs sampled)
56   parseurl  x    55,231 ops/sec ±0.22% (194 runs sampled)
57
58 > node benchmark/pathquery.js
59
60   Parsing URL "/foo/bar?user=tj&pet=fluffy"
61
62   1 test completed.
63   2 tests completed.
64   3 tests completed.
65
66   fasturl   x 1,986,668 ops/sec ±0.27% (190 runs sampled)
67   nativeurl x    98,740 ops/sec ±0.21% (195 runs sampled)
68   parseurl  x 2,628,171 ops/sec ±0.36% (195 runs sampled)
69
70 > node benchmark/samerequest.js
71
72   Parsing URL "/foo/bar?user=tj&pet=fluffy" on same request object
73
74   1 test completed.
75   2 tests completed.
76   3 tests completed.
77
78   fasturl   x  2,184,468 ops/sec ±0.40% (194 runs sampled)
79   nativeurl x     99,437 ops/sec ±0.71% (194 runs sampled)
80   parseurl  x 10,498,005 ops/sec ±0.61% (186 runs sampled)
81
82 > node benchmark/simplepath.js
83
84   Parsing URL "/foo/bar"
85
86   1 test completed.
87   2 tests completed.
88   3 tests completed.
89
90   fasturl   x 4,535,825 ops/sec ±0.27% (191 runs sampled)
91   nativeurl x    98,769 ops/sec ±0.54% (191 runs sampled)
92   parseurl  x 4,164,865 ops/sec ±0.34% (192 runs sampled)
93
94 > node benchmark/slash.js
95
96   Parsing URL "/"
97
98   1 test completed.
99   2 tests completed.
100   3 tests completed.
101
102   fasturl   x 4,908,405 ops/sec ±0.42% (191 runs sampled)
103   nativeurl x   100,945 ops/sec ±0.59% (188 runs sampled)
104   parseurl  x 4,333,208 ops/sec ±0.27% (194 runs sampled)
105 ```
106
107 ## License
108
109   [MIT](LICENSE)
110
111 [npm-image]: https://img.shields.io/npm/v/parseurl.svg
112 [npm-url]: https://npmjs.org/package/parseurl
113 [node-version-image]: https://img.shields.io/node/v/parseurl.svg
114 [node-version-url]: http://nodejs.org/download/
115 [travis-image]: https://img.shields.io/travis/pillarjs/parseurl/master.svg
116 [travis-url]: https://travis-ci.org/pillarjs/parseurl
117 [coveralls-image]: https://img.shields.io/coveralls/pillarjs/parseurl/master.svg
118 [coveralls-url]: https://coveralls.io/r/pillarjs/parseurl?branch=master
119 [downloads-image]: https://img.shields.io/npm/dm/parseurl.svg
120 [downloads-url]: https://npmjs.org/package/parseurl