-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathuser.ts
More file actions
25 lines (21 loc) · 648 Bytes
/
user.ts
File metadata and controls
25 lines (21 loc) · 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import * as v from 'valibot'
const NPM_USERNAME_RE = /^[a-z0-9]([\w.-]*[a-z0-9])?$/i
const NPM_USERNAME_MAX_LENGTH = 50
/**
* Schema for npm usernames.
*/
export const NpmUsernameSchema = v.pipe(
v.string(),
v.trim(),
v.nonEmpty('Username is required'),
v.maxLength(NPM_USERNAME_MAX_LENGTH, 'Username is too long'),
v.regex(NPM_USERNAME_RE, 'Invalid username format'),
)
/**
* Schema for Gravatar query inputs.
*/
export const GravatarQuerySchema = v.object({
username: NpmUsernameSchema,
})
export type NpmUsername = v.InferOutput<typeof NpmUsernameSchema>
export type GravatarQuery = v.InferOutput<typeof GravatarQuerySchema>