urlpurify 1.4.1 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clean.mjs +2 -3
- package/dist/node_modules/trousse/dist/is.mjs +6 -0
- package/dist/node_modules/trousse/dist/matching.mjs +4 -2
- package/dist/node_modules/trousse/dist/urls.mjs +18 -2
- package/dist/unwraps/adjust.mjs +2 -1
- package/dist/unwraps/anonymTo.mjs +2 -1
- package/dist/unwraps/deviantartOutgoing.mjs +2 -1
- package/dist/unwraps/hrefLi.mjs +2 -1
- package/dist/unwraps/mozillaOutgoing.mjs +4 -5
- package/dist/unwraps/nicoMs.mjs +2 -1
- package/dist/unwraps/postmark.mjs +3 -4
- package/dist/unwraps/proofpointV3.mjs +7 -6
- package/dist/unwraps/webArchive.mjs +3 -4
- package/dist/unwraps/yahooSearch.mjs +3 -4
- package/dist/utils.mjs +5 -6
- package/package.json +3 -3
package/dist/clean.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseUrl } from "./node_modules/trousse/dist/urls.mjs";
|
|
1
|
+
import { parseUrl, stripWww } from "./node_modules/trousse/dist/urls.mjs";
|
|
2
2
|
import { defaultTrackingParams, defaultUnwrappers } from "./defaults.mjs";
|
|
3
3
|
//#region src/clean.ts
|
|
4
4
|
const trackingMatcherCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -28,9 +28,8 @@ const deleteTrackingParams = (url, trackingParams) => {
|
|
|
28
28
|
for (const key of keysToDelete) url.searchParams.delete(key);
|
|
29
29
|
return keysToDelete.length > 0;
|
|
30
30
|
};
|
|
31
|
-
const wwwPrefixRegex = /^www\./;
|
|
32
31
|
const stripHostPrefix = (host) => {
|
|
33
|
-
return host
|
|
32
|
+
return stripWww(host).toLowerCase();
|
|
34
33
|
};
|
|
35
34
|
const deleteSelfReferentialParams = (url) => {
|
|
36
35
|
const value = url.searchParams.get("ref");
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { isNullish } from "./is.mjs";
|
|
1
2
|
//#region node_modules/trousse/dist/matching.js
|
|
2
3
|
const isAnyOf = (value, patterns, parser) => {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
if (isNullish(value)) return false;
|
|
5
|
+
const parsedValue = parser ? parser(value) : value.toLowerCase().trim();
|
|
6
|
+
return (typeof patterns === "string" || patterns instanceof RegExp ? [patterns] : patterns).some((pattern) => {
|
|
5
7
|
if (pattern instanceof RegExp) return pattern.test(parsedValue);
|
|
6
8
|
return parsedValue === pattern.toLowerCase().trim();
|
|
7
9
|
});
|
|
@@ -9,12 +9,28 @@ const parseUrl = (value, base) => {
|
|
|
9
9
|
const isHostOf = (url, hosts) => {
|
|
10
10
|
const hostname = parseUrl(url)?.hostname;
|
|
11
11
|
if (!hostname) return false;
|
|
12
|
-
return isAnyOf(hostname,
|
|
12
|
+
return isAnyOf(hostname, hosts);
|
|
13
13
|
};
|
|
14
14
|
const isSubdomainOf = (url, domains) => {
|
|
15
15
|
const hostname = parseUrl(url)?.hostname;
|
|
16
16
|
if (!hostname) return false;
|
|
17
17
|
return endsWithAnyOf(hostname, (typeof domains === "string" ? [domains] : domains).map((domain) => `.${domain}`));
|
|
18
18
|
};
|
|
19
|
+
const isHostOrSubdomainOf = (url, domains) => {
|
|
20
|
+
return isHostOf(url, domains) || isSubdomainOf(url, domains);
|
|
21
|
+
};
|
|
22
|
+
const decodeSegment = (segment) => {
|
|
23
|
+
if (segment === void 0) return;
|
|
24
|
+
try {
|
|
25
|
+
return decodeURIComponent(segment);
|
|
26
|
+
} catch {}
|
|
27
|
+
};
|
|
28
|
+
const wwwPrefixRegex = /^www\./;
|
|
29
|
+
const schemeSeparator = String.raw`\.*[:\s=\\/][:\s=.\\/]*`;
|
|
30
|
+
new RegExp(String.raw`^\/?[htps]{2,7}${schemeSeparator}([htps]{2,7})${schemeSeparator}[.,:/]*(www[./]+)?`, "i");
|
|
31
|
+
new RegExp(String.raw`^\/?(?:h[htps():]{1,10}|t{1,2}ps?)${schemeSeparator}[.,:/]*(www[./]+)?`, "i");
|
|
32
|
+
const stripWww = (hostname) => {
|
|
33
|
+
return hostname.replace(wwwPrefixRegex, "");
|
|
34
|
+
};
|
|
19
35
|
//#endregion
|
|
20
|
-
export { isHostOf, isSubdomainOf, parseUrl };
|
|
36
|
+
export { decodeSegment, isHostOf, isHostOrSubdomainOf, isSubdomainOf, parseUrl, stripWww };
|
package/dist/unwraps/adjust.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/adjust.ts
|
|
2
3
|
const unwrapAdjust = (url) => {
|
|
3
|
-
if (url
|
|
4
|
+
if (!isHostOf(url, "app.adjust.com")) return;
|
|
4
5
|
const target = url.searchParams.get("redirect");
|
|
5
6
|
if (target?.startsWith("https://") !== true && target?.startsWith("http://") !== true) return;
|
|
6
7
|
return target;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/anonymTo.ts
|
|
2
3
|
const unwrapAnonymTo = (url) => {
|
|
3
|
-
if (url
|
|
4
|
+
if (!isHostOf(url, ["anonym.to", "www.anonym.to"])) return;
|
|
4
5
|
return url.search.slice(1) || void 0;
|
|
5
6
|
};
|
|
6
7
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { isHostOrSubdomainOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/deviantartOutgoing.ts
|
|
2
3
|
const unwrapDeviantartOutgoing = (url) => {
|
|
3
|
-
if (!url
|
|
4
|
+
if (!isHostOrSubdomainOf(url, "deviantart.com") || !url.pathname.endsWith("/outgoing")) return;
|
|
4
5
|
return url.search.slice(1) || void 0;
|
|
5
6
|
};
|
|
6
7
|
//#endregion
|
package/dist/unwraps/hrefLi.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/hrefLi.ts
|
|
2
3
|
const unwrapHrefLi = (url) => {
|
|
3
|
-
if (url
|
|
4
|
+
if (!isHostOf(url, ["href.li", "www.href.li"])) return;
|
|
4
5
|
return url.search.slice(1) || void 0;
|
|
5
6
|
};
|
|
6
7
|
//#endregion
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import { decodeSegment, isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/mozillaOutgoing.ts
|
|
2
3
|
const pathRegex = /^\/v1\/[0-9a-f]{64}\/(.+)$/;
|
|
3
|
-
const mozillaOutgoingHosts =
|
|
4
|
+
const mozillaOutgoingHosts = ["outgoing.prod.mozaws.net", "prod.outgoing.prod.webservices.mozgcp.net"];
|
|
4
5
|
const unwrapMozillaOutgoing = (url) => {
|
|
5
|
-
if (!
|
|
6
|
+
if (!isHostOf(url, mozillaOutgoingHosts)) return;
|
|
6
7
|
const match = url.pathname.match(pathRegex);
|
|
7
8
|
if (!match) return;
|
|
8
|
-
|
|
9
|
-
return decodeURIComponent(match[1]);
|
|
10
|
-
} catch {}
|
|
9
|
+
return decodeSegment(match[1]);
|
|
11
10
|
};
|
|
12
11
|
//#endregion
|
|
13
12
|
export { unwrapMozillaOutgoing };
|
package/dist/unwraps/nicoMs.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/nicoMs.ts
|
|
2
3
|
const nicoMsRegex = /^\/((?:sm|nm|so|im)\w+)$/;
|
|
3
4
|
const unwrapNicoMs = (url) => {
|
|
4
|
-
if (url
|
|
5
|
+
if (!isHostOf(url, "nico.ms")) return;
|
|
5
6
|
const match = url.pathname.match(nicoMsRegex);
|
|
6
7
|
if (!match) return;
|
|
7
8
|
const id = match[1];
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { decodeSegment, isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/postmark.ts
|
|
2
3
|
const postmarkPathRegex = /^\/[23][st]\/([^/]+)\//;
|
|
3
4
|
const unwrapPostmark = (url) => {
|
|
4
|
-
if (url
|
|
5
|
+
if (!isHostOf(url, "click.pstmrk.it")) return;
|
|
5
6
|
const match = url.pathname.match(postmarkPathRegex);
|
|
6
7
|
if (!match) return;
|
|
7
|
-
|
|
8
|
-
return decodeURIComponent(match[1]);
|
|
9
|
-
} catch {}
|
|
8
|
+
return decodeSegment(match[1]);
|
|
10
9
|
};
|
|
11
10
|
//#endregion
|
|
12
11
|
export { unwrapPostmark };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
import { decodeBase64Url, getUtf8ByteLength } from "../utils.mjs";
|
|
2
3
|
//#region src/unwraps/proofpointV3.ts
|
|
3
4
|
const v3PathRegex = /^\/v3\/__(.+)__;([^!]*)!/;
|
|
4
|
-
const
|
|
5
|
+
const v3Hosts = [
|
|
5
6
|
"urldefense.com",
|
|
6
7
|
"urldefense.proofpoint.com",
|
|
7
8
|
"urldefense.us"
|
|
8
|
-
]
|
|
9
|
+
];
|
|
9
10
|
const runLengthMap = (() => {
|
|
10
11
|
const map = {};
|
|
11
12
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
@@ -19,11 +20,11 @@ const decodeReplacements = (mangled, replacementBase64) => {
|
|
|
19
20
|
const replacementChars = Array.from(replacement);
|
|
20
21
|
const urlChars = Array.from(mangled);
|
|
21
22
|
const result = [];
|
|
22
|
-
const
|
|
23
|
+
const markerRegex = /(?<!\*)\*(?!\*)|\*{2}[A-Za-z0-9\-_]/g;
|
|
23
24
|
let lastIndex = 0;
|
|
24
25
|
let savedBytes = 0;
|
|
25
26
|
let match;
|
|
26
|
-
match =
|
|
27
|
+
match = markerRegex.exec(mangled);
|
|
27
28
|
while (match !== null) {
|
|
28
29
|
const startChar = positionInChars(mangled, match.index);
|
|
29
30
|
const endChar = positionInChars(mangled, match.index + match[0].length);
|
|
@@ -53,7 +54,7 @@ const decodeReplacements = (mangled, replacementBase64) => {
|
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
lastIndex = endChar;
|
|
56
|
-
match =
|
|
57
|
+
match = markerRegex.exec(mangled);
|
|
57
58
|
}
|
|
58
59
|
for (let charIndex = lastIndex; charIndex < urlChars.length; charIndex += 1) result.push(urlChars[charIndex]);
|
|
59
60
|
return result.join("");
|
|
@@ -69,7 +70,7 @@ const positionInChars = (source, codeUnitIndex) => {
|
|
|
69
70
|
return charIndex;
|
|
70
71
|
};
|
|
71
72
|
const unwrapProofpointV3 = (url) => {
|
|
72
|
-
if (!
|
|
73
|
+
if (!isHostOf(url, v3Hosts)) return;
|
|
73
74
|
const match = `${url.pathname}${url.search}`.match(v3PathRegex);
|
|
74
75
|
if (!match) return;
|
|
75
76
|
return decodeReplacements(match[1], match[2]);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { decodeSegment, isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/webArchive.ts
|
|
2
3
|
const pathRegex = /^\/web\/\d{14}\*?\/(.+)$/;
|
|
3
4
|
const unwrapWebArchive = (url) => {
|
|
4
|
-
if (url
|
|
5
|
+
if (!isHostOf(url, "web.archive.org")) return;
|
|
5
6
|
const match = url.pathname.match(pathRegex);
|
|
6
7
|
if (!match) return;
|
|
7
|
-
|
|
8
|
-
return decodeURIComponent(match[1]);
|
|
9
|
-
} catch {}
|
|
8
|
+
return decodeSegment(match[1]);
|
|
10
9
|
};
|
|
11
10
|
//#endregion
|
|
12
11
|
export { unwrapWebArchive };
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
import { decodeSegment, isHostOf } from "../node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/unwraps/yahooSearch.ts
|
|
2
3
|
const yahooPathRegex = /\/RU=([^/]+)\/RK=/;
|
|
3
4
|
const unwrapYahooSearch = (url) => {
|
|
4
|
-
if (url
|
|
5
|
+
if (!isHostOf(url, "r.search.yahoo.com")) return;
|
|
5
6
|
const match = url.pathname.match(yahooPathRegex);
|
|
6
7
|
if (!match) return;
|
|
7
|
-
|
|
8
|
-
return decodeURIComponent(match[1]);
|
|
9
|
-
} catch {}
|
|
8
|
+
return decodeSegment(match[1]);
|
|
10
9
|
};
|
|
11
10
|
//#endregion
|
|
12
11
|
export { unwrapYahooSearch };
|
package/dist/utils.mjs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
+
import { isHostOf } from "./node_modules/trousse/dist/urls.mjs";
|
|
1
2
|
//#region src/utils.ts
|
|
2
|
-
const
|
|
3
|
-
if (hosts instanceof RegExp) return
|
|
4
|
-
|
|
5
|
-
return (host) => hostSet.has(host);
|
|
3
|
+
const matchesHost = (url, hosts) => {
|
|
4
|
+
if (hosts instanceof RegExp) return hosts.test(url.hostname);
|
|
5
|
+
return isHostOf(url, hosts);
|
|
6
6
|
};
|
|
7
7
|
const createParamExtractor = (config) => {
|
|
8
|
-
const matchesHost = createHostMatcher(config.hosts);
|
|
9
8
|
return (url) => {
|
|
10
|
-
if (!matchesHost(url.
|
|
9
|
+
if (!matchesHost(url, config.hosts)) return;
|
|
11
10
|
if (config.path && url.pathname !== config.path) return;
|
|
12
11
|
for (const param of config.params) {
|
|
13
12
|
const value = url.searchParams.get(param);
|
package/package.json
CHANGED