sync
This commit is contained in:
21
apps/backend/src/projects/project-slug.ts
Normal file
21
apps/backend/src/projects/project-slug.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user