decord/alpha/source/modules/coded_links/findCodedLinkUrlsUsingRegex.tsx

31 lines
1 KiB
TypeScript
Raw Normal View History

2026-10-12 06:59:38 +00:00
// Module ID: 14069
// Function ID: 14070
// Name: findCodedLinkUrlsUsingRegex
2026-10-09 10:00:15 +00:00
// Dependencies: [1385, 2]
2026-08-25 06:04:03 +00:00
// Exports: default
2026-10-12 06:59:38 +00:00
// Module 14069 (findCodedLinkUrlsUsingRegex)
2026-10-09 10:00:15 +00:00
import ip from "ip" /* 1385 */;
2026-10-03 08:58:59 +00:00
import size from "module_2" /* 2 */;
2026-08-25 06:04:03 +00:00
function trimTrailingPunctuation(str) {
return str.replace(re2, "");
2026-08-25 06:04:03 +00:00
}
const regExp = new RegExp("(?:(?:(?:https?:)?//)|www\\.)(?:[^\\s:@]+(?::[^\\s@]*)?@)?(?:localhost|" + ip.v4().source + "|(?:[a-z\\u00a1-\\uffff0-9-_]+\\.)+(?:(?:[a-z\\u00a1-\\uffff]{2,})))(?::\\d{2,5})?(?:[/?#][^\\s\"()\\[\\]<>]*)?", "ig");
2026-08-25 06:04:03 +00:00
const re1 = /`{3,}[\s\S]*?(?:`{3,}|$)|(`{1,2})[^`]+\1(?!`)/g;
const re2 = /[.,;:?'*_~|]+$/;
const result = size.fileFinishedImporting("modules/coded_links/findCodedLinkUrlsUsingRegex.tsx");
2026-08-25 06:04:03 +00:00
export default function findCodedLinkUrlsUsingRegex(str) {
2026-10-03 08:58:59 +00:00
str = str.replaceAll(re1, " ");
const match = str.match(regExp);
2026-08-25 06:04:03 +00:00
let mapped;
if (match != null) {
mapped = match.map(trimTrailingPunctuation);
}
if (mapped == null) {
mapped = [];
}
return mapped;
};