Files
url-shortener/backend/src/schemas/url.schema.ts
T
2025-11-23 20:42:56 +01:00

25 lines
569 B
TypeScript

import * as z from "zod"
const urlSchema = z.url({
protocol: /^https?$/,
hostname: z.regexes.domain,
})
export const shortIdSchema = z.string().length(6)
const aliasSchema = z
.string()
.max(30)
.optional()
.nullable()
.refine((val) => {
if (val === null || val === undefined) return true
return /^[a-zA-Z0-9]+$/.test(val)
}, "Alias can only contain alphanumeric characters")
export const urlShortenerSchema = z.object({
url: urlSchema,
shortId: shortIdSchema,
alias: aliasSchema,
})
export type UrlShortenerInput = z.infer<typeof urlShortenerSchema>