From d18ae642b5218ca9b028be73361429aea49f0153 Mon Sep 17 00:00:00 2001 From: will Date: Wed, 9 Jun 2021 19:52:14 +0000 Subject: [PATCH] add comments explaining what's going on with urlParse --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6874beb..ad81583 100644 --- a/index.js +++ b/index.js @@ -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 = { @@ -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 + ":" };