Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { COMPONENT_REGEXES } from './regex-helpers.js';

/**
* Validates that a component name is a valid Design System component name
* Accepts both formats: "Button" and "DsButton"
* @param componentName The component name to validate
* @throws Error if the component name is invalid
*/
Expand All @@ -14,22 +15,22 @@ export function validateComponentName(
!COMPONENT_REGEXES.isValidDsComponent(componentName)
) {
throw new Error(
'Invalid component name. Must be a string starting with "Ds".',
'Invalid component name. Must be a valid PascalCase string (e.g., "Button" or "DsButton").',
);
}
}

/**
* Converts a Design System component name to kebab case
* @param componentName The component name (e.g., "DsButton")
* @param componentName The component name (e.g., "DsButton" or "Button")
* @returns The kebab case name (e.g., "button")
*/
export function componentNameToKebabCase(componentName: string): string {
const kebabCase = COMPONENT_REGEXES.toKebabCase(componentName);

if (!kebabCase?.trim()?.length) {
throw new Error(
'Invalid component name. Must be a string starting with "Ds".',
'Invalid component name. Must be a valid PascalCase string (e.g., "Button" or "DsButton").',
);
}

Expand All @@ -38,7 +39,7 @@ export function componentNameToKebabCase(componentName: string): string {

/**
* Creates a tag name from a component name
* @param componentName The component name (e.g., "DsButton")
* @param componentName The component name (e.g., "DsButton" or "Button")
* @returns The tag name (e.g., "ds-button")
*/
export function componentNameToTagName(componentName: string): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export const COMPONENT_REGEXES = {
.toLowerCase(),

/**
* Validates DS component name format
* Validates DS component name format (accepts both "DsButton" and "Button" formats)
*/
isValidDsComponent: (name: string): boolean =>
/^Ds[A-Z][a-zA-Z0-9]*$/.test(name),
/^(Ds)?[A-Z][a-zA-Z0-9]*$/.test(name),

/**
* Extracts component name from coverage titles
Expand Down