move helper back to strings dir

This commit is contained in:
Samuel Newman
2025-12-11 12:10:56 +02:00
parent 6f67a446f3
commit 677d78b2d7
3 changed files with 17 additions and 14 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
import {describe, expect, it} from '@jest/globals'
// co-located with LinkBox.tsx so we can lazy load PSL
import {splitApexDomain} from '../../../src/components/dialogs/LinkWarning/LinkBox'
import {splitApexDomain} from '../../../src/lib/strings/url-apex-split'
import {
isPossiblyAUrl,
isTrustedUrl,
+1 -12
View File
@@ -1,21 +1,10 @@
import {useMemo} from 'react'
import {View} from 'react-native'
import psl from 'psl'
import {splitApexDomain} from '#/lib/strings/url-apex-split'
import {atoms as a, useTheme} from '#/alf'
import {Text} from '#/components/Typography'
export function splitApexDomain(hostname: string): [string, string] {
const hostnamep = psl.parse(hostname)
if (hostnamep.error || !hostnamep.listed || !hostnamep.domain) {
return ['', hostname]
}
return [
hostnamep.subdomain ? `${hostnamep.subdomain}.` : '',
hostnamep.domain,
]
}
export default function LinkBox({href}: {href: string}) {
const t = useTheme()
const [scheme, hostname, rest] = useMemo(() => {
+15
View File
@@ -0,0 +1,15 @@
import psl from 'psl'
/**
* NOTE: Expensive import! Try to lazy load when using it.
*/
export function splitApexDomain(hostname: string): [string, string] {
const hostnamep = psl.parse(hostname)
if (hostnamep.error || !hostnamep.listed || !hostnamep.domain) {
return ['', hostname]
}
return [
hostnamep.subdomain ? `${hostnamep.subdomain}.` : '',
hostnamep.domain,
]
}