|
|
1 mēnesi atpakaļ | |
|---|---|---|
| .. | ||
| build.js | 1 mēnesi atpakaļ | |
| build.mjs | 1 mēnesi atpakaļ | |
| index.d.ts | 1 mēnesi atpakaļ | |
| package.json | 1 mēnesi atpakaļ | |
| readme.md | 1 mēnesi atpakaļ | |
Super fast, memoized
req.urlparser; 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 incomingreq.urlvalue 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.
$ npm install --save @polka/url
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
Returns: Object or undefined
Important: The
reqmust have aurlkey, otherwiseundefinedwill be returned.
If no input is provided at all, aTypeErrorwill be thrown.
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.urlbegins with a pathname & does not include ahash.
Check out the bench directory for in-depth benchmark results and comparisons.
Any issues or questions can be sent to the Polka repository.
However, please specify that your inquiry is about @polka/url specifically.
MIT © Luke Edwards