All files / src/dom ids.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 5/5
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  404x                 130x       114x       114x       7x    
function sanitizeIdPart(value: string): string {
  return value
    .trim()
    .toLowerCase()
    .replace(/[^a-z0-9_-]+/g, "-")
    .replace(/^-+|-+$/g, "");
}
 
/** Generate deterministic DOM IDs without trusting schema text as raw attributes. */
export function createFieldDomId(schemaId: string, fieldName: string, classPrefix: string): string {
  return `${sanitizeIdPart(classPrefix)}-${sanitizeIdPart(schemaId)}-${sanitizeIdPart(fieldName)}`;
}
 
export function createHelpDomId(fieldId: string): string {
  return `${fieldId}-help`;
}
 
export function createErrorDomId(fieldId: string): string {
  return `${fieldId}-error`;
}
 
export function createErrorSummaryId(schemaId: string, classPrefix: string): string {
  return `${sanitizeIdPart(classPrefix)}-${sanitizeIdPart(schemaId)}-error-summary`;
}