Skip to content

Commit

Permalink
add comments explaining what's going on with urlParse
Browse files Browse the repository at this point in the history
  • Loading branch information
KelWill committed Jun 9, 2021
1 parent 0095ddf commit d18ae64
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ var url = require("fast-url-parser");
var querystring = require('querystring');
var isBrowser = (typeof window !== "undefined");

// the node url library is quite slow & is often a code bottleneck
// this wraps fast-url-parser to return url-parser-like results
function urlParse(href) {
var parsed = url.parse(href);
var result = {
Expand All @@ -18,11 +20,12 @@ function urlParse(href) {
search: parsed.search,
pathname: parsed.pathname,
_prependSlash: parsed._prependSlash,

// fields that node url library returns too
port: parsed._port === -1 ? null : parsed._port.toString(),
path: (parsed.pathname || "") + (parsed.search || ""),
href: parsed._href || href,
href: href,
query: parsed.search ? parsed.search.slice(1) : parsed.search,
// fields that "url" also returns
protocol: parsed._protocol + ":"
};

Expand Down

0 comments on commit d18ae64

Please sign in to comment.