22 lines
579 B
TypeScript
22 lines
579 B
TypeScript
import { BadRequestException } from "@nestjs/common"
|
|
|
|
export function normalizeProjectSlug(value: string) {
|
|
const normalized = value.trim().toLowerCase()
|
|
|
|
if (!/^[a-z0-9][a-z0-9_-]{2,63}$/.test(normalized)) {
|
|
throw new BadRequestException("project slug must be 3-64 chars and contain lowercase letters, digits, _ or -")
|
|
}
|
|
|
|
return normalized
|
|
}
|
|
|
|
export function createProjectSlug(name: string) {
|
|
const slug = name
|
|
.trim()
|
|
.toLowerCase()
|
|
.replaceAll(/[^a-z0-9_-]+/g, "-")
|
|
.replaceAll(/^-+|-+$/g, "")
|
|
|
|
return normalizeProjectSlug(slug || "project")
|
|
}
|