From f6321fc3249d83a0059ef47978ed101d3c75375f Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Wed, 2 Jun 2021 13:59:27 -0400 Subject: feat: import from notion2site repo --- src/normalize-url.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/normalize-url.js (limited to 'src/normalize-url.js') diff --git a/src/normalize-url.js b/src/normalize-url.js new file mode 100644 index 0000000..c22e243 --- /dev/null +++ b/src/normalize-url.js @@ -0,0 +1,58 @@ +/** + * Stripped down version of [normalize-url](https://github.com/sindresorhus/normalize-url) + * by sindresorhus + * + * - always converts http => https + * - removed unused options + * - removed dataURL support + */ +export const normalizeUrl = (urlString) => { + const urlObj = new URL(urlString) + + if (urlObj.protocol === 'http:') { + urlObj.protocol = 'https:' + } + + /* + // Remove auth + // TODO: Cloudflare Workers seems to have a subtle bug where if you set URL.username and + // URL.password at all, it will include the @ authentication prefix in the resulting URL. + // This does not repro in normal web or Node.js contexts. + if (options.stripAuthentication) { + urlObj.username = '' + urlObj.password = '' + } + */ + + // Remove duplicate slashes if not preceded by a protocol + if (urlObj.pathname) { + urlObj.pathname = urlObj.pathname.replace(/(?