Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
@polka/url
Advanced tools
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 incomingreq.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.
$ 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
// Example with `toDecode` param
req = {
url: '/f%C3%B8%C3%B8%C3%9F%E2%88%82r?phone=%2b8675309'
};
parse(req, true);
//=> {
//=> pathname: '/føøß∂r',
//=> raw: '/f%C3%B8%C3%B8%C3%9F%E2%88%82r?phone=%2b8675309',
//=> search: '?phone=%2b8675309',
//=> query: {
//=> phone: '+8675309'
//=> }
//=> }
// Attaches awareness key
assert(req._decoded); //=> '/føøß∂r'
Returns: Object
or undefined
Important: The
req
must have aurl
key, otherwiseundefined
will be returned.
If no input is provided at all, aTypeError
will 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.url
begins with a pathname & does not include ahash
.
Type: Boolean
Default: false
If enabled, the pathname
will be fully decoded, via decodeURIComponent
.
Important: Please note the following behaviors:
raw
is never decoded; this key reflects your original valuepathname
is decoded only whentoDecode
is enabledsearch
is never decoded; this key reflects your original querystring valuequery
is always decoded; even whentoDecode
is disabled
Additionally, the req
is mutated with req._decoded
so as to prevent repetitive decoding.
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
FAQs
Super fast, memoized `req.url` parser
The npm package @polka/url receives a total of 3,573,013 weekly downloads. As such, @polka/url popularity was classified as popular.
We found that @polka/url demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.