urlpurify 1.1.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 CHANGED
@@ -51,6 +51,8 @@ Applies the unwrappers in order (one pass) and returns the first extracted targe
51
51
 
52
52
  Removes matching query parameters and returns the cleaned URL. The input is returned unchanged when nothing matches or it cannot be parsed.
53
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
+
54
56
  ### `createParamExtractor(config)`
55
57
 
56
58
  Builds an unwrapper for the common case where the target URL sits in a query parameter:
@@ -79,7 +81,8 @@ Enabled by default:
79
81
  | Unwrapper | Description |
80
82
  | --- | --- |
81
83
  | `unwrapBing` | Bing search-result redirect (www.bing.com/ck/a?u=a1\<base64url\>) |
82
- | `unwrapFacebookShim` | Facebook link shim (l.facebook.com/l.php?u=\<target\>) |
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\>) |
83
86
  | `unwrapGoogle` | Google redirect (google.\<TLD\>/url?url=\<target\> or ?q=\<target\>) |
84
87
  | `unwrapGoogleAmpViewer` | Google AMP viewer (www.google.\<TLD\>/amp/s/\<host\>/\<path\>) |
85
88
  | `unwrapGoogleNews` | Google News legacy redirect (news.google.\<TLD\>/news/url?url=\<target\>) |
@@ -87,6 +90,7 @@ Enabled by default:
87
90
  | `unwrapGoogleScholar` | Google Scholar search-result redirect (scholar.google.\<TLD\>/scholar_url?url=\<target\>) |
88
91
  | `unwrapInstagramShim` | Instagram outbound link shim (l.instagram.com with ?u=\<target\>) |
89
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\>) |
90
94
  | `unwrapVkAway` | VK away redirect (vk.com/away.php?to=\<target\>) |
91
95
  | `unwrapYahooSearch` | Yahoo Search redirect (r.search.yahoo.com/.../RU=\<target\>/RK=...) |
92
96
  | `unwrapYouTube` | YouTube external redirect (www.youtube.com/redirect?q=\<target\>) |
package/dist/clean.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { parseUrl } from "./node_modules/trousse/dist/urls.js";
1
2
  import { defaultTrackingParams, defaultUnwrappers } from "./defaults.js";
2
3
  //#region src/clean.ts
3
4
  const trackingMatcherCache = /* @__PURE__ */ new WeakMap();
@@ -16,11 +17,6 @@ const getTrackingMatcher = (params) => {
16
17
  }
17
18
  return cached;
18
19
  };
19
- const parseUrl = (url) => {
20
- try {
21
- return new URL(url);
22
- } catch {}
23
- };
24
20
  const deleteTrackingParams = (url, trackingParams) => {
25
21
  if (!url.search) return false;
26
22
  const matcher = getTrackingMatcher(trackingParams);
@@ -32,6 +28,16 @@ const deleteTrackingParams = (url, trackingParams) => {
32
28
  for (const key of keysToDelete) url.searchParams.delete(key);
33
29
  return keysToDelete.length > 0;
34
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
+ };
35
41
  const applyUnwrappers = (url, unwrappers) => {
36
42
  for (const unwrap of unwrappers) {
37
43
  const target = unwrap(url);
@@ -46,7 +52,9 @@ const unwrapUrl = (url, unwrappers = defaultUnwrappers) => {
46
52
  const stripTrackingParams = (url, trackingParams = defaultTrackingParams) => {
47
53
  const parsed = parseUrl(url);
48
54
  if (!parsed) return url;
49
- if (deleteTrackingParams(parsed, trackingParams)) return parsed.toString();
55
+ const trackingRemoved = deleteTrackingParams(parsed, trackingParams);
56
+ const selfReferentialRemoved = deleteSelfReferentialParams(parsed);
57
+ if (trackingRemoved || selfReferentialRemoved) return parsed.toString();
50
58
  return url;
51
59
  };
52
60
  const cleanUrl = (url, options) => {
@@ -65,7 +73,9 @@ const cleanUrl = (url, options) => {
65
73
  currentUrl = target;
66
74
  currentParsed = targetParsed;
67
75
  }
68
- if (deleteTrackingParams(currentParsed, trackingParams)) return currentParsed.toString();
76
+ const trackingRemoved = deleteTrackingParams(currentParsed, trackingParams);
77
+ const selfReferentialRemoved = deleteSelfReferentialParams(currentParsed);
78
+ if (trackingRemoved || selfReferentialRemoved) return currentParsed.toString();
69
79
  return currentUrl;
70
80
  };
71
81
  //#endregion
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,6 +8,7 @@ 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";
@@ -25,8 +27,10 @@ const defaultUnwrappers = [
25
27
  unwrapYouTube,
26
28
  unwrapFacebookShim,
27
29
  unwrapInstagramShim,
30
+ unwrapThreadsShim,
28
31
  unwrapVkAway,
29
- unwrapRedditOut
32
+ unwrapRedditOut,
33
+ unwrapBlueskyRedirect
30
34
  ];
31
35
  //#endregion
32
36
  export { defaultTrackingParams, defaultUnwrappers };
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ import { unwrapAmazonAffiliate } from "./unwraps/amazonAffiliate.js";
9
9
  import { unwrapAmpCache } from "./unwraps/ampCache.js";
10
10
  import { unwrapAwin } from "./unwraps/awin.js";
11
11
  import { unwrapBing } from "./unwraps/bing.js";
12
+ import { unwrapBlueskyRedirect } from "./unwraps/bsky.js";
12
13
  import { unwrapCjNetwork } from "./unwraps/cjNetwork.js";
13
14
  import { unwrapDigidip } from "./unwraps/digidip.js";
14
15
  import { unwrapDisqus } from "./unwraps/disqus.js";
@@ -67,6 +68,7 @@ import { unwrapSmartredirect } from "./unwraps/smartredirect.js";
67
68
  import { unwrapSspai } from "./unwraps/sspai.js";
68
69
  import { unwrapSteamLinkfilter } from "./unwraps/steamLinkfilter.js";
69
70
  import { unwrapTelegramIv } from "./unwraps/telegramIv.js";
71
+ import { unwrapThreadsShim } from "./unwraps/threads.js";
70
72
  import { unwrapTradedoubler } from "./unwraps/tradedoubler.js";
71
73
  import { unwrapTumblr } from "./unwraps/tumblr.js";
72
74
  import { unwrapValuecommerce } from "./unwraps/valuecommerce.js";
@@ -78,4 +80,4 @@ import { unwrapYandexTurbo } from "./unwraps/yandexTurbo.js";
78
80
  import { unwrapYouTube } from "./unwraps/youtube.js";
79
81
  import { unwrapZhihu } from "./unwraps/zhihu.js";
80
82
  import { ParamExtractorConfig, createParamExtractor } from "./utils.js";
81
- export { type CleanUrlOptions, type ParamExtractorConfig, type TrackingParam, type UrlUnwrapper, cleanUrl, createParamExtractor, defaultTrackingParams, defaultUnwrappers, stripTrackingParams, trackingParamsLiterals, trackingParamsPatterns, 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,6 +9,7 @@ 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";
@@ -77,4 +79,4 @@ import { unwrapViglink } from "./unwraps/viglink.js";
77
79
  import { unwrapWebArchive } from "./unwraps/webArchive.js";
78
80
  import { unwrapYandexTurbo } from "./unwraps/yandexTurbo.js";
79
81
  import { unwrapZhihu } from "./unwraps/zhihu.js";
80
- export { cleanUrl, createParamExtractor, defaultTrackingParams, defaultUnwrappers, stripTrackingParams, trackingParamsLiterals, trackingParamsPatterns, 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 };
@@ -17,23 +17,29 @@ const trackingParamsLiterals = [
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 trackingParamsLiterals = [
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 trackingParamsLiterals = [
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,6 +176,7 @@ const trackingParamsLiterals = [
150
176
  "trk",
151
177
  "vero_conv",
152
178
  "vero_id",
179
+ "vgo_ee",
153
180
  "wickedid",
154
181
  "xtor"
155
182
  ];
@@ -1,4 +1,4 @@
1
- import { isHostOf, isSubdomainOf } from "../utils.js";
1
+ import { isHostOf, isSubdomainOf } from "../node_modules/trousse/dist/urls.js";
2
2
  //#region src/unwraps/ampCache.ts
3
3
  const httpsPathRegex = /^\/c\/s\/(.+)$/;
4
4
  const httpPathRegex = /^\/c\/(?!s\/)(.+)$/;
@@ -0,0 +1,6 @@
1
+ import { UrlUnwrapper } from "../types.js";
2
+
3
+ //#region src/unwraps/bsky.d.ts
4
+ declare const unwrapBlueskyRedirect: UrlUnwrapper;
5
+ //#endregion
6
+ export { unwrapBlueskyRedirect };
@@ -0,0 +1,9 @@
1
+ import { createParamExtractor } from "../utils.js";
2
+ //#region src/unwraps/bsky.ts
3
+ const unwrapBlueskyRedirect = createParamExtractor({
4
+ hosts: "go.bsky.app",
5
+ path: "/redirect",
6
+ params: ["u"]
7
+ });
8
+ //#endregion
9
+ export { unwrapBlueskyRedirect };
@@ -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: ["l.facebook.com", "lm.facebook.com"],
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 { decodeBase64Binary, isHostOf } from "../utils.js";
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;
@@ -0,0 +1,6 @@
1
+ import { UrlUnwrapper } from "../types.js";
2
+
3
+ //#region src/unwraps/threads.d.ts
4
+ declare const unwrapThreadsShim: UrlUnwrapper;
5
+ //#endregion
6
+ export { unwrapThreadsShim };
@@ -0,0 +1,8 @@
1
+ import { createParamExtractor } from "../utils.js";
2
+ //#region src/unwraps/threads.ts
3
+ const unwrapThreadsShim = createParamExtractor({
4
+ hosts: ["l.threads.com", "l.threads.net"],
5
+ params: ["u"]
6
+ });
7
+ //#endregion
8
+ export { unwrapThreadsShim };
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.from(binary, (char) => char.charCodeAt(0));
41
- return new TextDecoder().decode(bytes);
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, isHostOf, isSubdomainOf };
38
+ export { createParamExtractor, decodeBase64, decodeBase64Binary, decodeBase64Url, getUtf8ByteLength };
package/package.json CHANGED
@@ -38,8 +38,9 @@
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/bun": "^1.3.14",
41
- "kvalita": "^1.14.0",
41
+ "kvalita": "^1.15.0",
42
+ "trousse": "^1.0.0",
42
43
  "tsdown": "^0.22.2"
43
44
  },
44
- "version": "1.1.0"
45
+ "version": "1.2.0"
45
46
  }