[READ-ONLY] a fast, modern browser for the npm registry
at main 27 lines 678 B view raw
1import * as v from 'valibot' 2 3const NPM_USERNAME_RE = /^[a-z0-9]([\w.-]*[a-z0-9])?$/i 4const NPM_USERNAME_MAX_LENGTH = 50 5 6/** 7 * Schema for npm usernames. 8 */ 9export const NpmUsernameSchema = v.pipe( 10 v.string(), 11 v.trim(), 12 v.nonEmpty('Username is required'), 13 v.maxLength(NPM_USERNAME_MAX_LENGTH, 'Username is too long'), 14 v.regex(NPM_USERNAME_RE, 'Invalid username format'), 15) 16 17/** 18 * Schema for Gravatar query inputs. 19 */ 20export const GravatarQuerySchema = v.object({ 21 username: NpmUsernameSchema, 22}) 23 24/** @public */ 25export type NpmUsername = v.InferOutput<typeof NpmUsernameSchema> 26/** @public */ 27export type GravatarQuery = v.InferOutput<typeof GravatarQuerySchema>