Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿
1const truncateUrl = (url: string, maxLength: number): string => {
2 try {
3 const parsed = new URL(url);
4 const stripped =
5 `${parsed.host}${parsed.pathname}${parsed.search}${parsed.hash}`.replace(
6 /^www\./,
7 ""
8 );
9
10 if (parsed.hostname.endsWith("hey.xyz")) return stripped;
11
12 return stripped.length > maxLength
13 ? `${stripped.slice(0, maxLength - 1)}…`
14 : stripped;
15 } catch {
16 // fallback: remove protocol/www, truncate if needed
17 const stripped = `${url.replace(/^(https?:\/\/)?(www\.)?/, "")}`;
18 return stripped.length > maxLength
19 ? `${stripped.slice(0, maxLength - 1)}…`
20 : stripped;
21 }
22};
23
24export default truncateUrl;