@polka/url
Super fast, memoized `req.url` parser
Last updated 3 years ago by lukeed .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @polka/url 
SYNC missed versions from official npm registry.

@polka/url npm

Super fast, memoized req.url parser; not limited to Polka!

Parses the url from a IncomingMessage request. The returned object will always only contain the following keys: search, query, pathname, and raw.

Note: This library does not process protocol, hostname, port, etc.
This is because the incoming req.url value only begins with the path information.

Parsed requests will be mutated with a _parsedUrl key, containing the returned output. This is used for future memoization, avoiding the need to fully parse the same url value multiple times.

Install

$ npm install --save @polka/url

Usage

const parse = require('@polka/url');

let req = {
  url: '/foo/bar?fizz=buzz'
};
let output = parse(req);
//=> {
//=>   pathname: '/foo/bar',
//=>   raw: '/foo/bar?fizz=buzz',
//=>   search: '?fizz=buzz',
//=>   query: {
//=>     fizz: 'buzz'
//=>   },
//=> }

// Attaches result for future memoization
assert.deepEqual(output, req._parsedUrl); //=> true

API

url(req)

Returns: Object or undefined

Important: The req must have a url key, otherwise undefined will be returned.
If no input is provided at all, a TypeError will be thrown.

req

Type: IncomingMessage or { url: string }

The incoming HTTP request (req) or a plain Object with a url key.

Note: In Node.js servers, the req.url begins with a pathname & does not include a hash.

Benchmarks

Check out the bench directory for in-depth benchmark results and comparisons.

Support

Any issues or questions can be sent to the Polka repository.
However, please specify that your inquiry is about @polka/url specifically.

License

MIT © Luke Edwards

Current Tags

  • 0.5.0                                ...           latest (8 years ago)
  • 1.0.0-next.29                                ...           next (2 years ago)

20 Versions

  • 1.0.0-next.29                                ...           2 years ago
  • 1.0.0-next.28                                ...           2 years ago
  • 1.0.0-next.27                                ...           2 years ago
  • 1.0.0-next.25                                ...           3 years ago
  • 1.0.0-next.24                                ...           3 years ago
  • 1.0.0-next.23                                ...           3 years ago
  • 1.0.0-next.21                                ...           5 years ago
  • 1.0.0-next.20                                ...           5 years ago
  • 1.0.0-next.19                                ...           5 years ago
  • 1.0.0-next.18                                ...           5 years ago
  • 1.0.0-next.17                                ...           5 years ago
  • 1.0.0-next.15                                ...           6 years ago
  • 1.0.0-next.12                                ...           6 years ago
  • 1.0.0-next.11                                ...           7 years ago
  • 1.0.0-next.9                                ...           7 years ago
  • 1.0.0-next.7                                ...           7 years ago
  • 1.0.0-next.3                                ...           8 years ago
  • 1.0.0-next.1                                ...           8 years ago
  • 1.0.0-next.0                                ...           8 years ago
  • 0.5.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 2
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE