PageSourceSearch

https://kindredly.ai/js/url.utilsCetgXmY_.js

js kindredly.ai collected 2026-09-24 14:29:37 UTC 7,736 bytes, 1 lines download raw bytes

1import{I as h}from"./constantsDsHwd9pV.js";const b=new Set(["co.uk","org.uk","gov.uk","ac.uk","co.jp","co.in","co.nz","co.za","co.kr","com.au","com.br","com.mx","com.cn","com.tr","com.sg","com.hk","com.tw"]),g=new Set(["sites.google.com","docs.google.com","drive.google.com","groups.google.com","medium.com","notion.so","padlet.com","linktr.ee"]);function u(t){const e=(t||"").toLowerCase().replace(/^www\./,"").replace(/\.$/,""),n=e.split(".");if(n.length<=2)return e;const r=n.slice(-2).join(".");return b.has(r)?n.slice(-3).join("."):r}function p(t){if(typeof t!="string"||!t.trim())return null;try{const e=/^https?:\/\//i.test(t)?t:`https://${t.trim()}`,n=new URL(e).hostname.toLowerCase();return n?n.replace(/^www\./,""):null}catch{return null}}const _=["facebook.com","twitter.com","x.com","bsky.app","bsky.social","instagram.com","tiktok.com","snapchat.com","reddit.com","redd.it","tumblr.com","pinterest.com","linkedin.com","whatsapp.com","threads.net","discord.com"];function l(t){return t=k(t),t?(t.endsWith("/")&&(t=t.slice(0,-1)),t=t.toLowerCase().replace("https://","").replace("http://","").replace("wwww.","").trim(),t.startsWith("URI-")||(t="URI-"+t),t):null}function a(t){if(t==null)return t;let e=t.replace(/https?:\/\//,"").replace(/^www\./i,"");const n=e.indexOf("/"),r=n===-1?e:e.slice(0,n),s=n===-1?"":e.slice(n);return r&&r.includes(".")&&!r.startsWith("*")&&r===u(r)&&(e="*."+r+s),e.includes("/")||(e=e+"/"),e.endsWith("*")||(e=e+"*"),e}function y(t){return t==="specific"||t==="site"||t==="domain"?t:void 0}function L(t,e){if(typeof e!="string"||!e.trim())return[];const n=j(e.trim())||e.trim();let r=null;try{r=new URL(n)}catch{r=null}if(!r){const o=a(n);return o?[o]:[]}const s=r.hostname.toLowerCase();if(t==="domain"){const o=a(u(s));return o?[o]:[]}if(t==="site"){const o=a(s);return o?[o]:[]}if(U(n)){const o=a(n);return o?[o]:[]}const i=`${r.pathname}${r.search}`.replace(/^\//,"");return i?[`${s}/${i}`]:[s]}function R(t,e){var i;const n=p(t);if(!n||g.has(n))return"specific";const r=u(n),s=p(e==null?void 0:e.url);if(s&&u(s)===r||n===r)return"domain";for(const o of((i=e==null?void 0:e.info)==null?void 0:i.additionalLinks)||[]){const c=p(o==null?void 0:o.url);if(!(!c||c===n)&&u(c)===r)return"domain"}return"site"}function d(t){return Array.isArray(t)?t.filter(e=>typeof e=="string"&&e.trim().length>0):[]}function z(t){var i,o;if(!t||typeof t!="object")return[];const e=new Set,n=d(t.patterns);for(const c of n)e.add(c);const r=c=>{if(!(typeof c!="string"||c.trim().length===0))try{const f=a(c);f&&e.add(f)}catch(f){console.warn("getItemDetailPatterns: failed to derive pattern for",c,f)}};for(const c of((i=t==null?void 0:t.info)==null?void 0:i.additionalLinks)||[])w(c,t,e);return((o=t==null?void 0:t.info)==null?void 0:o.accessScopeKind)==="specific"&&n.length>0||r(t.url),Array.from(e)}function w(t,e,n){const r=t==null?void 0:t.url;if(!(typeof r!="string"||r.trim().length===0))try{const s=y(t==null?void 0:t.scope)||R(r,e);for(const i of L(s,r))i&&n.add(i)}catch(s){console.warn("getItemDetailPatterns: failed to derive pattern for",r,s)}}function W(t){var r;if(!t||typeof t!="object")return[];const e=new Set;let n=null;if(typeof t.url=="string"&&t.url.trim().length>0)try{n=a(t.url)||null}catch{n=null}for(const s of d(t.patterns))s!==n&&e.add(s);for(const s of((r=t==null?void 0:t.info)==null?void 0:r.additionalLinks)||[])w(s,t,e);return Array.from(e)}function x(t){try{return new URL(t),!0}catch{return!1}}function D(t){return P(t)?A(t)?h.YT_CHANNEL:C(t)?h.YT_VIDEO:h.YT_PAGE:null}function U(t){try{const e=new URL(t);return e.pathname==="/"||!e.pathname}catch(e){return console.error("Invalid URL:",t,e),!1}}function P(t){if(!t||typeof t!="string"||!t.includes("youtube.com")&&!t.includes("youtu.be"))return!1;try{const e=new URL(t);return!0}catch{return!1}}function E(t){if(!t||typeof t!="string"||!t.includes("reddit.com")&&!t.includes("redd.it"))return!1;try{const e=new URL(t);return!0}catch{return!1}}function m(t,e){return e.some(n=>t===n||t.endsWith(`.${n}`))}function Y(t){if(!t||typeof t!="string")return null;try{const e=new URL(t).hostname.toLowerCase();return m(e,["facebook.com","fb.com"])?"facebook":m(e,["instagram.com"])?"instagram":m(e,["x.com","twitter.com"])?"x":m(e,["bsky.app","bsky.social"])?"bluesky":m(e,["tiktok.com"])?"tiktok":null}catch{return null}}const S=new Set(["watch","shorts","playlist","feed","results","premium","gaming","music","kids","tv","embed","v","live","clip","hashtag","channel","c","user","about","account","reporthistory","upload","subscription_manager","paid_memberships","new","audiolibrary","creator","dashboard"]);function T(t){if(!t||t.length<1)return!1;const e=t.toLowerCase();return!S.has(e)}function A(t){if(!t||typeof t!="string")return!1;try{const e=new URL(t);if(!e.hostname.toLowerCase().includes("youtube.com"))return!1;
1const r=e.pathname.split("/").filter(Boolean);if(r.length<1)return!1;const s=r[0];return!!(s.startsWith("@")||["channel","c","user"].includes(s)||r.length===1&&T(s))}catch{return!1}}function C(t){if(!t||typeof t!="string"||!t.includes("youtube.com")&&!t.includes("youtu.be"))return!1;try{const e=new URL(t);if(e.hostname.toLowerCase().includes("youtu.be")){const s=e.pathname.split("/")[1];return/^[a-zA-Z0-9_-]{11}$/.test(s)}return e.searchParams.has("v")?/^[a-zA-Z0-9_-]{11}$/.test(e.searchParams.get("v")):e.pathname.match(/^\/(embed|v)\/([a-zA-Z0-9_-]{11})/)!==null}catch{return!1}}function N(t){if(!t)return null;try{const e=new URL(t);return e.hostname.includes("youtu.be")?e.pathname.substring(1):e.pathname.includes("/watch")?e.searchParams.get("v"):e.pathname.includes("/embed/")?e.pathname.split("/embed/")[1]:e.pathname.includes("/shorts/")?e.pathname.split("/shorts/")[1]:e.searchParams.get("v")||e.pathname.split("/").pop()}catch(e){return console.error("Error parsing YouTube URL",e),null}}function k(t){var i;if(!t)return t;const e=t;if(t.startsWith("internal:"))return t;const n=t.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/),r=((i=n==null?void 0:n[1])==null?void 0:i.toLowerCase())||null;if(r&&r!=="http"&&r!=="https")return t.trim();const s=["about:","chrome:","chrome-extension:","moz-extension:","safari-web-extension:","file:","data:","blob:","javascript:","capacitor:"];if(s.some(o=>e.startsWith(o)))return t;if(s.some(o=>e.includes("://"+o)))return null;t.startsWith("http")||(t="https://"+t);try{if(t.includes("google.com/?"))t=t.split("?")[0];else if(t.includes("youtube.com/watch?"))t="https://youtube.com/watch?v="+new URL(t).searchParams.get("v");else if(t.includes("youtu.be/"))t=t.split("/")[3],t=t.split("?")[0],t="https://youtube.com/watch?v="+t;else if(t.includes("youtube.com/embed/")){let c=t.split("/");t=t.split("/")[4],t=t.split("?")[0],t="https://youtube.com/watch?v="+t}t.includes("m.youtube.com")&&(t=t.replace("m.youtube.com","youtube.com"));const o=new URL(t);o.hostname=o.hostname.toLowerCase(),t=o.toString(),t.endsWith(o.hostname+"/")&&(t=t.
1slice(0,-1))}catch(o){console.error("Error cleaning url:",o)}return t.trim()}function $(t,e,n={normalize:!1}){return!t||!e?0:(n.normalize&&(t=l(t),e=l(e)),t==e?1:0)}function H(t,e="hostname"){if(e==="registrable")return I(t);try{const n=new URL(t).hostname.toLowerCase();return n?n.startsWith("www.")?n.slice(4):n:null}catch{return null}}function I(t){try{const e=new URL(t).hostname.toLowerCase();return!e||e==="localhost"?e||null:e.includes(".")?u(e):null}catch{return null}}function j(t,e=!1){if(!t)return t;t.includes("http")||(t="https://"+t);try{const n=new URL(t);n.hostname=n.hostname.toLowerCase(),t=n.toString()}catch{if(e)throw new Error("Invalid URL")}return t}export{_ as S,H as a,z as b,k as c,P as d,D as e,L as f,a as g,x as h,U as i,R as j,N as k,A as l,C as m,$ as n,Y as o,E as p,W as q,u as r,j as t,l as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.