urlpurify 1.0.0 → 1.2.0
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/README.md +9 -4
- package/dist/clean.d.ts +2 -2
- package/dist/clean.js +35 -16
- package/dist/defaults.d.ts +5 -3
- package/dist/defaults.js +9 -3
- package/dist/index.d.ts +7 -4
- package/dist/index.js +6 -3
- package/dist/node_modules/trousse/dist/matching.js +17 -0
- package/dist/node_modules/trousse/dist/urls.js +20 -0
- package/dist/tracking/literals.d.ts +4 -0
- package/dist/{params.js → tracking/literals.js} +30 -3
- package/dist/tracking/patterns.d.ts +4 -0
- package/dist/tracking/patterns.js +19 -0
- package/dist/types.d.ts +3 -2
- package/dist/unwraps/ampCache.js +1 -1
- package/dist/unwraps/bsky.d.ts +6 -0
- package/dist/unwraps/bsky.js +9 -0
- package/dist/unwraps/facebook.js +5 -1
- package/dist/unwraps/googleNewsModern.js +2 -1
- package/dist/unwraps/threads.d.ts +6 -0
- package/dist/unwraps/threads.js +8 -0
- package/dist/utils.js +5 -17
- package/package.json +3 -2
- package/dist/params.d.ts +0 -4
package/README.md
CHANGED
|
@@ -35,8 +35,9 @@ import { cleanUrl, defaultUnwrappers, unwrapWebArchive } from 'urlpurify'
|
|
|
35
35
|
const cleaned = cleanUrl(url, {
|
|
36
36
|
// Unwrappers to apply, first match wins per pass (omit to use defaults).
|
|
37
37
|
unwrappers: [...defaultUnwrappers, unwrapWebArchive],
|
|
38
|
-
//
|
|
39
|
-
|
|
38
|
+
// Param names (matched case-insensitively) or anchored regexes tested against the
|
|
39
|
+
// lowercased name (omit to use defaults).
|
|
40
|
+
trackingParams: ['fbclid', /^utm_[a-z0-9_-]+$/],
|
|
40
41
|
// Maximum number of unwrap passes for nested wrappers. Defaults to 3.
|
|
41
42
|
maxUnwrapDepth: 3,
|
|
42
43
|
})
|
|
@@ -50,6 +51,8 @@ Applies the unwrappers in order (one pass) and returns the first extracted targe
|
|
|
50
51
|
|
|
51
52
|
Removes matching query parameters and returns the cleaned URL. The input is returned unchanged when nothing matches or it cannot be parsed.
|
|
52
53
|
|
|
54
|
+
Both `cleanUrl` and `stripTrackingParams` also drop a `ref` parameter when its value is the URL's own host (Ghost's self-referral `?ref=example.com` on `example.com`), regardless of the tracking list passed. With any other value `ref` is left alone, since it is often a real referral target.
|
|
55
|
+
|
|
53
56
|
### `createParamExtractor(config)`
|
|
54
57
|
|
|
55
58
|
Builds an unwrapper for the common case where the target URL sits in a query parameter:
|
|
@@ -69,7 +72,7 @@ For wrappers that encode the target (base64 path segments, custom escaping), wri
|
|
|
69
72
|
|
|
70
73
|
### Defaults
|
|
71
74
|
|
|
72
|
-
`defaultTrackingParams`
|
|
75
|
+
`defaultTrackingParams` is the combined default list for `cleanUrl` and `stripTrackingParams`: literal names plus family regexes like `/^utm_[a-z0-9_-]+$/` that cover vendor namespaces where new variants keep appearing. Its parts are exported separately as `trackingParamsLiterals` (strings only, for consumers that need a plain string list) and `trackingParamsPatterns`. `defaultUnwrappers` is exported alongside. `defaultUnwrappers` enables a conservative subset of the catalog (search-engine redirects and social-platform shims); everything else is exported individually for explicit opt-in.
|
|
73
76
|
|
|
74
77
|
## Unwrappers
|
|
75
78
|
|
|
@@ -78,7 +81,8 @@ Enabled by default:
|
|
|
78
81
|
| Unwrapper | Description |
|
|
79
82
|
| --- | --- |
|
|
80
83
|
| `unwrapBing` | Bing search-result redirect (www.bing.com/ck/a?u=a1\<base64url\>) |
|
|
81
|
-
| `
|
|
84
|
+
| `unwrapBlueskyRedirect` | Bluesky outbound link redirect (go.bsky.app/redirect?u=\<target\>) |
|
|
85
|
+
| `unwrapFacebookShim` | Meta link shim (l.facebook.com / l.messenger.com /l.php?u=\<target\>) |
|
|
82
86
|
| `unwrapGoogle` | Google redirect (google.\<TLD\>/url?url=\<target\> or ?q=\<target\>) |
|
|
83
87
|
| `unwrapGoogleAmpViewer` | Google AMP viewer (www.google.\<TLD\>/amp/s/\<host\>/\<path\>) |
|
|
84
88
|
| `unwrapGoogleNews` | Google News legacy redirect (news.google.\<TLD\>/news/url?url=\<target\>) |
|
|
@@ -86,6 +90,7 @@ Enabled by default:
|
|
|
86
90
|
| `unwrapGoogleScholar` | Google Scholar search-result redirect (scholar.google.\<TLD\>/scholar_url?url=\<target\>) |
|
|
87
91
|
| `unwrapInstagramShim` | Instagram outbound link shim (l.instagram.com with ?u=\<target\>) |
|
|
88
92
|
| `unwrapRedditOut` | Reddit outbound click tracker (out.reddit.com/?url=\<target\>) |
|
|
93
|
+
| `unwrapThreadsShim` | Threads outbound link shim (l.threads.com / l.threads.net with ?u=\<target\>) |
|
|
89
94
|
| `unwrapVkAway` | VK away redirect (vk.com/away.php?to=\<target\>) |
|
|
90
95
|
| `unwrapYahooSearch` | Yahoo Search redirect (r.search.yahoo.com/.../RU=\<target\>/RK=...) |
|
|
91
96
|
| `unwrapYouTube` | YouTube external redirect (www.youtube.com/redirect?q=\<target\>) |
|
package/dist/clean.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CleanUrlOptions, UrlUnwrapper } from "./types.js";
|
|
1
|
+
import { CleanUrlOptions, TrackingParam, UrlUnwrapper } from "./types.js";
|
|
2
2
|
|
|
3
3
|
//#region src/clean.d.ts
|
|
4
4
|
declare const unwrapUrl: (url: string, unwrappers?: Array<UrlUnwrapper>) => string | undefined;
|
|
5
|
-
declare const stripTrackingParams: (url: string, trackingParams?: Array<
|
|
5
|
+
declare const stripTrackingParams: (url: string, trackingParams?: Array<TrackingParam>) => string;
|
|
6
6
|
declare const cleanUrl: (url: string, options?: CleanUrlOptions) => string;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { cleanUrl, stripTrackingParams, unwrapUrl };
|
package/dist/clean.js
CHANGED
|
@@ -1,28 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defaultUnwrappers } from "./defaults.js";
|
|
1
|
+
import { parseUrl } from "./node_modules/trousse/dist/urls.js";
|
|
2
|
+
import { defaultTrackingParams, defaultUnwrappers } from "./defaults.js";
|
|
3
3
|
//#region src/clean.ts
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
let cached =
|
|
4
|
+
const trackingMatcherCache = /* @__PURE__ */ new WeakMap();
|
|
5
|
+
const getTrackingMatcher = (params) => {
|
|
6
|
+
let cached = trackingMatcherCache.get(params);
|
|
7
7
|
if (!cached) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const literals = /* @__PURE__ */ new Set();
|
|
9
|
+
const patterns = [];
|
|
10
|
+
for (const param of params) if (param instanceof RegExp) patterns.push(param);
|
|
11
|
+
else literals.add(param.toLowerCase());
|
|
12
|
+
cached = {
|
|
13
|
+
literals,
|
|
14
|
+
patterns
|
|
15
|
+
};
|
|
16
|
+
trackingMatcherCache.set(params, cached);
|
|
10
17
|
}
|
|
11
18
|
return cached;
|
|
12
19
|
};
|
|
13
|
-
const parseUrl = (url) => {
|
|
14
|
-
try {
|
|
15
|
-
return new URL(url);
|
|
16
|
-
} catch {}
|
|
17
|
-
};
|
|
18
20
|
const deleteTrackingParams = (url, trackingParams) => {
|
|
19
21
|
if (!url.search) return false;
|
|
20
|
-
const
|
|
22
|
+
const matcher = getTrackingMatcher(trackingParams);
|
|
21
23
|
const keysToDelete = [];
|
|
22
|
-
for (const key of url.searchParams.keys())
|
|
24
|
+
for (const key of url.searchParams.keys()) {
|
|
25
|
+
const name = key.toLowerCase();
|
|
26
|
+
if (matcher.literals.has(name) || matcher.patterns.some((pattern) => pattern.test(name))) keysToDelete.push(key);
|
|
27
|
+
}
|
|
23
28
|
for (const key of keysToDelete) url.searchParams.delete(key);
|
|
24
29
|
return keysToDelete.length > 0;
|
|
25
30
|
};
|
|
31
|
+
const wwwPrefixRegex = /^www\./;
|
|
32
|
+
const stripHostPrefix = (host) => {
|
|
33
|
+
return host.replace(wwwPrefixRegex, "").toLowerCase();
|
|
34
|
+
};
|
|
35
|
+
const deleteSelfReferentialParams = (url) => {
|
|
36
|
+
const value = url.searchParams.get("ref");
|
|
37
|
+
if (!value || stripHostPrefix(value) !== stripHostPrefix(url.hostname)) return false;
|
|
38
|
+
url.searchParams.delete("ref");
|
|
39
|
+
return true;
|
|
40
|
+
};
|
|
26
41
|
const applyUnwrappers = (url, unwrappers) => {
|
|
27
42
|
for (const unwrap of unwrappers) {
|
|
28
43
|
const target = unwrap(url);
|
|
@@ -37,7 +52,9 @@ const unwrapUrl = (url, unwrappers = defaultUnwrappers) => {
|
|
|
37
52
|
const stripTrackingParams = (url, trackingParams = defaultTrackingParams) => {
|
|
38
53
|
const parsed = parseUrl(url);
|
|
39
54
|
if (!parsed) return url;
|
|
40
|
-
|
|
55
|
+
const trackingRemoved = deleteTrackingParams(parsed, trackingParams);
|
|
56
|
+
const selfReferentialRemoved = deleteSelfReferentialParams(parsed);
|
|
57
|
+
if (trackingRemoved || selfReferentialRemoved) return parsed.toString();
|
|
41
58
|
return url;
|
|
42
59
|
};
|
|
43
60
|
const cleanUrl = (url, options) => {
|
|
@@ -56,7 +73,9 @@ const cleanUrl = (url, options) => {
|
|
|
56
73
|
currentUrl = target;
|
|
57
74
|
currentParsed = targetParsed;
|
|
58
75
|
}
|
|
59
|
-
|
|
76
|
+
const trackingRemoved = deleteTrackingParams(currentParsed, trackingParams);
|
|
77
|
+
const selfReferentialRemoved = deleteSelfReferentialParams(currentParsed);
|
|
78
|
+
if (trackingRemoved || selfReferentialRemoved) return currentParsed.toString();
|
|
60
79
|
return currentUrl;
|
|
61
80
|
};
|
|
62
81
|
//#endregion
|
package/dist/defaults.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { UrlUnwrapper } from "./types.js";
|
|
2
|
-
import {
|
|
1
|
+
import { TrackingParam, UrlUnwrapper } from "./types.js";
|
|
2
|
+
import { trackingParamsLiterals } from "./tracking/literals.js";
|
|
3
|
+
import { trackingParamsPatterns } from "./tracking/patterns.js";
|
|
3
4
|
|
|
4
5
|
//#region src/defaults.d.ts
|
|
6
|
+
declare const defaultTrackingParams: Array<TrackingParam>;
|
|
5
7
|
declare const defaultUnwrappers: Array<UrlUnwrapper>;
|
|
6
8
|
//#endregion
|
|
7
|
-
export { defaultUnwrappers };
|
|
9
|
+
export { defaultTrackingParams, defaultUnwrappers };
|
package/dist/defaults.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { unwrapBing } from "./unwraps/bing.js";
|
|
2
|
+
import { unwrapBlueskyRedirect } from "./unwraps/bsky.js";
|
|
2
3
|
import { unwrapFacebookShim } from "./unwraps/facebook.js";
|
|
3
4
|
import { unwrapGoogle } from "./unwraps/google.js";
|
|
4
5
|
import { unwrapGoogleAmpViewer } from "./unwraps/googleAmpViewer.js";
|
|
@@ -7,11 +8,14 @@ import { unwrapGoogleNewsModern } from "./unwraps/googleNewsModern.js";
|
|
|
7
8
|
import { unwrapGoogleScholar } from "./unwraps/googleScholar.js";
|
|
8
9
|
import { unwrapInstagramShim } from "./unwraps/instagram.js";
|
|
9
10
|
import { unwrapRedditOut } from "./unwraps/redditOut.js";
|
|
11
|
+
import { unwrapThreadsShim } from "./unwraps/threads.js";
|
|
10
12
|
import { unwrapVkAway } from "./unwraps/vkAway.js";
|
|
11
13
|
import { unwrapYahooSearch } from "./unwraps/yahooSearch.js";
|
|
12
14
|
import { unwrapYouTube } from "./unwraps/youtube.js";
|
|
13
|
-
import "./
|
|
15
|
+
import { trackingParamsLiterals } from "./tracking/literals.js";
|
|
16
|
+
import { trackingParamsPatterns } from "./tracking/patterns.js";
|
|
14
17
|
//#region src/defaults.ts
|
|
18
|
+
const defaultTrackingParams = [...trackingParamsLiterals, ...trackingParamsPatterns];
|
|
15
19
|
const defaultUnwrappers = [
|
|
16
20
|
unwrapBing,
|
|
17
21
|
unwrapGoogle,
|
|
@@ -23,8 +27,10 @@ const defaultUnwrappers = [
|
|
|
23
27
|
unwrapYouTube,
|
|
24
28
|
unwrapFacebookShim,
|
|
25
29
|
unwrapInstagramShim,
|
|
30
|
+
unwrapThreadsShim,
|
|
26
31
|
unwrapVkAway,
|
|
27
|
-
unwrapRedditOut
|
|
32
|
+
unwrapRedditOut,
|
|
33
|
+
unwrapBlueskyRedirect
|
|
28
34
|
];
|
|
29
35
|
//#endregion
|
|
30
|
-
export { defaultUnwrappers };
|
|
36
|
+
export { defaultTrackingParams, defaultUnwrappers };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { CleanUrlOptions, UrlUnwrapper } from "./types.js";
|
|
1
|
+
import { CleanUrlOptions, TrackingParam, UrlUnwrapper } from "./types.js";
|
|
2
2
|
import { cleanUrl, stripTrackingParams, unwrapUrl } from "./clean.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { trackingParamsLiterals } from "./tracking/literals.js";
|
|
4
|
+
import { trackingParamsPatterns } from "./tracking/patterns.js";
|
|
5
|
+
import { defaultTrackingParams, defaultUnwrappers } from "./defaults.js";
|
|
5
6
|
import { unwrapAceml } from "./unwraps/aceml.js";
|
|
6
7
|
import { unwrapAdjust } from "./unwraps/adjust.js";
|
|
7
8
|
import { unwrapAmazonAffiliate } from "./unwraps/amazonAffiliate.js";
|
|
8
9
|
import { unwrapAmpCache } from "./unwraps/ampCache.js";
|
|
9
10
|
import { unwrapAwin } from "./unwraps/awin.js";
|
|
10
11
|
import { unwrapBing } from "./unwraps/bing.js";
|
|
12
|
+
import { unwrapBlueskyRedirect } from "./unwraps/bsky.js";
|
|
11
13
|
import { unwrapCjNetwork } from "./unwraps/cjNetwork.js";
|
|
12
14
|
import { unwrapDigidip } from "./unwraps/digidip.js";
|
|
13
15
|
import { unwrapDisqus } from "./unwraps/disqus.js";
|
|
@@ -66,6 +68,7 @@ import { unwrapSmartredirect } from "./unwraps/smartredirect.js";
|
|
|
66
68
|
import { unwrapSspai } from "./unwraps/sspai.js";
|
|
67
69
|
import { unwrapSteamLinkfilter } from "./unwraps/steamLinkfilter.js";
|
|
68
70
|
import { unwrapTelegramIv } from "./unwraps/telegramIv.js";
|
|
71
|
+
import { unwrapThreadsShim } from "./unwraps/threads.js";
|
|
69
72
|
import { unwrapTradedoubler } from "./unwraps/tradedoubler.js";
|
|
70
73
|
import { unwrapTumblr } from "./unwraps/tumblr.js";
|
|
71
74
|
import { unwrapValuecommerce } from "./unwraps/valuecommerce.js";
|
|
@@ -77,4 +80,4 @@ import { unwrapYandexTurbo } from "./unwraps/yandexTurbo.js";
|
|
|
77
80
|
import { unwrapYouTube } from "./unwraps/youtube.js";
|
|
78
81
|
import { unwrapZhihu } from "./unwraps/zhihu.js";
|
|
79
82
|
import { ParamExtractorConfig, createParamExtractor } from "./utils.js";
|
|
80
|
-
export { type CleanUrlOptions, type ParamExtractorConfig, type UrlUnwrapper, cleanUrl, createParamExtractor, defaultTrackingParams, defaultUnwrappers, stripTrackingParams, unwrapAceml, unwrapAdjust, unwrapAmazonAffiliate, unwrapAmpCache, unwrapAwin, unwrapBing, unwrapCjNetwork, unwrapDigidip, unwrapDisqus, unwrapDouban, unwrapDuckduckgo, unwrapEbayRover, unwrapEffiliation, unwrapEmbedly, unwrapFacebookShim, unwrapFeedsportal, unwrapFirebaseDynamicLinks, unwrapFlipboard, unwrapGateSc, unwrapGeoriot, unwrapGitee, unwrapGoogle, unwrapGoogleAmpViewer, unwrapGoogleNews, unwrapGoogleNewsModern, unwrapGoogleScholar, unwrapGoogleTranslate, unwrapHashnode, unwrapIcptrack, unwrapIdealoPartner, unwrapInstagramShim, unwrapJianshuGo, unwrapJuejin, unwrapLeverAnalytics, unwrapLinksynergy, unwrapMailchimp, unwrapMailpanion, unwrapMailpgn, unwrapMailtrack, unwrapMedium, unwrapMimecast, unwrapMozillaOutgoing, unwrapNarrativ, unwrapNicoMs, unwrapOutlookSafelinks, unwrapPartnerAds, unwrapPocket, unwrapPostmark, unwrapProofpointV1, unwrapProofpointV2, unwrapProofpointV3, unwrapPxf, unwrapRecruitics, unwrapRedditOut, unwrapRedirectingat, unwrapSegmentfault, unwrapShareasale, unwrapSjv, unwrapSkimlinks, unwrapSlack, unwrapSmartredirect, unwrapSspai, unwrapSteamLinkfilter, unwrapTelegramIv, unwrapTradedoubler, unwrapTumblr, unwrapUrl, unwrapValuecommerce, unwrapViglink, unwrapVkAway, unwrapWebArchive, unwrapYahooSearch, unwrapYandexTurbo, unwrapYouTube, unwrapZhihu };
|
|
83
|
+
export { type CleanUrlOptions, type ParamExtractorConfig, type TrackingParam, type UrlUnwrapper, cleanUrl, createParamExtractor, defaultTrackingParams, defaultUnwrappers, stripTrackingParams, trackingParamsLiterals, trackingParamsPatterns, unwrapAceml, unwrapAdjust, unwrapAmazonAffiliate, unwrapAmpCache, unwrapAwin, unwrapBing, unwrapBlueskyRedirect, unwrapCjNetwork, unwrapDigidip, unwrapDisqus, unwrapDouban, unwrapDuckduckgo, unwrapEbayRover, unwrapEffiliation, unwrapEmbedly, unwrapFacebookShim, unwrapFeedsportal, unwrapFirebaseDynamicLinks, unwrapFlipboard, unwrapGateSc, unwrapGeoriot, unwrapGitee, unwrapGoogle, unwrapGoogleAmpViewer, unwrapGoogleNews, unwrapGoogleNewsModern, unwrapGoogleScholar, unwrapGoogleTranslate, unwrapHashnode, unwrapIcptrack, unwrapIdealoPartner, unwrapInstagramShim, unwrapJianshuGo, unwrapJuejin, unwrapLeverAnalytics, unwrapLinksynergy, unwrapMailchimp, unwrapMailpanion, unwrapMailpgn, unwrapMailtrack, unwrapMedium, unwrapMimecast, unwrapMozillaOutgoing, unwrapNarrativ, unwrapNicoMs, unwrapOutlookSafelinks, unwrapPartnerAds, unwrapPocket, unwrapPostmark, unwrapProofpointV1, unwrapProofpointV2, unwrapProofpointV3, unwrapPxf, unwrapRecruitics, unwrapRedditOut, unwrapRedirectingat, unwrapSegmentfault, unwrapShareasale, unwrapSjv, unwrapSkimlinks, unwrapSlack, unwrapSmartredirect, unwrapSspai, unwrapSteamLinkfilter, unwrapTelegramIv, unwrapThreadsShim, unwrapTradedoubler, unwrapTumblr, unwrapUrl, unwrapValuecommerce, unwrapViglink, unwrapVkAway, unwrapWebArchive, unwrapYahooSearch, unwrapYandexTurbo, unwrapYouTube, unwrapZhihu };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createParamExtractor } from "./utils.js";
|
|
2
2
|
import { unwrapBing } from "./unwraps/bing.js";
|
|
3
|
+
import { unwrapBlueskyRedirect } from "./unwraps/bsky.js";
|
|
3
4
|
import { unwrapFacebookShim } from "./unwraps/facebook.js";
|
|
4
5
|
import { unwrapGoogle } from "./unwraps/google.js";
|
|
5
6
|
import { unwrapGoogleAmpViewer } from "./unwraps/googleAmpViewer.js";
|
|
@@ -8,11 +9,13 @@ import { unwrapGoogleNewsModern } from "./unwraps/googleNewsModern.js";
|
|
|
8
9
|
import { unwrapGoogleScholar } from "./unwraps/googleScholar.js";
|
|
9
10
|
import { unwrapInstagramShim } from "./unwraps/instagram.js";
|
|
10
11
|
import { unwrapRedditOut } from "./unwraps/redditOut.js";
|
|
12
|
+
import { unwrapThreadsShim } from "./unwraps/threads.js";
|
|
11
13
|
import { unwrapVkAway } from "./unwraps/vkAway.js";
|
|
12
14
|
import { unwrapYahooSearch } from "./unwraps/yahooSearch.js";
|
|
13
15
|
import { unwrapYouTube } from "./unwraps/youtube.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
+
import { trackingParamsLiterals } from "./tracking/literals.js";
|
|
17
|
+
import { trackingParamsPatterns } from "./tracking/patterns.js";
|
|
18
|
+
import { defaultTrackingParams, defaultUnwrappers } from "./defaults.js";
|
|
16
19
|
import { cleanUrl, stripTrackingParams, unwrapUrl } from "./clean.js";
|
|
17
20
|
import { unwrapAceml } from "./unwraps/aceml.js";
|
|
18
21
|
import { unwrapAdjust } from "./unwraps/adjust.js";
|
|
@@ -76,4 +79,4 @@ import { unwrapViglink } from "./unwraps/viglink.js";
|
|
|
76
79
|
import { unwrapWebArchive } from "./unwraps/webArchive.js";
|
|
77
80
|
import { unwrapYandexTurbo } from "./unwraps/yandexTurbo.js";
|
|
78
81
|
import { unwrapZhihu } from "./unwraps/zhihu.js";
|
|
79
|
-
export { cleanUrl, createParamExtractor, defaultTrackingParams, defaultUnwrappers, stripTrackingParams, unwrapAceml, unwrapAdjust, unwrapAmazonAffiliate, unwrapAmpCache, unwrapAwin, unwrapBing, unwrapCjNetwork, unwrapDigidip, unwrapDisqus, unwrapDouban, unwrapDuckduckgo, unwrapEbayRover, unwrapEffiliation, unwrapEmbedly, unwrapFacebookShim, unwrapFeedsportal, unwrapFirebaseDynamicLinks, unwrapFlipboard, unwrapGateSc, unwrapGeoriot, unwrapGitee, unwrapGoogle, unwrapGoogleAmpViewer, unwrapGoogleNews, unwrapGoogleNewsModern, unwrapGoogleScholar, unwrapGoogleTranslate, unwrapHashnode, unwrapIcptrack, unwrapIdealoPartner, unwrapInstagramShim, unwrapJianshuGo, unwrapJuejin, unwrapLeverAnalytics, unwrapLinksynergy, unwrapMailchimp, unwrapMailpanion, unwrapMailpgn, unwrapMailtrack, unwrapMedium, unwrapMimecast, unwrapMozillaOutgoing, unwrapNarrativ, unwrapNicoMs, unwrapOutlookSafelinks, unwrapPartnerAds, unwrapPocket, unwrapPostmark, unwrapProofpointV1, unwrapProofpointV2, unwrapProofpointV3, unwrapPxf, unwrapRecruitics, unwrapRedditOut, unwrapRedirectingat, unwrapSegmentfault, unwrapShareasale, unwrapSjv, unwrapSkimlinks, unwrapSlack, unwrapSmartredirect, unwrapSspai, unwrapSteamLinkfilter, unwrapTelegramIv, unwrapTradedoubler, unwrapTumblr, unwrapUrl, unwrapValuecommerce, unwrapViglink, unwrapVkAway, unwrapWebArchive, unwrapYahooSearch, unwrapYandexTurbo, unwrapYouTube, unwrapZhihu };
|
|
82
|
+
export { cleanUrl, createParamExtractor, defaultTrackingParams, defaultUnwrappers, stripTrackingParams, trackingParamsLiterals, trackingParamsPatterns, unwrapAceml, unwrapAdjust, unwrapAmazonAffiliate, unwrapAmpCache, unwrapAwin, unwrapBing, unwrapBlueskyRedirect, unwrapCjNetwork, unwrapDigidip, unwrapDisqus, unwrapDouban, unwrapDuckduckgo, unwrapEbayRover, unwrapEffiliation, unwrapEmbedly, unwrapFacebookShim, unwrapFeedsportal, unwrapFirebaseDynamicLinks, unwrapFlipboard, unwrapGateSc, unwrapGeoriot, unwrapGitee, unwrapGoogle, unwrapGoogleAmpViewer, unwrapGoogleNews, unwrapGoogleNewsModern, unwrapGoogleScholar, unwrapGoogleTranslate, unwrapHashnode, unwrapIcptrack, unwrapIdealoPartner, unwrapInstagramShim, unwrapJianshuGo, unwrapJuejin, unwrapLeverAnalytics, unwrapLinksynergy, unwrapMailchimp, unwrapMailpanion, unwrapMailpgn, unwrapMailtrack, unwrapMedium, unwrapMimecast, unwrapMozillaOutgoing, unwrapNarrativ, unwrapNicoMs, unwrapOutlookSafelinks, unwrapPartnerAds, unwrapPocket, unwrapPostmark, unwrapProofpointV1, unwrapProofpointV2, unwrapProofpointV3, unwrapPxf, unwrapRecruitics, unwrapRedditOut, unwrapRedirectingat, unwrapSegmentfault, unwrapShareasale, unwrapSjv, unwrapSkimlinks, unwrapSlack, unwrapSmartredirect, unwrapSspai, unwrapSteamLinkfilter, unwrapTelegramIv, unwrapThreadsShim, unwrapTradedoubler, unwrapTumblr, unwrapUrl, unwrapValuecommerce, unwrapViglink, unwrapVkAway, unwrapWebArchive, unwrapYahooSearch, unwrapYandexTurbo, unwrapYouTube, unwrapZhihu };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region node_modules/trousse/dist/matching.js
|
|
2
|
+
const isAnyOf = (value, patterns, parser) => {
|
|
3
|
+
const parsedValue = parser ? parser(value) : value?.toLowerCase()?.trim();
|
|
4
|
+
return patterns.some((pattern) => {
|
|
5
|
+
if (pattern instanceof RegExp) return pattern.test(parsedValue);
|
|
6
|
+
return parsedValue === pattern.toLowerCase().trim();
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
const endsWithAnyOf = (value, patterns) => {
|
|
10
|
+
const lowerValue = value.toLowerCase();
|
|
11
|
+
return patterns.some((pattern) => {
|
|
12
|
+
if (pattern instanceof RegExp) return pattern.test(lowerValue);
|
|
13
|
+
return pattern && lowerValue.endsWith(pattern.toLowerCase());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { endsWithAnyOf, isAnyOf };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { endsWithAnyOf, isAnyOf } from "./matching.js";
|
|
2
|
+
//#region node_modules/trousse/dist/urls.js
|
|
3
|
+
const parseUrl = (value, base) => {
|
|
4
|
+
if (value instanceof URL && base === void 0) return value;
|
|
5
|
+
try {
|
|
6
|
+
return new URL(value, base);
|
|
7
|
+
} catch {}
|
|
8
|
+
};
|
|
9
|
+
const isHostOf = (url, hosts) => {
|
|
10
|
+
const hostname = parseUrl(url)?.hostname;
|
|
11
|
+
if (!hostname) return false;
|
|
12
|
+
return isAnyOf(hostname, Array.isArray(hosts) ? hosts : [hosts]);
|
|
13
|
+
};
|
|
14
|
+
const isSubdomainOf = (url, domains) => {
|
|
15
|
+
const hostname = parseUrl(url)?.hostname;
|
|
16
|
+
if (!hostname) return false;
|
|
17
|
+
return endsWithAnyOf(hostname, (Array.isArray(domains) ? domains : [domains]).map((domain) => `.${domain}`));
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isHostOf, isSubdomainOf, parseUrl };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//#region src/
|
|
2
|
-
const
|
|
1
|
+
//#region src/tracking/literals.ts
|
|
2
|
+
const trackingParamsLiterals = [
|
|
3
3
|
"utm_source",
|
|
4
4
|
"utm_medium",
|
|
5
5
|
"utm_campaign",
|
|
@@ -17,23 +17,29 @@ const defaultTrackingParams = [
|
|
|
17
17
|
"gad_source",
|
|
18
18
|
"gad_campaignid",
|
|
19
19
|
"srsltid",
|
|
20
|
+
"usqp",
|
|
20
21
|
"fbclid",
|
|
21
22
|
"fb_action_ids",
|
|
22
23
|
"fb_action_types",
|
|
23
24
|
"fb_source",
|
|
24
25
|
"fb_ref",
|
|
26
|
+
"mibextid",
|
|
25
27
|
"_ga",
|
|
26
28
|
"_gl",
|
|
27
29
|
"_bk",
|
|
28
30
|
"_ke",
|
|
31
|
+
"_kx",
|
|
32
|
+
"__s",
|
|
29
33
|
"mc_cid",
|
|
30
34
|
"mc_eid",
|
|
31
35
|
"mc_tc",
|
|
32
36
|
"mkt_tok",
|
|
33
37
|
"msclkid",
|
|
34
38
|
"twclid",
|
|
39
|
+
"__twitter_impression",
|
|
35
40
|
"ttclid",
|
|
36
41
|
"igshid",
|
|
42
|
+
"igsh",
|
|
37
43
|
"mtm_campaign",
|
|
38
44
|
"mtm_cid",
|
|
39
45
|
"mtm_content",
|
|
@@ -50,6 +56,7 @@ const defaultTrackingParams = [
|
|
|
50
56
|
"pk_source",
|
|
51
57
|
"ncid",
|
|
52
58
|
"sr_share",
|
|
59
|
+
"cmpid",
|
|
53
60
|
"hsa_acc",
|
|
54
61
|
"hsa_ad",
|
|
55
62
|
"hsa_cam",
|
|
@@ -70,15 +77,34 @@ const defaultTrackingParams = [
|
|
|
70
77
|
"s_kwcid",
|
|
71
78
|
"sc_cid",
|
|
72
79
|
"ef_id",
|
|
80
|
+
"s_cid",
|
|
81
|
+
"wt_mc",
|
|
82
|
+
"wt_zmc",
|
|
83
|
+
"wtrid",
|
|
84
|
+
"cx_click",
|
|
85
|
+
"cx_recsOrder",
|
|
86
|
+
"cx_recsWidget",
|
|
73
87
|
"obOrigUrl",
|
|
74
88
|
"dicbo",
|
|
75
89
|
"yclid",
|
|
76
90
|
"ysclid",
|
|
77
91
|
"_openstat",
|
|
92
|
+
"guccounter",
|
|
93
|
+
"guce_referrer",
|
|
94
|
+
"guce_referrer_sig",
|
|
78
95
|
"awinaffid",
|
|
79
96
|
"awinmid",
|
|
80
97
|
"clickref",
|
|
81
98
|
"afftrack",
|
|
99
|
+
"sscid",
|
|
100
|
+
"awc",
|
|
101
|
+
"cjevent",
|
|
102
|
+
"cjdata",
|
|
103
|
+
"irclickid",
|
|
104
|
+
"irgwc",
|
|
105
|
+
"ir_adid",
|
|
106
|
+
"ir_campaignid",
|
|
107
|
+
"ir_partnerid",
|
|
82
108
|
"itm_source",
|
|
83
109
|
"itm_medium",
|
|
84
110
|
"itm_campaign",
|
|
@@ -150,8 +176,9 @@ const defaultTrackingParams = [
|
|
|
150
176
|
"trk",
|
|
151
177
|
"vero_conv",
|
|
152
178
|
"vero_id",
|
|
179
|
+
"vgo_ee",
|
|
153
180
|
"wickedid",
|
|
154
181
|
"xtor"
|
|
155
182
|
];
|
|
156
183
|
//#endregion
|
|
157
|
-
export {
|
|
184
|
+
export { trackingParamsLiterals };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/tracking/patterns.ts
|
|
2
|
+
const trackingParamsPatterns = [
|
|
3
|
+
/^utm_[a-z0-9_-]+$/,
|
|
4
|
+
/^stm_[a-z0-9_-]+$/,
|
|
5
|
+
/^hsa_[a-z0-9_]+$/,
|
|
6
|
+
/^mtm_[a-z0-9_]+$/,
|
|
7
|
+
/^pk_[a-z0-9_]+$/,
|
|
8
|
+
/^piwik_[a-z0-9_]+$/,
|
|
9
|
+
/^itm_[a-z0-9_]+$/,
|
|
10
|
+
/^int_[a-z0-9_]+$/,
|
|
11
|
+
/^at_[a-z0-9_]+$/,
|
|
12
|
+
/^g2i_[a-z0-9_]+$/,
|
|
13
|
+
/^bsft_[a-z0-9_]+$/,
|
|
14
|
+
/^sfmc_[a-z0-9_]+$/,
|
|
15
|
+
/^oft_[a-z0-9_]+$/,
|
|
16
|
+
/^cm_mmca?\d*$/
|
|
17
|
+
];
|
|
18
|
+
//#endregion
|
|
19
|
+
export { trackingParamsPatterns };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
2
|
type UrlUnwrapper = (url: URL) => string | undefined;
|
|
3
|
+
type TrackingParam = string | RegExp;
|
|
3
4
|
type CleanUrlOptions = {
|
|
4
5
|
unwrappers?: Array<UrlUnwrapper>;
|
|
5
|
-
trackingParams?: Array<
|
|
6
|
+
trackingParams?: Array<TrackingParam>;
|
|
6
7
|
maxUnwrapDepth?: number;
|
|
7
8
|
};
|
|
8
9
|
//#endregion
|
|
9
|
-
export { CleanUrlOptions, UrlUnwrapper };
|
|
10
|
+
export { CleanUrlOptions, TrackingParam, UrlUnwrapper };
|
package/dist/unwraps/ampCache.js
CHANGED
package/dist/unwraps/facebook.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { createParamExtractor } from "../utils.js";
|
|
2
2
|
//#region src/unwraps/facebook.ts
|
|
3
3
|
const unwrapFacebookShim = createParamExtractor({
|
|
4
|
-
hosts: [
|
|
4
|
+
hosts: [
|
|
5
|
+
"l.facebook.com",
|
|
6
|
+
"lm.facebook.com",
|
|
7
|
+
"l.messenger.com"
|
|
8
|
+
],
|
|
5
9
|
path: "/l.php",
|
|
6
10
|
params: ["u"]
|
|
7
11
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isHostOf } from "../node_modules/trousse/dist/urls.js";
|
|
2
|
+
import { decodeBase64Binary } from "../utils.js";
|
|
2
3
|
//#region src/unwraps/googleNewsModern.ts
|
|
3
4
|
const articleIdRegex = /^\/(?:rss\/)?articles\/([\w-]+)/;
|
|
4
5
|
const base64UrlMinusRegex = /-/g;
|
package/dist/utils.js
CHANGED
|
@@ -15,30 +15,18 @@ const createParamExtractor = (config) => {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
const isHostOf = (url, hosts) => {
|
|
19
|
-
try {
|
|
20
|
-
const hostname = (url instanceof URL ? url : new URL(url)).hostname.toLowerCase();
|
|
21
|
-
return (Array.isArray(hosts) ? hosts : [hosts]).some((host) => hostname === host.toLowerCase().trim());
|
|
22
|
-
} catch {}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
const isSubdomainOf = (url, domains) => {
|
|
26
|
-
try {
|
|
27
|
-
const hostname = (url instanceof URL ? url : new URL(url)).hostname.toLowerCase();
|
|
28
|
-
return (Array.isArray(domains) ? domains : [domains]).some((domain) => hostname.endsWith(`.${domain}`));
|
|
29
|
-
} catch {}
|
|
30
|
-
return false;
|
|
31
|
-
};
|
|
32
18
|
const decodeBase64Binary = (value) => {
|
|
33
19
|
try {
|
|
34
20
|
return atob(value);
|
|
35
21
|
} catch {}
|
|
36
22
|
};
|
|
23
|
+
const utf8Decoder = new TextDecoder();
|
|
37
24
|
const decodeBase64 = (value) => {
|
|
38
25
|
const binary = decodeBase64Binary(value);
|
|
39
26
|
if (binary === void 0) return;
|
|
40
|
-
const bytes = Uint8Array
|
|
41
|
-
|
|
27
|
+
const bytes = new Uint8Array(binary.length);
|
|
28
|
+
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
|
29
|
+
return utf8Decoder.decode(bytes);
|
|
42
30
|
};
|
|
43
31
|
const decodeBase64Url = (value) => {
|
|
44
32
|
return decodeBase64(value.replace(/-/g, "+").replace(/_/g, "/"));
|
|
@@ -47,4 +35,4 @@ const getUtf8ByteLength = (value) => {
|
|
|
47
35
|
return new TextEncoder().encode(value).length;
|
|
48
36
|
};
|
|
49
37
|
//#endregion
|
|
50
|
-
export { createParamExtractor, decodeBase64, decodeBase64Binary, decodeBase64Url, getUtf8ByteLength
|
|
38
|
+
export { createParamExtractor, decodeBase64, decodeBase64Binary, decodeBase64Url, getUtf8ByteLength };
|
package/package.json
CHANGED
package/dist/params.d.ts
DELETED