feature: the package installs the Router Manager, which is no longer a package of its own.
Release / release (push) Failing after 4s
Release / release (push) Failing after 4s
This commit is contained in:
1 parent
6d90441bee
commit
8efe21bfa6
129 files changed
+17381
-104
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import type { Person } from './api.ts'
|
||||
|
||||
/** The e-mail addresses vpn-router-user accepts: one @, no spaces, and a dot in the domain. */
|
||||
const EMAIL_PATTERN = /^[^@\s]+@[^@\s]+\.[^@\s]+$/
|
||||
|
||||
/** The longest first or last name vpn-router-user accepts. */
|
||||
const PERSON_NAME_MAX = 64
|
||||
|
||||
/** The problem of each person field, or '' while it is empty or good. */
|
||||
export function personProblems(person: Person): Record<keyof Person, string> {
|
||||
const name = (value: string) => (value.trim().length > PERSON_NAME_MAX ? `At most ${PERSON_NAME_MAX} characters.` : '')
|
||||
return {
|
||||
first_name: name(person.first_name),
|
||||
last_name: name(person.last_name),
|
||||
email: person.email.trim() !== '' && !EMAIL_PATTERN.test(person.email.trim()) ? 'Not an e-mail address.' : '',
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether every person field is filled in and has no problem. */
|
||||
export function personComplete(person: Person) {
|
||||
const problems = personProblems(person)
|
||||
return (Object.keys(person) as (keyof Person)[]).every((key) => person[key].trim() !== '' && problems[key] === '')
|
||||
}
|
||||
|
||||
/** The person fields with the surrounding spaces removed, as they are sent. */
|
||||
export function trimmed(person: Person): Person {
|
||||
return { first_name: person.first_name.trim(), last_name: person.last_name.trim(), email: person.email.trim() }
|
||||
}
|
||||
Reference in new issue
Block a user