47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { t } from '@/i18n'
|
|
import { copy } from '@/lib/directoryCopy'
|
|
import {
|
|
SITE_KEY_MAX,
|
|
SITE_KEY_MIN,
|
|
SLUG_PATTERN,
|
|
characterCount,
|
|
isSecureUrl,
|
|
siteUrlMessage,
|
|
siteUrlProblem,
|
|
} from '@/lib/directory'
|
|
|
|
export const BIO_MAX = 280
|
|
|
|
export function nameProblem(name: string) {
|
|
return name.trim() ? '' : copy('enterName')
|
|
}
|
|
|
|
export function bioProblem(bio: string) {
|
|
return characterCount(bio) > BIO_MAX ? copy('shortenBio') : ''
|
|
}
|
|
|
|
export function secureUrlProblem(value: string) {
|
|
return isSecureUrl(value) ? '' : copy('urlHttps')
|
|
}
|
|
|
|
export function optionalSecureUrlProblem(value: string) {
|
|
return value.trim() ? secureUrlProblem(value) : ''
|
|
}
|
|
|
|
export function authorSlugProblem(slug: string) {
|
|
if (!slug || SLUG_PATTERN.test(slug)) {
|
|
return ''
|
|
}
|
|
return t('Lowercase letters, numbers and hyphens. Unique across all authors.')
|
|
}
|
|
|
|
export function siteKeyProblem(key: string) {
|
|
const valid = SLUG_PATTERN.test(key) && key.length >= SITE_KEY_MIN && key.length <= SITE_KEY_MAX
|
|
return valid ? '' : t('Use lowercase letters, numbers and hyphens, 2 to 32 characters.')
|
|
}
|
|
|
|
export function baseUrlProblem(value: string) {
|
|
const problem = siteUrlProblem(value)
|
|
return problem ? siteUrlMessage(problem) : ''
|
|
}
|