feedsweep 1.0.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/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/common.d.ts +11 -0
- package/dist/common.js +116 -0
- package/dist/defaults.d.ts +14 -0
- package/dist/defaults.js +127 -0
- package/dist/embeds/youtube.d.ts +9 -0
- package/dist/embeds/youtube.js +50 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +118 -0
- package/dist/transforms/dom/fixLazyImages.d.ts +6 -0
- package/dist/transforms/dom/fixLazyImages.js +38 -0
- package/dist/transforms/dom/highlightCode.d.ts +7 -0
- package/dist/transforms/dom/highlightCode.js +30 -0
- package/dist/transforms/dom/injectEnclosureEmbedPlaceholders.d.ts +6 -0
- package/dist/transforms/dom/injectEnclosureEmbedPlaceholders.js +33 -0
- package/dist/transforms/dom/linkifyUrls.d.ts +6 -0
- package/dist/transforms/dom/linkifyUrls.js +45 -0
- package/dist/transforms/dom/mergeConsecutiveOneLinerPres.d.ts +6 -0
- package/dist/transforms/dom/mergeConsecutiveOneLinerPres.js +33 -0
- package/dist/transforms/dom/removeTrackingPixels.d.ts +6 -0
- package/dist/transforms/dom/removeTrackingPixels.js +59 -0
- package/dist/transforms/dom/replaceEmbedsWithPlaceholders.d.ts +6 -0
- package/dist/transforms/dom/replaceEmbedsWithPlaceholders.js +36 -0
- package/dist/transforms/dom/replacePreLineBreaks.d.ts +6 -0
- package/dist/transforms/dom/replacePreLineBreaks.js +13 -0
- package/dist/transforms/dom/resolveRelativeUrls.d.ts +6 -0
- package/dist/transforms/dom/resolveRelativeUrls.js +42 -0
- package/dist/transforms/dom/simplifyFigures.d.ts +6 -0
- package/dist/transforms/dom/simplifyFigures.js +27 -0
- package/dist/transforms/dom/stripComments.d.ts +6 -0
- package/dist/transforms/dom/stripComments.js +23 -0
- package/dist/transforms/dom/stripInterBlockBreaks.d.ts +6 -0
- package/dist/transforms/dom/stripInterBlockBreaks.js +18 -0
- package/dist/transforms/dom/stripParagraphBoundaryBreaks.d.ts +6 -0
- package/dist/transforms/dom/stripParagraphBoundaryBreaks.js +25 -0
- package/dist/transforms/dom/stripTrackingParams.d.ts +6 -0
- package/dist/transforms/dom/stripTrackingParams.js +22 -0
- package/dist/transforms/dom/trimPreWhitespace.d.ts +6 -0
- package/dist/transforms/dom/trimPreWhitespace.js +20 -0
- package/dist/transforms/dom/unwrapRedirectUrls.d.ts +7 -0
- package/dist/transforms/dom/unwrapRedirectUrls.js +28 -0
- package/dist/transforms/string/decodeDoubleEncodedTags.d.ts +6 -0
- package/dist/transforms/string/decodeDoubleEncodedTags.js +23 -0
- package/dist/transforms/string/paragraphizePlainText.d.ts +6 -0
- package/dist/transforms/string/paragraphizePlainText.js +10 -0
- package/dist/transforms/string/stripEmptyTags.d.ts +6 -0
- package/dist/transforms/string/stripEmptyTags.js +25 -0
- package/dist/transforms/string/stripOrphanedClosingTags.d.ts +6 -0
- package/dist/transforms/string/stripOrphanedClosingTags.js +28 -0
- package/dist/transforms/string/unwrapWrappers.d.ts +6 -0
- package/dist/transforms/string/unwrapWrappers.js +10 -0
- package/dist/types.d.ts +52 -0
- package/dist/unwraps/aceml.d.ts +6 -0
- package/dist/unwraps/aceml.js +17 -0
- package/dist/unwraps/adjust.d.ts +6 -0
- package/dist/unwraps/adjust.js +9 -0
- package/dist/unwraps/amazonAffiliate.d.ts +6 -0
- package/dist/unwraps/amazonAffiliate.js +9 -0
- package/dist/unwraps/ampCache.d.ts +6 -0
- package/dist/unwraps/ampCache.js +13 -0
- package/dist/unwraps/awin.d.ts +6 -0
- package/dist/unwraps/awin.js +9 -0
- package/dist/unwraps/bing.d.ts +6 -0
- package/dist/unwraps/bing.js +15 -0
- package/dist/unwraps/cjNetwork.d.ts +6 -0
- package/dist/unwraps/cjNetwork.js +17 -0
- package/dist/unwraps/digidip.d.ts +6 -0
- package/dist/unwraps/digidip.js +8 -0
- package/dist/unwraps/disqus.d.ts +6 -0
- package/dist/unwraps/disqus.js +8 -0
- package/dist/unwraps/douban.d.ts +6 -0
- package/dist/unwraps/douban.js +9 -0
- package/dist/unwraps/duckduckgo.d.ts +6 -0
- package/dist/unwraps/duckduckgo.js +9 -0
- package/dist/unwraps/ebayRover.d.ts +6 -0
- package/dist/unwraps/ebayRover.js +8 -0
- package/dist/unwraps/effiliation.d.ts +6 -0
- package/dist/unwraps/effiliation.js +8 -0
- package/dist/unwraps/embedly.d.ts +6 -0
- package/dist/unwraps/embedly.js +8 -0
- package/dist/unwraps/facebook.d.ts +6 -0
- package/dist/unwraps/facebook.js +9 -0
- package/dist/unwraps/feedsportal.d.ts +6 -0
- package/dist/unwraps/feedsportal.js +44 -0
- package/dist/unwraps/firebaseDynamicLinks.d.ts +6 -0
- package/dist/unwraps/firebaseDynamicLinks.js +8 -0
- package/dist/unwraps/flipboard.d.ts +6 -0
- package/dist/unwraps/flipboard.js +9 -0
- package/dist/unwraps/gateSc.d.ts +6 -0
- package/dist/unwraps/gateSc.js +8 -0
- package/dist/unwraps/georiot.d.ts +6 -0
- package/dist/unwraps/georiot.js +8 -0
- package/dist/unwraps/gitee.d.ts +6 -0
- package/dist/unwraps/gitee.js +9 -0
- package/dist/unwraps/google.d.ts +6 -0
- package/dist/unwraps/google.js +8 -0
- package/dist/unwraps/googleAmpViewer.d.ts +6 -0
- package/dist/unwraps/googleAmpViewer.js +13 -0
- package/dist/unwraps/googleNews.d.ts +6 -0
- package/dist/unwraps/googleNews.js +8 -0
- package/dist/unwraps/googleNewsModern.d.ts +6 -0
- package/dist/unwraps/googleNewsModern.js +11 -0
- package/dist/unwraps/googleScholar.d.ts +6 -0
- package/dist/unwraps/googleScholar.js +8 -0
- package/dist/unwraps/googleTranslate.d.ts +6 -0
- package/dist/unwraps/googleTranslate.js +8 -0
- package/dist/unwraps/hashnode.d.ts +6 -0
- package/dist/unwraps/hashnode.js +9 -0
- package/dist/unwraps/icptrack.d.ts +6 -0
- package/dist/unwraps/icptrack.js +9 -0
- package/dist/unwraps/idealoPartner.d.ts +6 -0
- package/dist/unwraps/idealoPartner.js +8 -0
- package/dist/unwraps/instagram.d.ts +6 -0
- package/dist/unwraps/instagram.js +8 -0
- package/dist/unwraps/jianshuGo.d.ts +6 -0
- package/dist/unwraps/jianshuGo.js +9 -0
- package/dist/unwraps/juejin.d.ts +6 -0
- package/dist/unwraps/juejin.js +8 -0
- package/dist/unwraps/leverAnalytics.d.ts +6 -0
- package/dist/unwraps/leverAnalytics.js +8 -0
- package/dist/unwraps/linksynergy.d.ts +6 -0
- package/dist/unwraps/linksynergy.js +9 -0
- package/dist/unwraps/mailchimp.d.ts +6 -0
- package/dist/unwraps/mailchimp.js +9 -0
- package/dist/unwraps/mailpanion.d.ts +6 -0
- package/dist/unwraps/mailpanion.js +8 -0
- package/dist/unwraps/mailpgn.d.ts +6 -0
- package/dist/unwraps/mailpgn.js +8 -0
- package/dist/unwraps/mailtrack.d.ts +6 -0
- package/dist/unwraps/mailtrack.js +8 -0
- package/dist/unwraps/medium.d.ts +6 -0
- package/dist/unwraps/medium.js +9 -0
- package/dist/unwraps/mimecast.d.ts +6 -0
- package/dist/unwraps/mimecast.js +11 -0
- package/dist/unwraps/mozillaOutgoing.d.ts +6 -0
- package/dist/unwraps/mozillaOutgoing.js +13 -0
- package/dist/unwraps/narrativ.d.ts +6 -0
- package/dist/unwraps/narrativ.js +8 -0
- package/dist/unwraps/nicoMs.d.ts +6 -0
- package/dist/unwraps/nicoMs.js +12 -0
- package/dist/unwraps/outlookSafelinks.d.ts +6 -0
- package/dist/unwraps/outlookSafelinks.js +8 -0
- package/dist/unwraps/partnerAds.d.ts +6 -0
- package/dist/unwraps/partnerAds.js +8 -0
- package/dist/unwraps/pocket.d.ts +6 -0
- package/dist/unwraps/pocket.js +9 -0
- package/dist/unwraps/postmark.d.ts +6 -0
- package/dist/unwraps/postmark.js +12 -0
- package/dist/unwraps/proofpointV1.d.ts +6 -0
- package/dist/unwraps/proofpointV1.js +16 -0
- package/dist/unwraps/proofpointV2.d.ts +6 -0
- package/dist/unwraps/proofpointV2.js +16 -0
- package/dist/unwraps/proofpointV3.d.ts +6 -0
- package/dist/unwraps/proofpointV3.js +78 -0
- package/dist/unwraps/pxf.d.ts +6 -0
- package/dist/unwraps/pxf.js +8 -0
- package/dist/unwraps/recruitics.d.ts +6 -0
- package/dist/unwraps/recruitics.js +8 -0
- package/dist/unwraps/redditOut.d.ts +6 -0
- package/dist/unwraps/redditOut.js +8 -0
- package/dist/unwraps/redirectingat.d.ts +6 -0
- package/dist/unwraps/redirectingat.js +8 -0
- package/dist/unwraps/segmentfault.d.ts +6 -0
- package/dist/unwraps/segmentfault.js +16 -0
- package/dist/unwraps/shareasale.d.ts +6 -0
- package/dist/unwraps/shareasale.js +9 -0
- package/dist/unwraps/sjv.d.ts +6 -0
- package/dist/unwraps/sjv.js +8 -0
- package/dist/unwraps/skimlinks.d.ts +6 -0
- package/dist/unwraps/skimlinks.js +8 -0
- package/dist/unwraps/slack.d.ts +6 -0
- package/dist/unwraps/slack.js +9 -0
- package/dist/unwraps/smartredirect.d.ts +6 -0
- package/dist/unwraps/smartredirect.js +8 -0
- package/dist/unwraps/sspai.d.ts +6 -0
- package/dist/unwraps/sspai.js +9 -0
- package/dist/unwraps/steamLinkfilter.d.ts +6 -0
- package/dist/unwraps/steamLinkfilter.js +9 -0
- package/dist/unwraps/telegramIv.d.ts +6 -0
- package/dist/unwraps/telegramIv.js +9 -0
- package/dist/unwraps/tradedoubler.d.ts +6 -0
- package/dist/unwraps/tradedoubler.js +9 -0
- package/dist/unwraps/tumblr.d.ts +6 -0
- package/dist/unwraps/tumblr.js +9 -0
- package/dist/unwraps/valuecommerce.d.ts +6 -0
- package/dist/unwraps/valuecommerce.js +9 -0
- package/dist/unwraps/viglink.d.ts +6 -0
- package/dist/unwraps/viglink.js +8 -0
- package/dist/unwraps/vkAway.d.ts +6 -0
- package/dist/unwraps/vkAway.js +9 -0
- package/dist/unwraps/webArchive.d.ts +6 -0
- package/dist/unwraps/webArchive.js +12 -0
- package/dist/unwraps/yahooSearch.d.ts +6 -0
- package/dist/unwraps/yahooSearch.js +12 -0
- package/dist/unwraps/yandexTurbo.d.ts +6 -0
- package/dist/unwraps/yandexTurbo.js +12 -0
- package/dist/unwraps/youtube.d.ts +6 -0
- package/dist/unwraps/youtube.js +9 -0
- package/dist/unwraps/zhihu.d.ts +6 -0
- package/dist/unwraps/zhihu.js +8 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.js +31 -0
- package/package.json +58 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/unwraps/postmark.ts
|
|
2
|
+
const postmarkPathRegex = /^\/[23][st]\/([^/]+)\//;
|
|
3
|
+
const unwrapPostmark = (url) => {
|
|
4
|
+
if (url.hostname !== "click.pstmrk.it") return;
|
|
5
|
+
const match = url.pathname.match(postmarkPathRegex);
|
|
6
|
+
if (!match) return;
|
|
7
|
+
try {
|
|
8
|
+
return decodeURIComponent(match[1]);
|
|
9
|
+
} catch {}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { unwrapPostmark };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createParamExtractor } from "../utils.js";
|
|
2
|
+
//#region src/unwraps/proofpointV1.ts
|
|
3
|
+
const baseExtractor = createParamExtractor({
|
|
4
|
+
hosts: "urldefense.proofpoint.com",
|
|
5
|
+
path: "/v1/url",
|
|
6
|
+
params: ["u"]
|
|
7
|
+
});
|
|
8
|
+
const unwrapProofpointV1 = (url) => {
|
|
9
|
+
const raw = baseExtractor(url);
|
|
10
|
+
if (!raw) return;
|
|
11
|
+
try {
|
|
12
|
+
return decodeURIComponent(raw.replace(/-/g, "%").replace(/_/g, "/"));
|
|
13
|
+
} catch {}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { unwrapProofpointV1 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createParamExtractor } from "../utils.js";
|
|
2
|
+
//#region src/unwraps/proofpointV2.ts
|
|
3
|
+
const baseExtractor = createParamExtractor({
|
|
4
|
+
hosts: "urldefense.proofpoint.com",
|
|
5
|
+
path: "/v2/url",
|
|
6
|
+
params: ["u"]
|
|
7
|
+
});
|
|
8
|
+
const unwrapProofpointV2 = (url) => {
|
|
9
|
+
const raw = baseExtractor(url);
|
|
10
|
+
if (!raw) return;
|
|
11
|
+
try {
|
|
12
|
+
return decodeURIComponent(raw.replace(/-/g, "%").replace(/_/g, "/"));
|
|
13
|
+
} catch {}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { unwrapProofpointV2 };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/unwraps/proofpointV3.ts
|
|
2
|
+
const v3PathRegex = /^\/v3\/__(.+)__;([^!]*)!/;
|
|
3
|
+
const v3HostSet = new Set([
|
|
4
|
+
"urldefense.com",
|
|
5
|
+
"urldefense.proofpoint.com",
|
|
6
|
+
"urldefense.us"
|
|
7
|
+
]);
|
|
8
|
+
const runLengthMap = (() => {
|
|
9
|
+
const map = {};
|
|
10
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
11
|
+
for (let index = 0; index < 64; index += 1) map[alphabet[index]] = index + 2;
|
|
12
|
+
return map;
|
|
13
|
+
})();
|
|
14
|
+
const decodeReplacements = (mangled, replacementBase64) => {
|
|
15
|
+
if (replacementBase64.length === 0) return mangled;
|
|
16
|
+
let padded = replacementBase64;
|
|
17
|
+
while (padded.length % 4 !== 0) padded += "=";
|
|
18
|
+
const replacement = Buffer.from(padded, "base64url").toString("utf-8");
|
|
19
|
+
const replacementChars = Array.from(replacement);
|
|
20
|
+
const urlChars = Array.from(mangled);
|
|
21
|
+
const result = [];
|
|
22
|
+
const matcher = /(?<!\*)\*(?!\*)|\*{2}[A-Za-z0-9\-_]/g;
|
|
23
|
+
let lastIndex = 0;
|
|
24
|
+
let savedBytes = 0;
|
|
25
|
+
let match;
|
|
26
|
+
match = matcher.exec(mangled);
|
|
27
|
+
while (match !== null) {
|
|
28
|
+
const startChar = positionInChars(mangled, match.index);
|
|
29
|
+
const endChar = positionInChars(mangled, match.index + match[0].length);
|
|
30
|
+
for (let charIndex = lastIndex; charIndex < startChar; charIndex += 1) result.push(urlChars[charIndex]);
|
|
31
|
+
if (match[0] === "*") {
|
|
32
|
+
const next = replacementChars.shift();
|
|
33
|
+
if (next === void 0) return;
|
|
34
|
+
result.push(next);
|
|
35
|
+
} else {
|
|
36
|
+
let bytesToReplace = runLengthMap[match[0][2]];
|
|
37
|
+
if (savedBytes !== 0) {
|
|
38
|
+
bytesToReplace += savedBytes;
|
|
39
|
+
savedBytes = 0;
|
|
40
|
+
}
|
|
41
|
+
let bytesConsumed = 0;
|
|
42
|
+
while (bytesConsumed < bytesToReplace) {
|
|
43
|
+
const next = replacementChars.shift();
|
|
44
|
+
if (next === void 0) return;
|
|
45
|
+
result.push(next);
|
|
46
|
+
bytesConsumed += Buffer.byteLength(next, "utf-8");
|
|
47
|
+
if (replacementChars.length > 0) {
|
|
48
|
+
if (Buffer.byteLength(replacementChars[0], "utf-8") > bytesToReplace - bytesConsumed) {
|
|
49
|
+
savedBytes = bytesToReplace - bytesConsumed;
|
|
50
|
+
bytesConsumed += savedBytes;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
lastIndex = endChar;
|
|
56
|
+
match = matcher.exec(mangled);
|
|
57
|
+
}
|
|
58
|
+
for (let charIndex = lastIndex; charIndex < urlChars.length; charIndex += 1) result.push(urlChars[charIndex]);
|
|
59
|
+
return result.join("");
|
|
60
|
+
};
|
|
61
|
+
const positionInChars = (source, codeUnitIndex) => {
|
|
62
|
+
let charIndex = 0;
|
|
63
|
+
let unit = 0;
|
|
64
|
+
while (unit < codeUnitIndex && unit < source.length) {
|
|
65
|
+
const codePoint = source.codePointAt(unit);
|
|
66
|
+
unit += codePoint !== void 0 && codePoint > 65535 ? 2 : 1;
|
|
67
|
+
charIndex += 1;
|
|
68
|
+
}
|
|
69
|
+
return charIndex;
|
|
70
|
+
};
|
|
71
|
+
const unwrapProofpointV3 = (url) => {
|
|
72
|
+
if (!v3HostSet.has(url.hostname)) return;
|
|
73
|
+
const match = `${url.pathname}${url.search}`.match(v3PathRegex);
|
|
74
|
+
if (!match) return;
|
|
75
|
+
return decodeReplacements(match[1], match[2]);
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { unwrapProofpointV3 };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createParamExtractor } from "../utils.js";
|
|
2
|
+
//#region src/unwraps/segmentfault.ts
|
|
3
|
+
const baseExtractor = createParamExtractor({
|
|
4
|
+
hosts: "link.segmentfault.com",
|
|
5
|
+
params: ["enc"]
|
|
6
|
+
});
|
|
7
|
+
const unwrapSegmentfault = (url) => {
|
|
8
|
+
const raw = baseExtractor(url);
|
|
9
|
+
if (!raw) return;
|
|
10
|
+
try {
|
|
11
|
+
const decoded = Buffer.from(raw, "base64").toString("utf-8");
|
|
12
|
+
if (decoded.startsWith("http://") || decoded.startsWith("https://")) return decoded;
|
|
13
|
+
} catch {}
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { unwrapSegmentfault };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createParamExtractor } from "../utils.js";
|
|
2
|
+
//#region src/unwraps/steamLinkfilter.ts
|
|
3
|
+
const unwrapSteamLinkfilter = createParamExtractor({
|
|
4
|
+
hosts: "steamcommunity.com",
|
|
5
|
+
path: "/linkfilter/",
|
|
6
|
+
params: ["url"]
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { unwrapSteamLinkfilter };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createParamExtractor } from "../utils.js";
|
|
2
|
+
//#region src/unwraps/tradedoubler.ts
|
|
3
|
+
const unwrapTradedoubler = createParamExtractor({
|
|
4
|
+
hosts: "clk.tradedoubler.com",
|
|
5
|
+
path: "/click",
|
|
6
|
+
params: ["url"]
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { unwrapTradedoubler };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createParamExtractor } from "../utils.js";
|
|
2
|
+
//#region src/unwraps/valuecommerce.ts
|
|
3
|
+
const unwrapValuecommerce = createParamExtractor({
|
|
4
|
+
hosts: "ck.jp.ap.valuecommerce.com",
|
|
5
|
+
path: "/servlet/referral",
|
|
6
|
+
params: ["vc_url"]
|
|
7
|
+
});
|
|
8
|
+
//#endregion
|
|
9
|
+
export { unwrapValuecommerce };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/unwraps/webArchive.ts
|
|
2
|
+
const pathRegex = /^\/web\/\d{14}\*?\/(.+)$/;
|
|
3
|
+
const unwrapWebArchive = (url) => {
|
|
4
|
+
if (url.hostname !== "web.archive.org") return;
|
|
5
|
+
const match = url.pathname.match(pathRegex);
|
|
6
|
+
if (!match) return;
|
|
7
|
+
try {
|
|
8
|
+
return decodeURIComponent(match[1]);
|
|
9
|
+
} catch {}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { unwrapWebArchive };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/unwraps/yahooSearch.ts
|
|
2
|
+
const yahooPathRegex = /\/RU=([^/]+)\/RK=/;
|
|
3
|
+
const unwrapYahooSearch = (url) => {
|
|
4
|
+
if (url.hostname !== "r.search.yahoo.com") return;
|
|
5
|
+
const match = url.pathname.match(yahooPathRegex);
|
|
6
|
+
if (!match) return;
|
|
7
|
+
try {
|
|
8
|
+
return decodeURIComponent(match[1]);
|
|
9
|
+
} catch {}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { unwrapYahooSearch };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/unwraps/yandexTurbo.ts
|
|
2
|
+
const turbopagesHostRegex = /\.turbopages\.org$/;
|
|
3
|
+
const turbopagesPathRegex = /^\/[^/]+\/s\/(.+)$/;
|
|
4
|
+
const dashRegex = /-/g;
|
|
5
|
+
const unwrapYandexTurbo = (url) => {
|
|
6
|
+
if (!turbopagesHostRegex.test(url.hostname)) return;
|
|
7
|
+
const match = url.pathname.match(turbopagesPathRegex);
|
|
8
|
+
if (!match) return;
|
|
9
|
+
return `https://${url.hostname.replace(turbopagesHostRegex, "").replace(dashRegex, ".")}/${match[1]}`;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { unwrapYandexTurbo };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { UrlUnwrapper } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils.d.ts
|
|
4
|
+
declare const chooseBaseUrl: (itemUrl: string | null | undefined, siteUrl: string | null | undefined, feedUrl: string) => string | undefined;
|
|
5
|
+
declare const coerceNumber: (value: string | null) => number | undefined;
|
|
6
|
+
type ParamExtractorConfig = {
|
|
7
|
+
hosts: string | Array<string> | RegExp;
|
|
8
|
+
path?: string;
|
|
9
|
+
params: Array<string>;
|
|
10
|
+
};
|
|
11
|
+
declare const createParamExtractor: (config: ParamExtractorConfig) => UrlUnwrapper;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ParamExtractorConfig, chooseBaseUrl, coerceNumber, createParamExtractor };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { resolveUrl } from "feedcanon";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
const chooseBaseUrl = (itemUrl, siteUrl, feedUrl) => {
|
|
4
|
+
if (itemUrl && resolveUrl(itemUrl)) return itemUrl;
|
|
5
|
+
if (siteUrl) {
|
|
6
|
+
const resolved = resolveUrl(siteUrl, feedUrl);
|
|
7
|
+
if (resolved) return resolved;
|
|
8
|
+
}
|
|
9
|
+
return resolveUrl(feedUrl);
|
|
10
|
+
};
|
|
11
|
+
const coerceNumber = (value) => {
|
|
12
|
+
if (value == null) return;
|
|
13
|
+
const parsed = Number(value);
|
|
14
|
+
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
15
|
+
};
|
|
16
|
+
const createParamExtractor = (config) => {
|
|
17
|
+
const matchesHost = (host) => {
|
|
18
|
+
if (config.hosts instanceof RegExp) return config.hosts.test(host);
|
|
19
|
+
return (Array.isArray(config.hosts) ? config.hosts : [config.hosts]).includes(host);
|
|
20
|
+
};
|
|
21
|
+
return (url) => {
|
|
22
|
+
if (!matchesHost(url.hostname)) return;
|
|
23
|
+
if (config.path && url.pathname !== config.path) return;
|
|
24
|
+
for (const param of config.params) {
|
|
25
|
+
const value = url.searchParams.get(param);
|
|
26
|
+
if (value) return value;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { chooseBaseUrl, coerceNumber, createParamExtractor };
|