diff --git a/__tests__/lib/strings/url-helpers.test.ts b/__tests__/lib/strings/url-helpers.test.ts index 339556a02d..5c06945055 100644 --- a/__tests__/lib/strings/url-helpers.test.ts +++ b/__tests__/lib/strings/url-helpers.test.ts @@ -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, diff --git a/src/components/dialogs/LinkWarning/LinkBox.tsx b/src/components/dialogs/LinkWarning/LinkBox.tsx index 3814eaa06d..4fe4d25ba6 100644 --- a/src/components/dialogs/LinkWarning/LinkBox.tsx +++ b/src/components/dialogs/LinkWarning/LinkBox.tsx @@ -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(() => { diff --git a/src/lib/strings/url-apex-split.ts b/src/lib/strings/url-apex-split.ts new file mode 100644 index 0000000000..2967871d09 --- /dev/null +++ b/src/lib/strings/url-apex-split.ts @@ -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, + ] +}