Files
project-gifuu/frontend/source/functions/Format.ts
T

22 lines
666 B
TypeScript
Raw Normal View History

2026-05-23 17:17:56 -07:00
export const validTagMatcher = new RegExp(/^[\p{L}\p{N}_]+$/u)
// Format user input for api requests, returns an empty string if invalid
export function formatTagInput(str: string): string | false {
const normal = str.trim().toLowerCase().replaceAll(/\s\s+/g, ' ').replaceAll(' ', '_')
if (!validTagMatcher.test(normal)) {
return false
}
return normal
}
// Format tag label for display in html
export function formatTagTextContent(str: string): string {
return str.trim().toUpperCase().replace('_', ' ')
}
// Format tag usage for display in html
export function formatTagUsage(num: number): string {
return num.toLocaleString()
}