@jridgewell/resolve-uri
Advanced tools
+24
-24
@@ -1,3 +0,1 @@ | ||
| /* istanbul ignore next */ | ||
| const Url = (typeof URL !== 'undefined' ? URL : require('url').URL); | ||
| // Matches "..", which must be preceeded by "/" or the start of the string, and | ||
@@ -7,8 +5,12 @@ // must be followed by a "/". We do not eat the following "/", so that the next | ||
| const parentRegex = /(^|\/)\.\.(?=\/|$)/g; | ||
| function isAbsoluteUrl(url) { | ||
| // Matches the scheme of a URL, which is a strong indicator it is an valid | ||
| // absolute URL. | ||
| const schemeRegex = /^\s*[a-z][a-z0-9+\-.]*:/i; | ||
| function absoluteUrl(url) { | ||
| try { | ||
| return !!new Url(url); | ||
| return schemeRegex.test(url) ? new URL(url) : null; | ||
| } | ||
| catch (e) { | ||
| return false; | ||
| catch (_a) { | ||
| /* istanbul ignore next */ | ||
| return null; | ||
| } | ||
@@ -21,4 +23,4 @@ } | ||
| let uniq = String(Math.random()).slice(2); | ||
| while (str.indexOf(uniq) > -1) { | ||
| /* istanbul ignore next */ | ||
| let index = 0; | ||
| while ((index = str.indexOf(uniq, index)) > -1) { | ||
| uniq += uniq; | ||
@@ -43,3 +45,3 @@ } | ||
| function normalizeProtocolRelative(input, absoluteBase) { | ||
| const { href, protocol } = new Url(input, absoluteBase); | ||
| const { href, protocol } = new URL(input, absoluteBase); | ||
| return href.slice(protocol.length); | ||
@@ -52,3 +54,3 @@ } | ||
| function normalizeSimplePath(input) { | ||
| const { href } = new Url(input, 'https://foo.com/'); | ||
| const { href } = new URL(input, 'https://foo.com/'); | ||
| return href.slice('https://foo.com/'.length); | ||
@@ -82,6 +84,2 @@ } | ||
| const uniqDirectory = `z${uniqInStr(input)}/`; | ||
| // uniqDirectory is just a "z", followed by numbers, followed by a "/". So | ||
| // generating a runtime regex from it is safe. We'll use this search regex to | ||
| // strip out our uniq directory names and insert any needed ".."s. | ||
| const search = new RegExp(`^(?:${uniqDirectory})*`); | ||
| // Now we can resolve the total path. If there are excess ".."s, they will | ||
@@ -93,8 +91,9 @@ // eliminate one or more of the unique directories we prefix with. | ||
| // 2 were eliminated, we need to insert 2 ".."s. If all 3 were eliminated, | ||
| // then we need 3, etc. This replace is guranteed to match (it may match 0 or | ||
| // more times), and we can count the total match to see how many were eliminated. | ||
| return relative.replace(search, (all) => { | ||
| const leftover = all.length / uniqDirectory.length; | ||
| return '../'.repeat(total - leftover); | ||
| }); | ||
| // then we need 3, etc. | ||
| let index = 0; | ||
| while (relative.startsWith(uniqDirectory, index)) { | ||
| total--; | ||
| index += uniqDirectory.length; | ||
| } | ||
| return '../'.repeat(total) + relative.slice(index); | ||
| } | ||
@@ -108,8 +107,9 @@ /** | ||
| // Absolute URLs are very easy to resolve right. | ||
| if (isAbsoluteUrl(input)) | ||
| return new Url(input).href; | ||
| let url; | ||
| if ((url = absoluteUrl(input))) | ||
| return url.href; | ||
| if (base) { | ||
| // Absolute URLs are easy... | ||
| if (isAbsoluteUrl(base)) | ||
| return new Url(input, base).href; | ||
| if (absoluteUrl(base)) | ||
| return new URL(input, base).href; | ||
| // If base is protocol relative, we'll resolve with it but keep the result | ||
@@ -116,0 +116,0 @@ // protocol relative. |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"resolve-uri.mjs","sources":["../src/resolve-uri.ts"],"sourcesContent":["type WhatWgUrl = import('url').URL;\ninterface Url extends WhatWgUrl {\n new (input: string, base?: string): WhatWgUrl;\n}\ndeclare var URL: unknown;\n\n/* istanbul ignore next */\nconst Url = (typeof URL !== 'undefined' ? URL : require('url').URL) as Url;\n\n// Matches \"..\", which must be preceeded by \"/\" or the start of the string, and\n// must be followed by a \"/\". We do not eat the following \"/\", so that the next\n// iteration can match on it.\nconst parentRegex = /(^|\\/)\\.\\.(?=\\/|$)/g;\n\nfunction isAbsoluteUrl(url: string): boolean {\n try {\n return !!new Url(url);\n } catch (e) {\n return false;\n }\n}\n\n/**\n * Creates a directory name that is guaranteed to not be in `str`.\n */\nfunction uniqInStr(str: string): string {\n let uniq = String(Math.random()).slice(2);\n while (str.indexOf(uniq) > -1) {\n /* istanbul ignore next */\n uniq += uniq;\n }\n return uniq;\n}\n\n/**\n * Removes the filename from the path (everything trailing the last \"/\"). This\n * is only safe to call on a path, never call with an absolute or protocol\n * relative URL.\n */\nfunction stripPathFilename(path: string): string {\n path = normalizePath(path);\n const index = path.lastIndexOf('/');\n return path.slice(0, index + 1);\n}\n\n/**\n * Normalizes a protocol-relative URL, but keeps it protocol relative by\n * stripping out the protocl before returning it.\n */\nfunction normalizeProtocolRelative(input: string, absoluteBase: string): string {\n const { href, protocol } = new Url(input, absoluteBase);\n return href.slice(protocol.length);\n}\n\n/**\n * Normalizes a simple path (one that has no \"..\"s, or is absolute so \"..\"s can\n * be normalized absolutely).\n */\nfunction normalizeSimplePath(input: string): string {\n const { href } = new Url(input, 'https://foo.com/');\n return href.slice('https://foo.com/'.length);\n}\n\n/**\n * Normalizes a path, ensuring that excess \"..\"s are preserved for relative\n * paths in the output.\n *\n * If the input is absolute, this will return an absolutey normalized path, but\n * it will not have a leading \"/\".\n *\n * If the input has a leading \"..\", the output will have a leading \"..\".\n *\n * If the input has a leading \".\", the output will not have a leading \".\"\n * unless there are too many \"..\"s, in which case there will be a leading \"..\".\n */\nfunction normalizePath(input: string): string {\n // If there are no \"..\"s, we can treat this as if it were an absolute path.\n // The return won't be an absolute path, so it's easy.\n if (!parentRegex.test(input)) return normalizeSimplePath(input);\n\n // We already found one \"..\". Let's see how many there are.\n let total = 1;\n while (parentRegex.test(input)) total++;\n\n // If there are \"..\"s, we need to prefix the the path with the same number of\n // unique directories. This is to ensure that we \"remember\" how many parent\n // directories we are accessing. Eg, \"../../..\" must keep 3, and \"foo/../..\"\n // must keep 1.\n const uniqDirectory = `z${uniqInStr(input)}/`;\n\n // uniqDirectory is just a \"z\", followed by numbers, followed by a \"/\". So\n // generating a runtime regex from it is safe. We'll use this search regex to\n // strip out our uniq directory names and insert any needed \"..\"s.\n const search = new RegExp(`^(?:${uniqDirectory})*`);\n\n // Now we can resolve the total path. If there are excess \"..\"s, they will\n // eliminate one or more of the unique directories we prefix with.\n const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input);\n\n // We can now count the number of unique directories that were eliminated. If\n // there were 3, and 1 was eliminated, we know we only need to add 1 \"..\". If\n // 2 were eliminated, we need to insert 2 \"..\"s. If all 3 were eliminated,\n // then we need 3, etc. This replace is guranteed to match (it may match 0 or\n // more times), and we can count the total match to see how many were eliminated.\n return relative.replace(search, (all: string) => {\n const leftover = all.length / uniqDirectory.length;\n return '../'.repeat(total - leftover);\n });\n}\n\n/**\n * Attempts to resolve `input` URL relative to `base`.\n */\nexport default function resolve(input: string, base: string | undefined): string {\n if (!base) base = '';\n\n // Absolute URLs are very easy to resolve right.\n if (isAbsoluteUrl(input)) return new Url(input).href;\n\n if (base) {\n // Absolute URLs are easy...\n if (isAbsoluteUrl(base)) return new Url(input, base).href;\n\n // If base is protocol relative, we'll resolve with it but keep the result\n // protocol relative.\n if (base.startsWith('//')) return normalizeProtocolRelative(input, `https:${base}`);\n }\n\n // Normalize input, but keep it protocol relative. We know base doesn't supply\n // a protocol, because that would have been handled above.\n if (input.startsWith('//')) return normalizeProtocolRelative(input, 'https://foo.com/');\n\n // We now know that base (if there is one) and input are paths. We've handled\n // both absolute and protocol-relative variations above.\n\n // Absolute paths don't need any special handling, because they cannot have\n // extra \".\" or \"..\"s. That'll all be stripped away. Input takes priority here,\n // because if input is an absolute path, base path won't affect it in any way.\n if (input.startsWith('/')) return '/' + normalizeSimplePath(input);\n\n // Since input and base are paths, we need to join them to do any further\n // processing. Paths are joined at the directory level, so we need to remove\n // the base's filename before joining. We also know that input does not have a\n // leading slash, and that the stripped base will have a trailing slash if\n // there are any directories (or it'll be empty).\n const joined = stripPathFilename(base) + input;\n\n // If base is an absolute path, then input will be relative to it.\n if (base.startsWith('/')) return '/' + normalizeSimplePath(joined);\n\n // We now know both base (if there is one) and input are relative paths.\n const relative = normalizePath(joined);\n\n // If base started with a leading \".\", or there is no base and input started\n // with a \".\", then we need to ensure that the relative path starts with a\n // \".\". We don't know if relative starts with a \"..\", though, so check before\n // prepending.\n if ((base || input).startsWith('.') && !relative.startsWith('.')) {\n return './' + relative;\n }\n\n return relative;\n}\n"],"names":[],"mappings":"AAMA;AACA,MAAM,GAAG,IAAI,OAAO,GAAG,KAAK,WAAW,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAQ,CAAC;;;;AAK3E,MAAM,WAAW,GAAG,qBAAqB,CAAC;AAE1C,SAAS,aAAa,CAAC,GAAW;IAChC,IAAI;QACF,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;KACvB;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;CACF;;;;AAKD,SAAS,SAAS,CAAC,GAAW;IAC5B,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC1C,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;;QAE7B,IAAI,IAAI,IAAI,CAAC;KACd;IACD,OAAO,IAAI,CAAC;CACb;;;;;;AAOD,SAAS,iBAAiB,CAAC,IAAY;IACrC,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAC3B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;CACjC;;;;;AAMD,SAAS,yBAAyB,CAAC,KAAa,EAAE,YAAoB;IACpE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;IACxD,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CACpC;;;;;AAMD,SAAS,m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I,CAAC,CAAC,IAAI,CAAC;;;QAI1D,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,yBAAyB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;KACrF;;;IAID,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,yBAAyB,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;;;;;;IAQxF,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;;;;;;IAOnE,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;;IAG/C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;;IAGnE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;IAMvC,IAAI,CAAC,IAAI,IAAI,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAChE,OAAO,IAAI,GAAG,QAAQ,CAAC;KACxB;IAED,OAAO,QAAQ,CAAC;CACjB;;;;"} | ||
| {"version":3,"file":"resolve-uri.mjs","sources":["../../src/resolve-uri.ts"],"sourcesContent":["// Matches \"..\", which must be preceeded by \"/\" or the start of the string, and\n// must be followed by a \"/\". We do not eat the following \"/\", so that the next\n// iteration can match on it.\nconst parentRegex = /(^|\\/)\\.\\.(?=\\/|$)/g;\n\n// Matches the scheme of a URL, which is a strong indicator it is an valid\n// absolute URL.\nconst schemeRegex = /^\\s*[a-z][a-z0-9+\\-.]*:/i;\n\nfunction absoluteUrl(url: string): null | URL {\n try {\n return schemeRegex.test(url) ? new URL(url) : null;\n } catch {\n /* istanbul ignore next */\n return null;\n }\n}\n\n/**\n * Creates a directory name that is guaranteed to not be in `str`.\n */\nfunction uniqInStr(str: string): string {\n let uniq = String(Math.random()).slice(2);\n let index = 0;\n while ((index = str.indexOf(uniq, index)) > -1) {\n uniq += uniq;\n }\n return uniq;\n}\n\n/**\n * Removes the filename from the path (everything trailing the last \"/\"). This\n * is only safe to call on a path, never call with an absolute or protocol\n * relative URL.\n */\nfunction stripPathFilename(path: string): string {\n path = normalizePath(path);\n const index = path.lastIndexOf('/');\n return path.slice(0, index + 1);\n}\n\n/**\n * Normalizes a protocol-relative URL, but keeps it protocol relative by\n * stripping out the protocl before returning it.\n */\nfunction normalizeProtocolRelative(input: string, absoluteBase: string): string {\n const { href, protocol } = new URL(input, absoluteBase);\n return href.slice(protocol.length);\n}\n\n/**\n * Normalizes a simple path (one that has no \"..\"s, or is absolute so \"..\"s can\n * be normalized absolutely).\n */\nfunction normalizeSimplePath(input: string): string {\n const { href } = new URL(input, 'https://foo.com/');\n return href.slice('https://foo.com/'.length);\n}\n\n/**\n * Normalizes a path, ensuring that excess \"..\"s are preserved for relative\n * paths in the output.\n *\n * If the input is absolute, this will return an absolutey normalized path, but\n * it will not have a leading \"/\".\n *\n * If the input has a leading \"..\", the output will have a leading \"..\".\n *\n * If the input has a leading \".\", the output will not have a leading \".\"\n * unless there are too many \"..\"s, in which case there will be a leading \"..\".\n */\nfunction normalizePath(input: string): string {\n // If there are no \"..\"s, we can treat this as if it were an absolute path.\n // The return won't be an absolute path, so it's easy.\n if (!parentRegex.test(input)) return normalizeSimplePath(input);\n\n // We already found one \"..\". Let's see how many there are.\n let total = 1;\n while (parentRegex.test(input)) total++;\n\n // If there are \"..\"s, we need to prefix the the path with the same number of\n // unique directories. This is to ensure that we \"remember\" how many parent\n // directories we are accessing. Eg, \"../../..\" must keep 3, and \"foo/../..\"\n // must keep 1.\n const uniqDirectory = `z${uniqInStr(input)}/`;\n\n // Now we can resolve the total path. If there are excess \"..\"s, they will\n // eliminate one or more of the unique directories we prefix with.\n const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input);\n\n // We can now count the number of unique directories that were eliminated. If\n // there were 3, and 1 was eliminated, we know we only need to add 1 \"..\". If\n // 2 were eliminated, we need to insert 2 \"..\"s. If all 3 were eliminated,\n // then we need 3, etc.\n let index = 0;\n while (relative.startsWith(uniqDirectory, index)) {\n total--;\n index += uniqDirectory.length;\n }\n return '../'.repeat(total) + relative.slice(index);\n}\n\n/**\n * Attempts to resolve `input` URL relative to `base`.\n */\nexport default function resolve(input: string, base: string | undefined): string {\n if (!base) base = '';\n\n // Absolute URLs are very easy to resolve right.\n let url;\n if ((url = absoluteUrl(input))) return url.href;\n\n if (base) {\n // Absolute URLs are easy...\n if (absoluteUrl(base)) return new URL(input, base).href;\n\n // If base is protocol relative, we'll resolve with it but keep the result\n // protocol relative.\n if (base.startsWith('//')) return normalizeProtocolRelative(input, `https:${base}`);\n }\n\n // Normalize input, but keep it protocol relative. We know base doesn't supply\n // a protocol, because that would have been handled above.\n if (input.startsWith('//')) return normalizeProtocolRelative(input, 'https://foo.com/');\n\n // We now know that base (if there is one) and input are paths. We've handled\n // both absolute and protocol-relative variations above.\n\n // Absolute paths don't need any special handling, because they cannot have\n // extra \".\" or \"..\"s. That'll all be stripped away. Input takes priority here,\n // because if input is an absolute path, base path won't affect it in any way.\n if (input.startsWith('/')) return '/' + normalizeSimplePath(input);\n\n // Since input and base are paths, we need to join them to do any further\n // processing. Paths are joined at the directory level, so we need to remove\n // the base's filename before joining. We also know that input does not have a\n // leading slash, and that the stripped base will have a trailing slash if\n // there are any directories (or it'll be empty).\n const joined = stripPathFilename(base) + input;\n\n // If base is an absolute path, then input will be relative to it.\n if (base.startsWith('/')) return '/' + normalizeSimplePath(joined);\n\n // We now know both base (if there is one) and input are relative paths.\n const relative = normalizePath(joined);\n\n // If base started with a leading \".\", or there is no base and input started\n // with a \".\", then we need to ensure that the relative path starts with a\n // \".\". We don't know if relative starts with a \"..\", though, so check before\n // prepending.\n if ((base || input).startsWith('.') && !relative.startsWith('.')) {\n return './'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I,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,yBAAyB,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC,CAAC;KACrF;;;IAID,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,yBAAyB,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;;;;;;IAQxF,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;;;;;;IAOnE,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;;IAG/C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;;IAGnE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;IAMvC,IAAI,CAAC,IAAI,IAAI,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAChE,OAAO,IAAI,GAAG,QAAQ,CAAC;KACxB;IAED,OAAO,QAAQ,CAAC;AAClB;;;;"} |
+149
-149
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
| typeof define === 'function' && define.amd ? define(factory) : | ||
| (global = global || self, global.resolveURI = factory()); | ||
| }(this, function () { 'use strict'; | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
| typeof define === 'function' && define.amd ? define(factory) : | ||
| (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.resolveURI = factory()); | ||
| }(this, (function () { 'use strict'; | ||
| /* istanbul ignore next */ | ||
| const Url = (typeof URL !== 'undefined' ? URL : require('url').URL); | ||
| // Matches "..", which must be preceeded by "/" or the start of the string, and | ||
| // must be followed by a "/". We do not eat the following "/", so that the next | ||
| // iteration can match on it. | ||
| const parentRegex = /(^|\/)\.\.(?=\/|$)/g; | ||
| function isAbsoluteUrl(url) { | ||
| try { | ||
| return !!new Url(url); | ||
| } | ||
| catch (e) { | ||
| return false; | ||
| } | ||
| } | ||
| /** | ||
| * Creates a directory name that is guaranteed to not be in `str`. | ||
| */ | ||
| function uniqInStr(str) { | ||
| let uniq = String(Math.random()).slice(2); | ||
| while (str.indexOf(uniq) > -1) { | ||
| /* istanbul ignore next */ | ||
| uniq += uniq; | ||
| } | ||
| return uniq; | ||
| } | ||
| /** | ||
| * Removes the filename from the path (everything trailing the last "/"). This | ||
| * is only safe to call on a path, never call with an absolute or protocol | ||
| * relative URL. | ||
| */ | ||
| function stripPathFilename(path) { | ||
| path = normalizePath(path); | ||
| const index = path.lastIndexOf('/'); | ||
| return path.slice(0, index + 1); | ||
| } | ||
| /** | ||
| * Normalizes a protocol-relative URL, but keeps it protocol relative by | ||
| * stripping out the protocl before returning it. | ||
| */ | ||
| function normalizeProtocolRelative(input, absoluteBase) { | ||
| const { href, protocol } = new Url(input, absoluteBase); | ||
| return href.slice(protocol.length); | ||
| } | ||
| /** | ||
| * Normalizes a simple path (one that has no ".."s, or is absolute so ".."s can | ||
| * be normalized absolutely). | ||
| */ | ||
| function normalizeSimplePath(input) { | ||
| const { href } = new Url(input, 'https://foo.com/'); | ||
| return href.slice('https://foo.com/'.length); | ||
| } | ||
| /** | ||
| * Normalizes a path, ensuring that excess ".."s are preserved for relative | ||
| * paths in the output. | ||
| * | ||
| * If the input is absolute, this will return an absolutey normalized path, but | ||
| * it will not have a leading "/". | ||
| * | ||
| * If the input has a leading "..", the output will have a leading "..". | ||
| * | ||
| * If the input has a leading ".", the output will not have a leading "." | ||
| * unless there are too many ".."s, in which case there will be a leading "..". | ||
| */ | ||
| function normalizePath(input) { | ||
| // If there are no ".."s, we can treat this as if it were an absolute path. | ||
| // The return won't be an absolute path, so it's easy. | ||
| if (!parentRegex.test(input)) | ||
| return normalizeSimplePath(input); | ||
| // We already found one "..". Let's see how many there are. | ||
| let total = 1; | ||
| while (parentRegex.test(input)) | ||
| total++; | ||
| // If there are ".."s, we need to prefix the the path with the same number of | ||
| // unique directories. This is to ensure that we "remember" how many parent | ||
| // directories we are accessing. Eg, "../../.." must keep 3, and "foo/../.." | ||
| // must keep 1. | ||
| const uniqDirectory = `z${uniqInStr(input)}/`; | ||
| // uniqDirectory is just a "z", followed by numbers, followed by a "/". So | ||
| // generating a runtime regex from it is safe. We'll use this search regex to | ||
| // strip out our uniq directory names and insert any needed ".."s. | ||
| const search = new RegExp(`^(?:${uniqDirectory})*`); | ||
| // Now we can resolve the total path. If there are excess ".."s, they will | ||
| // eliminate one or more of the unique directories we prefix with. | ||
| const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input); | ||
| // We can now count the number of unique directories that were eliminated. If | ||
| // there were 3, and 1 was eliminated, we know we only need to add 1 "..". If | ||
| // 2 were eliminated, we need to insert 2 ".."s. If all 3 were eliminated, | ||
| // then we need 3, etc. This replace is guranteed to match (it may match 0 or | ||
| // more times), and we can count the total match to see how many were eliminated. | ||
| return relative.replace(search, (all) => { | ||
| const leftover = all.length / uniqDirectory.length; | ||
| return '../'.repeat(total - leftover); | ||
| }); | ||
| } | ||
| /** | ||
| * Attempts to resolve `input` URL relative to `base`. | ||
| */ | ||
| function resolve(input, base) { | ||
| if (!base) | ||
| base = ''; | ||
| // Absolute URLs are very easy to resolve right. | ||
| if (isAbsoluteUrl(input)) | ||
| return new Url(input).href; | ||
| if (base) { | ||
| // Absolute URLs are easy... | ||
| if (isAbsoluteUrl(base)) | ||
| return new Url(input, base).href; | ||
| // If base is protocol relative, we'll resolve with it but keep the result | ||
| // protocol relative. | ||
| if (base.startsWith('//')) | ||
| return normalizeProtocolRelative(input, `https:${base}`); | ||
| } | ||
| // Normalize input, but keep it protocol relative. We know base doesn't supply | ||
| // a protocol, because that would have been handled above. | ||
| if (input.startsWith('//')) | ||
| return normalizeProtocolRelative(input, 'https://foo.com/'); | ||
| // We now know that base (if there is one) and input are paths. We've handled | ||
| // both absolute and protocol-relative variations above. | ||
| // Absolute paths don't need any special handling, because they cannot have | ||
| // extra "." or ".."s. That'll all be stripped away. Input takes priority here, | ||
| // because if input is an absolute path, base path won't affect it in any way. | ||
| if (input.startsWith('/')) | ||
| return '/' + normalizeSimplePath(input); | ||
| // Since input and base are paths, we need to join them to do any further | ||
| // processing. Paths are joined at the directory level, so we need to remove | ||
| // the base's filename before joining. We also know that input does not have a | ||
| // leading slash, and that the stripped base will have a trailing slash if | ||
| // there are any directories (or it'll be empty). | ||
| const joined = stripPathFilename(base) + input; | ||
| // If base is an absolute path, then input will be relative to it. | ||
| if (base.startsWith('/')) | ||
| return '/' + normalizeSimplePath(joined); | ||
| // We now know both base (if there is one) and input are relative paths. | ||
| const relative = normalizePath(joined); | ||
| // If base started with a leading ".", or there is no base and input started | ||
| // with a ".", then we need to ensure that the relative path starts with a | ||
| // ".". We don't know if relative starts with a "..", though, so check before | ||
| // prepending. | ||
| if ((base || input).startsWith('.') && !relative.startsWith('.')) { | ||
| return './' + relative; | ||
| } | ||
| return relative; | ||
| } | ||
| // Matches "..", which must be preceeded by "/" or the start of the string, and | ||
| // must be followed by a "/". We do not eat the following "/", so that the next | ||
| // iteration can match on it. | ||
| const parentRegex = /(^|\/)\.\.(?=\/|$)/g; | ||
| // Matches the scheme of a URL, which is a strong indicator it is an valid | ||
| // absolute URL. | ||
| const schemeRegex = /^\s*[a-z][a-z0-9+\-.]*:/i; | ||
| function absoluteUrl(url) { | ||
| try { | ||
| return schemeRegex.test(url) ? new URL(url) : null; | ||
| } | ||
| catch (_a) { | ||
| /* istanbul ignore next */ | ||
| return null; | ||
| } | ||
| } | ||
| /** | ||
| * Creates a directory name that is guaranteed to not be in `str`. | ||
| */ | ||
| function uniqInStr(str) { | ||
| let uniq = String(Math.random()).slice(2); | ||
| let index = 0; | ||
| while ((index = str.indexOf(uniq, index)) > -1) { | ||
| uniq += uniq; | ||
| } | ||
| return uniq; | ||
| } | ||
| /** | ||
| * Removes the filename from the path (everything trailing the last "/"). This | ||
| * is only safe to call on a path, never call with an absolute or protocol | ||
| * relative URL. | ||
| */ | ||
| function stripPathFilename(path) { | ||
| path = normalizePath(path); | ||
| const index = path.lastIndexOf('/'); | ||
| return path.slice(0, index + 1); | ||
| } | ||
| /** | ||
| * Normalizes a protocol-relative URL, but keeps it protocol relative by | ||
| * stripping out the protocl before returning it. | ||
| */ | ||
| function normalizeProtocolRelative(input, absoluteBase) { | ||
| const { href, protocol } = new URL(input, absoluteBase); | ||
| return href.slice(protocol.length); | ||
| } | ||
| /** | ||
| * Normalizes a simple path (one that has no ".."s, or is absolute so ".."s can | ||
| * be normalized absolutely). | ||
| */ | ||
| function normalizeSimplePath(input) { | ||
| const { href } = new URL(input, 'https://foo.com/'); | ||
| return href.slice('https://foo.com/'.length); | ||
| } | ||
| /** | ||
| * Normalizes a path, ensuring that excess ".."s are preserved for relative | ||
| * paths in the output. | ||
| * | ||
| * If the input is absolute, this will return an absolutey normalized path, but | ||
| * it will not have a leading "/". | ||
| * | ||
| * If the input has a leading "..", the output will have a leading "..". | ||
| * | ||
| * If the input has a leading ".", the output will not have a leading "." | ||
| * unless there are too many ".."s, in which case there will be a leading "..". | ||
| */ | ||
| function normalizePath(input) { | ||
| // If there are no ".."s, we can treat this as if it were an absolute path. | ||
| // The return won't be an absolute path, so it's easy. | ||
| if (!parentRegex.test(input)) | ||
| return normalizeSimplePath(input); | ||
| // We already found one "..". Let's see how many there are. | ||
| let total = 1; | ||
| while (parentRegex.test(input)) | ||
| total++; | ||
| // If there are ".."s, we need to prefix the the path with the same number of | ||
| // unique directories. This is to ensure that we "remember" how many parent | ||
| // directories we are accessing. Eg, "../../.." must keep 3, and "foo/../.." | ||
| // must keep 1. | ||
| const uniqDirectory = `z${uniqInStr(input)}/`; | ||
| // Now we can resolve the total path. If there are excess ".."s, they will | ||
| // eliminate one or more of the unique directories we prefix with. | ||
| const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input); | ||
| // We can now count the number of unique directories that were eliminated. If | ||
| // there were 3, and 1 was eliminated, we know we only need to add 1 "..". If | ||
| // 2 were eliminated, we need to insert 2 ".."s. If all 3 were eliminated, | ||
| // then we need 3, etc. | ||
| let index = 0; | ||
| while (relative.startsWith(uniqDirectory, index)) { | ||
| total--; | ||
| index += uniqDirectory.length; | ||
| } | ||
| return '../'.repeat(total) + relative.slice(index); | ||
| } | ||
| /** | ||
| * Attempts to resolve `input` URL relative to `base`. | ||
| */ | ||
| function resolve(input, base) { | ||
| if (!base) | ||
| base = ''; | ||
| // Absolute URLs are very easy to resolve right. | ||
| let url; | ||
| if ((url = absoluteUrl(input))) | ||
| return url.href; | ||
| if (base) { | ||
| // Absolute URLs are easy... | ||
| if (absoluteUrl(base)) | ||
| return new URL(input, base).href; | ||
| // If base is protocol relative, we'll resolve with it but keep the result | ||
| // protocol relative. | ||
| if (base.startsWith('//')) | ||
| return normalizeProtocolRelative(input, `https:${base}`); | ||
| } | ||
| // Normalize input, but keep it protocol relative. We know base doesn't supply | ||
| // a protocol, because that would have been handled above. | ||
| if (input.startsWith('//')) | ||
| return normalizeProtocolRelative(input, 'https://foo.com/'); | ||
| // We now know that base (if there is one) and input are paths. We've handled | ||
| // both absolute and protocol-relative variations above. | ||
| // Absolute paths don't need any special handling, because they cannot have | ||
| // extra "." or ".."s. That'll all be stripped away. Input takes priority here, | ||
| // because if input is an absolute path, base path won't affect it in any way. | ||
| if (input.startsWith('/')) | ||
| return '/' + normalizeSimplePath(input); | ||
| // Since input and base are paths, we need to join them to do any further | ||
| // processing. Paths are joined at the directory level, so we need to remove | ||
| // the base's filename before joining. We also know that input does not have a | ||
| // leading slash, and that the stripped base will have a trailing slash if | ||
| // there are any directories (or it'll be empty). | ||
| const joined = stripPathFilename(base) + input; | ||
| // If base is an absolute path, then input will be relative to it. | ||
| if (base.startsWith('/')) | ||
| return '/' + normalizeSimplePath(joined); | ||
| // We now know both base (if there is one) and input are relative paths. | ||
| const relative = normalizePath(joined); | ||
| // If base started with a leading ".", or there is no base and input started | ||
| // with a ".", then we need to ensure that the relative path starts with a | ||
| // ".". We don't know if relative starts with a "..", though, so check before | ||
| // prepending. | ||
| if ((base || input).startsWith('.') && !relative.startsWith('.')) { | ||
| return './' + relative; | ||
| } | ||
| return relative; | ||
| } | ||
| return resolve; | ||
| return resolve; | ||
| })); | ||
| }))); | ||
| //# sourceMappingURL=resolve-uri.umd.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"resolve-uri.umd.js","sources":["../src/resolve-uri.ts"],"sourcesContent":["type WhatWgUrl = import('url').URL;\ninterface Url extends WhatWgUrl {\n new (input: string, base?: string): WhatWgUrl;\n}\ndeclare var URL: unknown;\n\n/* istanbul ignore next */\nconst Url = (typeof URL !== 'undefined' ? URL : require('url').URL) as Url;\n\n// Matches \"..\", which must be preceeded by \"/\" or the start of the string, and\n// must be followed by a \"/\". We do not eat the following \"/\", so that the next\n// iteration can match on it.\nconst parentRegex = /(^|\\/)\\.\\.(?=\\/|$)/g;\n\nfunction isAbsoluteUrl(url: string): boolean {\n try {\n return !!new Url(url);\n } catch (e) {\n return false;\n }\n}\n\n/**\n * Creates a directory name that is guaranteed to not be in `str`.\n */\nfunction uniqInStr(str: string): string {\n let uniq = String(Math.random()).slice(2);\n while (str.indexOf(uniq) > -1) {\n /* istanbul ignore next */\n uniq += uniq;\n }\n return uniq;\n}\n\n/**\n * Removes the filename from the path (everything trailing the last \"/\"). This\n * is only safe to call on a path, never call with an absolute or protocol\n * relative URL.\n */\nfunction stripPathFilename(path: string): string {\n path = normalizePath(path);\n const index = path.lastIndexOf('/');\n return path.slice(0, index + 1);\n}\n\n/**\n * Normalizes a protocol-relative URL, but keeps it protocol relative by\n * stripping out the protocl before returning it.\n */\nfunction normalizeProtocolRelative(input: string, absoluteBase: string): string {\n const { href, protocol } = new Url(input, absoluteBase);\n return href.slice(protocol.length);\n}\n\n/**\n * Normalizes a simple path (one that has no \"..\"s, or is absolute so \"..\"s can\n * be normalized absolutely).\n */\nfunction normalizeSimplePath(input: string): string {\n const { href } = new Url(input, 'https://foo.com/');\n return href.slice('https://foo.com/'.length);\n}\n\n/**\n * Normalizes a path, ensuring that excess \"..\"s are preserved for relative\n * paths in the output.\n *\n * If the input is absolute, this will return an absolutey normalized path, but\n * it will not have a leading \"/\".\n *\n * If the input has a leading \"..\", the output will have a leading \"..\".\n *\n * If the input has a leading \".\", the output will not have a leading \".\"\n * unless there are too many \"..\"s, in which case there will be a leading \"..\".\n */\nfunction normalizePath(input: string): string {\n // If there are no \"..\"s, we can treat this as if it were an absolute path.\n // The return won't be an absolute path, so it's easy.\n if (!parentRegex.test(input)) return normalizeSimplePath(input);\n\n // We already found one \"..\". Let's see how many there are.\n let total = 1;\n while (parentRegex.test(input)) total++;\n\n // If there are \"..\"s, we need to prefix the the path with the same number of\n // unique directories. This is to ensure that we \"remember\" how many parent\n // directories we are accessing. Eg, \"../../..\" must keep 3, and \"foo/../..\"\n // must keep 1.\n const uniqDirectory = `z${uniqInStr(input)}/`;\n\n // uniqDirectory is just a \"z\", followed by numbers, followed by a \"/\". So\n // generating a runtime regex from it is safe. We'll use this search regex to\n // strip out our uniq directory names and insert any needed \"..\"s.\n const search = new RegExp(`^(?:${uniqDirectory})*`);\n\n // Now we can resolve the total path. If there are excess \"..\"s, they will\n // eliminate one or more of the unique directories we prefix with.\n const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input);\n\n // We can now count the number of unique directories that were eliminated. If\n // there were 3, and 1 was eliminated, we know we only need to add 1 \"..\". If\n // 2 were eliminated, we need to insert 2 \"..\"s. If all 3 were eliminated,\n // then we need 3, etc. This replace is guranteed to match (it may match 0 or\n // more times), and we can count the total match to see how many were eliminated.\n return relative.replace(search, (all: string) => {\n const leftover = all.length / uniqDirectory.length;\n return '../'.repeat(total - leftover);\n });\n}\n\n/**\n * Attempts to resolve `input` URL relative to `base`.\n */\nexport default function resolve(input: string, base: string | undefined): string {\n if (!base) base = '';\n\n // Absolute URLs are very easy to resolve right.\n if (isAbsoluteUrl(input)) return new Url(input).href;\n\n if (base) {\n // Absolute URLs are easy...\n if (isAbsoluteUrl(base)) return new Url(input, base).href;\n\n // If base is protocol relative, we'll resolve with it but keep the result\n // protocol relative.\n if (base.startsWith('//')) return normalizeProtocolRelative(input, `https:${base}`);\n }\n\n // Normalize input, but keep it protocol relative. We know base doesn't supply\n // a protocol, because that would have been handled above.\n if (input.startsWith('//')) return normalizeProtocolRelative(input, 'https://foo.com/');\n\n // We now know that base (if there is one) and input are paths. We've handled\n // both absolute and protocol-relative variations above.\n\n // Absolute paths don't need any special handling, because they cannot have\n // extra \".\" or \"..\"s. That'll all be stripped away. Input takes priority here,\n // because if input is an absolute path, base path won't affect it in any way.\n if (input.startsWith('/')) return '/' + normalizeSimplePath(input);\n\n // Since input and base are paths, we need to join them to do any further\n // processing. Paths are joined at the directory level, so we need to remove\n // the base's filename before joining. We also know that input does not have a\n // leading slash, and that the stripped base will have a trailing slash if\n // there are any directories (or it'll be empty).\n const joined = stripPathFilename(base) + input;\n\n // If base is an absolute path, then input will be relative to it.\n if (base.startsWith('/')) return '/' + normalizeSimplePath(joined);\n\n // We now know both base (if there is one) and input are relative paths.\n const relative = normalizePath(joined);\n\n // If base started with a leading \".\", or there is no base and input started\n // with a \".\", then we need to ensure that the relative path starts with a\n // \".\". We don't know if relative starts with a \"..\", though, so check before\n // prepending.\n if ((base || input).startsWith('.') && !relative.startsWith('.')) {\n return './' + relative;\n }\n\n return relative;\n}\n"],"names":[],"mappings":";;;;;;EAMA;EACA,MAAM,GAAG,IAAI,OAAO,GAAG,KAAK,WAAW,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAQ,CAAC;EAE3E;EACA;EACA;EACA,MAAM,WAAW,GAAG,qBAAqB,CAAC;EAE1C,SAAS,aAAa,CAAC,GAAW;MAChC,IAAI;UACF,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG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B,CAAC,KAAK,CAAC,CAAC;;;;;;MAOnE,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;;MAG/C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;UAAE,OAAO,GAAG,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;;MAGnE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;MAMvC,IAAI,CAAC,IAAI,IAAI,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;UAChE,OAAO,IAAI,GAAG,QAAQ,CAAC;OACxB;MAED,OAAO,QAAQ,CAAC;EAClB,CAAC;;;;;;;;"} | ||
| {"version":3,"file":"resolve-uri.umd.js","sources":["../../src/resolve-uri.ts"],"sourcesContent":["// Matches \"..\", which must be preceeded by \"/\" or the start of the string, and\n// must be followed by a \"/\". We do not eat the following \"/\", so that the next\n// iteration can match on it.\nconst parentRegex = /(^|\\/)\\.\\.(?=\\/|$)/g;\n\n// Matches the scheme of a URL, which is a strong indicator it is an valid\n// absolute URL.\nconst schemeRegex = /^\\s*[a-z][a-z0-9+\\-.]*:/i;\n\nfunction absoluteUrl(url: string): null | URL {\n try {\n return schemeRegex.test(url) ? new URL(url) : null;\n } catch {\n /* istanbul ignore next */\n return null;\n }\n}\n\n/**\n * Creates a directory name that is guaranteed to not be in `str`.\n */\nfunction uniqInStr(str: string): string {\n let uniq = String(Math.random()).slice(2);\n let index = 0;\n while ((index = str.indexOf(uniq, index)) > -1) {\n uniq += uniq;\n }\n return uniq;\n}\n\n/**\n * Removes the filename from the path (everything trailing the last \"/\"). This\n * is only safe to call on a path, never call with an absolute or protocol\n * relative URL.\n */\nfunction stripPathFilename(path: string): string {\n path = normalizePath(path);\n const index = path.lastIndexOf('/');\n return path.slice(0, index + 1);\n}\n\n/**\n * Normalizes a protocol-relative URL, but keeps it protocol relative by\n * stripping out the protocl before returning it.\n */\nfunction normalizeProtocolRelative(input: string, absoluteBase: string): string {\n const { href, protocol } = new URL(input, absoluteBase);\n return href.slice(protocol.length);\n}\n\n/**\n * Normalizes a simple path (one that has no \"..\"s, or is absolute so \"..\"s can\n * be normalized absolutely).\n */\nfunction normalizeSimplePath(input: string): string {\n const { href } = new URL(input, 'https://foo.com/');\n return href.slice('https://foo.com/'.length);\n}\n\n/**\n * Normalizes a path, ensuring that excess \"..\"s are preserved for relative\n * paths in the output.\n *\n * If the input is absolute, this will return an absolutey normalized path, but\n * it will not have a leading \"/\".\n *\n * If the input has a leading \"..\", the output will have a leading \"..\".\n *\n * If the input has a leading \".\", the output will not have a leading \".\"\n * unless there are too many \"..\"s, in which case there will be a leading \"..\".\n */\nfunction normalizePath(input: string): string {\n // If there are no \"..\"s, we can treat this as if it were an absolute path.\n // The return won't be an absolute path, so it's easy.\n if (!parentRegex.test(input)) return normalizeSimplePath(input);\n\n // We already found one \"..\". Let's see how many there are.\n let total = 1;\n while (parentRegex.test(input)) total++;\n\n // If there are \"..\"s, we need to prefix the the path with the same number of\n // unique directories. This is to ensure that we \"remember\" how many parent\n // directories we are accessing. Eg, \"../../..\" must keep 3, and \"foo/../..\"\n // must keep 1.\n const uniqDirectory = `z${uniqInStr(input)}/`;\n\n // Now we can resolve the total path. If there are excess \"..\"s, they will\n // eliminate one or more of the unique directories we prefix with.\n const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input);\n\n // We can now count the number of unique directories that were eliminated. If\n // there were 3, and 1 was eliminated, we know we only need to add 1 \"..\". If\n // 2 were eliminated, we need to insert 2 \"..\"s. If all 3 were eliminated,\n // then we need 3, etc.\n let index = 0;\n while (relative.startsWith(uniqDirectory, index)) {\n total--;\n index += uniqDirectory.length;\n }\n return '../'.repeat(total) + relative.slice(index);\n}\n\n/**\n * Attempts to resolve `input` URL relative to `base`.\n */\nexport default function resolve(input: string, base: string | undefined): string {\n if (!base) base = '';\n\n // Absolute URLs are very easy to resolve right.\n let url;\n if ((url = absoluteUrl(input))) return url.href;\n\n if (base) {\n // Absolute URLs are easy...\n if (absoluteUrl(base)) return new URL(input, base).href;\n\n // If base is protocol relative, we'll resolve with it but keep the result\n // protocol relative.\n if (base.startsWith('//')) return normalizeProtocolRelative(input, `https:${base}`);\n }\n\n // Normalize input, but keep it protocol relative. We know base doesn't supply\n // a protocol, because that would have been handled above.\n if (input.startsWith('//')) return normalizeProtocolRelative(input, 'https://foo.com/');\n\n // We now know that base (if there is one) and input are paths. We've handled\n // both absolute and protocol-relative variations above.\n\n // Absolute paths don't need any special handling, because they cannot have\n // extra \".\" or \"..\"s. That'll all be stripped away. Input takes priority here,\n // because if input is an absolute path, base path won't affect it in any way.\n if (input.startsWith('/')) return '/' + normalizeSimplePath(input);\n\n // Since input and base are paths, we need to join them to do any further\n // processing. Paths are joined at the directory level, so we need to remove\n // the base's filename before joining. We also know that input does not have a\n // leading slash, and that the stripped base will have a trailing slash if\n // there are any directories (or it'll be empty).\n const joined = stripPathFilename(base) + input;\n\n // If base is an absolute path, then input will be relative to it.\n if (base.startsWith('/')) return '/' + normalizeSimplePath(joined);\n\n // We now know both base (if there is one) and input are relative paths.\n const relative = normalizePath(joined);\n\n // If base started with a leading \".\", or there is no base and input started\n // with a \".\", then we need to ensure that the relative path starts with a\n // \".\". We don't know if relative starts with a \"..\", though, so check before\n // prepending.\n if ((base || input).startsWith('.') && !relative.startsWith('.')) {\n return './' + relative;\n }\n\n return relative;\n}\n"],"names":[],"mappings":";;;;;;IAAA;IACA;IACA;IACA,MAAM,WAAW,GAAG,qBAAqB,CAAC;IAE1C;IACA;IACA,MAAM,WAAW,GAAG,0BAA0B,CAAC;IAE/C,SAAS,WAAW,CAAC,GAAW;QAC9B,IAAI;YACF,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;SACpD;QAAC,WAAM;;YAEN,OAAO,IAAI,CAA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,CAAC;;;;;;QAOnE,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;;QAG/C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,GAAG,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;;QAGnE,MAAM,QAAQ,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;;;;;QAMvC,IAAI,CAAC,IAAI,IAAI,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAChE,OAAO,IAAI,GAAG,QAAQ,CAAC;SACxB;QAED,OAAO,QAAQ,CAAC;IAClB;;;;;;;;"} |
+30
-39
| { | ||
| "name": "@jridgewell/resolve-uri", | ||
| "version": "1.0.0", | ||
| "version": "2.0.0", | ||
| "description": "Resolve a URI relative to an optional base URI", | ||
@@ -11,2 +11,5 @@ "keywords": [ | ||
| ], | ||
| "author": "Justin Ridgewell <justin@ridgewell.name>", | ||
| "license": "MIT", | ||
| "repository": "https://github.com/jridgewell/resolve-uri", | ||
| "main": "dist/resolve-uri.umd.js", | ||
@@ -18,51 +21,39 @@ "module": "dist/resolve-uri.mjs", | ||
| ], | ||
| "author": "Justin Ridgewell <jridgewell@google.com>", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/jridgewell/resolve-uri.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/jridgewell/resolve-uri/issues" | ||
| }, | ||
| "license": "MIT", | ||
| "engines": { | ||
| "node": ">=6.0.0" | ||
| "node": ">=10.0.0" | ||
| }, | ||
| "scripts": { | ||
| "lint:ts": "npm run test:lint:ts -- --fix", | ||
| "lint:prettier": "npm run test:lint:prettier -- --write", | ||
| "lint": "run-s -n lint:*", | ||
| "prebuild": "rm -rf dist", | ||
| "build:ts": "tsc --module commonjs", | ||
| "build:rollup": "rollup -c rollup.config.ts", | ||
| "build": "run-s -n build:*", | ||
| "test": "jest --coverage", | ||
| "build:rollup": "rollup -c rollup.config.js", | ||
| "build:ts": "tsc --project tsconfig.build.json", | ||
| "lint": "run-s -n lint:*", | ||
| "lint:prettier": "npm run test:lint:prettier -- --write", | ||
| "lint:ts": "npm run test:lint:ts -- --fix", | ||
| "test": "run-s -n test:lint 'test:only -- --no-cache'", | ||
| "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand", | ||
| "test:lint": "run-s -n test:lint:*", | ||
| "test:lint:prettier": "prettier --check '{src,test}/**/*.ts'", | ||
| "test:lint:ts": "eslint '{src,test}/**/*.ts'", | ||
| "test:only": "jest --coverage", | ||
| "test:watch": "jest --coverage --watch", | ||
| "test:lint:ts": "tslint --project tsconfig.json -t codeFrame '{src,test}/**/*.ts'", | ||
| "test:lint:prettier": "prettier --check '{src,test}/**/*.ts'", | ||
| "test:lint": "run-s -n test:lint:*", | ||
| "test:prod": "run-s -n test:lint 'test --no-cache'", | ||
| "preversion": "run-s test:prod build", | ||
| "prepublishOnly": "npm run preversion" | ||
| "prepublishOnly": "npm run preversion", | ||
| "preversion": "run-s test build" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/jest": "24.0.15", | ||
| "@types/node": "12.6.2", | ||
| "jest": "24.8.0", | ||
| "jest-config": "24.8.0", | ||
| "@rollup/plugin-typescript": "8.1.0", | ||
| "@types/jest": "26.0.19", | ||
| "@typescript-eslint/eslint-plugin": "4.10.0", | ||
| "@typescript-eslint/parser": "4.10.0", | ||
| "eslint": "7.15.0", | ||
| "eslint-config-prettier": "7.0.0", | ||
| "jest": "26.6.3", | ||
| "jest-config": "26.6.3", | ||
| "npm-run-all": "4.1.5", | ||
| "prettier": "1.18.2", | ||
| "rollup": "1.16.7", | ||
| "rollup-plugin-commonjs": "10.0.1", | ||
| "rollup-plugin-node-resolve": "5.2.0", | ||
| "rollup-plugin-sourcemaps": "0.4.2", | ||
| "rollup-plugin-typescript": "1.0.1", | ||
| "ts-jest": "24.0.2", | ||
| "ts-node": "8.3.0", | ||
| "tslint": "5.18.0", | ||
| "tslint-config-prettier": "1.18.0", | ||
| "tslint-config-standard": "8.0.1", | ||
| "typescript": "3.5.3" | ||
| "prettier": "2.2.1", | ||
| "rollup": "2.35.1", | ||
| "ts-jest": "26.4.4", | ||
| "tslib": "2.0.3", | ||
| "typescript": "4.1.3" | ||
| } | ||
| } |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| /* istanbul ignore next */ | ||
| const Url = (typeof URL !== 'undefined' ? URL : require('url').URL); | ||
| // Matches "..", which must be preceeded by "/" or the start of the string, and | ||
| // must be followed by a "/". We do not eat the following "/", so that the next | ||
| // iteration can match on it. | ||
| const parentRegex = /(^|\/)\.\.(?=\/|$)/g; | ||
| function isAbsoluteUrl(url) { | ||
| try { | ||
| return !!new Url(url); | ||
| } | ||
| catch (e) { | ||
| return false; | ||
| } | ||
| } | ||
| /** | ||
| * Creates a directory name that is guaranteed to not be in `str`. | ||
| */ | ||
| function uniqInStr(str) { | ||
| let uniq = String(Math.random()).slice(2); | ||
| while (str.indexOf(uniq) > -1) { | ||
| /* istanbul ignore next */ | ||
| uniq += uniq; | ||
| } | ||
| return uniq; | ||
| } | ||
| /** | ||
| * Removes the filename from the path (everything trailing the last "/"). This | ||
| * is only safe to call on a path, never call with an absolute or protocol | ||
| * relative URL. | ||
| */ | ||
| function stripPathFilename(path) { | ||
| path = normalizePath(path); | ||
| const index = path.lastIndexOf('/'); | ||
| return path.slice(0, index + 1); | ||
| } | ||
| /** | ||
| * Normalizes a protocol-relative URL, but keeps it protocol relative by | ||
| * stripping out the protocl before returning it. | ||
| */ | ||
| function normalizeProtocolRelative(input, absoluteBase) { | ||
| const { href, protocol } = new Url(input, absoluteBase); | ||
| return href.slice(protocol.length); | ||
| } | ||
| /** | ||
| * Normalizes a simple path (one that has no ".."s, or is absolute so ".."s can | ||
| * be normalized absolutely). | ||
| */ | ||
| function normalizeSimplePath(input) { | ||
| const { href } = new Url(input, 'https://foo.com/'); | ||
| return href.slice('https://foo.com/'.length); | ||
| } | ||
| /** | ||
| * Normalizes a path, ensuring that excess ".."s are preserved for relative | ||
| * paths in the output. | ||
| * | ||
| * If the input is absolute, this will return an absolutey normalized path, but | ||
| * it will not have a leading "/". | ||
| * | ||
| * If the input has a leading "..", the output will have a leading "..". | ||
| * | ||
| * If the input has a leading ".", the output will not have a leading "." | ||
| * unless there are too many ".."s, in which case there will be a leading "..". | ||
| */ | ||
| function normalizePath(input) { | ||
| // If there are no ".."s, we can treat this as if it were an absolute path. | ||
| // The return won't be an absolute path, so it's easy. | ||
| if (!parentRegex.test(input)) | ||
| return normalizeSimplePath(input); | ||
| // We already found one "..". Let's see how many there are. | ||
| let total = 1; | ||
| while (parentRegex.test(input)) | ||
| total++; | ||
| // If there are ".."s, we need to prefix the the path with the same number of | ||
| // unique directories. This is to ensure that we "remember" how many parent | ||
| // directories we are accessing. Eg, "../../.." must keep 3, and "foo/../.." | ||
| // must keep 1. | ||
| const uniqDirectory = `z${uniqInStr(input)}/`; | ||
| // uniqDirectory is just a "z", followed by numbers, followed by a "/". So | ||
| // generating a runtime regex from it is safe. We'll use this search regex to | ||
| // strip out our uniq directory names and insert any needed ".."s. | ||
| const search = new RegExp(`^(?:${uniqDirectory})*`); | ||
| // Now we can resolve the total path. If there are excess ".."s, they will | ||
| // eliminate one or more of the unique directories we prefix with. | ||
| const relative = normalizeSimplePath(uniqDirectory.repeat(total) + input); | ||
| // We can now count the number of unique directories that were eliminated. If | ||
| // there were 3, and 1 was eliminated, we know we only need to add 1 "..". If | ||
| // 2 were eliminated, we need to insert 2 ".."s. If all 3 were eliminated, | ||
| // then we need 3, etc. This replace is guranteed to match (it may match 0 or | ||
| // more times), and we can count the total match to see how many were eliminated. | ||
| return relative.replace(search, (all) => { | ||
| const leftover = all.length / uniqDirectory.length; | ||
| return '../'.repeat(total - leftover); | ||
| }); | ||
| } | ||
| /** | ||
| * Attempts to resolve `input` URL relative to `base`. | ||
| */ | ||
| function resolve(input, base) { | ||
| if (!base) | ||
| base = ''; | ||
| // Absolute URLs are very easy to resolve right. | ||
| if (isAbsoluteUrl(input)) | ||
| return new Url(input).href; | ||
| if (base) { | ||
| // Absolute URLs are easy... | ||
| if (isAbsoluteUrl(base)) | ||
| return new Url(input, base).href; | ||
| // If base is protocol relative, we'll resolve with it but keep the result | ||
| // protocol relative. | ||
| if (base.startsWith('//')) | ||
| return normalizeProtocolRelative(input, `https:${base}`); | ||
| } | ||
| // Normalize input, but keep it protocol relative. We know base doesn't supply | ||
| // a protocol, because that would have been handled above. | ||
| if (input.startsWith('//')) | ||
| return normalizeProtocolRelative(input, 'https://foo.com/'); | ||
| // We now know that base (if there is one) and input are paths. We've handled | ||
| // both absolute and protocol-relative variations above. | ||
| // Absolute paths don't need any special handling, because they cannot have | ||
| // extra "." or ".."s. That'll all be stripped away. Input takes priority here, | ||
| // because if input is an absolute path, base path won't affect it in any way. | ||
| if (input.startsWith('/')) | ||
| return '/' + normalizeSimplePath(input); | ||
| // Since input and base are paths, we need to join them to do any further | ||
| // processing. Paths are joined at the directory level, so we need to remove | ||
| // the base's filename before joining. We also know that input does not have a | ||
| // leading slash, and that the stripped base will have a trailing slash if | ||
| // there are any directories (or it'll be empty). | ||
| const joined = stripPathFilename(base) + input; | ||
| // If base is an absolute path, then input will be relative to it. | ||
| if (base.startsWith('/')) | ||
| return '/' + normalizeSimplePath(joined); | ||
| // We now know both base (if there is one) and input are relative paths. | ||
| const relative = normalizePath(joined); | ||
| // If base started with a leading ".", or there is no base and input started | ||
| // with a ".", then we need to ensure that the relative path starts with a | ||
| // ".". We don't know if relative starts with a "..", though, so check before | ||
| // prepending. | ||
| if ((base || input).startsWith('.') && !relative.startsWith('.')) { | ||
| return './' + relative; | ||
| } | ||
| return relative; | ||
| } | ||
| exports.default = resolve; | ||
| //# sourceMappingURL=resolve-uri.js.map |
| {"version":3,"file":"resolve-uri.js","sourceRoot":"","sources":["../../src/resolve-uri.ts"],"names":[],"mappings":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KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAChE,OAAO,IAAI,GAAG,QAAQ,CAAC;KACxB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAjDD,0BAiDC"} |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
14
-17.65%36964
-23.12%8
-20%300
-32.74%1
Infinity%4
300%