move helper back to strings dir
This commit is contained in:
@@ -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,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(() => {
|
||||
|
||||
@@ -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,
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user