Skip to content

Commit 577b171

Browse files
poltorakSzymon.Poltorak
andauthored
refactor: allow to pass component name without DS prefix (#16)
* refactor(): allow to pass component name without DS prefix * refactor: revent not needed changes --------- Co-authored-by: Szymon.Poltorak <szymon.poltorak@push-based.io>
1 parent 29ec8df commit 577b171

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

packages/angular-mcp-server/src/lib/tools/ds/shared/utils/component-validation.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { COMPONENT_REGEXES } from './regex-helpers.js';
22

33
/**
44
* Validates that a component name is a valid Design System component name
5+
* Accepts both formats: "Button" and "DsButton"
56
* @param componentName The component name to validate
67
* @throws Error if the component name is invalid
78
*/
@@ -14,22 +15,22 @@ export function validateComponentName(
1415
!COMPONENT_REGEXES.isValidDsComponent(componentName)
1516
) {
1617
throw new Error(
17-
'Invalid component name. Must be a string starting with "Ds".',
18+
'Invalid component name. Must be a valid PascalCase string (e.g., "Button" or "DsButton").',
1819
);
1920
}
2021
}
2122

2223
/**
2324
* Converts a Design System component name to kebab case
24-
* @param componentName The component name (e.g., "DsButton")
25+
* @param componentName The component name (e.g., "DsButton" or "Button")
2526
* @returns The kebab case name (e.g., "button")
2627
*/
2728
export function componentNameToKebabCase(componentName: string): string {
2829
const kebabCase = COMPONENT_REGEXES.toKebabCase(componentName);
2930

3031
if (!kebabCase?.trim()?.length) {
3132
throw new Error(
32-
'Invalid component name. Must be a string starting with "Ds".',
33+
'Invalid component name. Must be a valid PascalCase string (e.g., "Button" or "DsButton").',
3334
);
3435
}
3536

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

3940
/**
4041
* Creates a tag name from a component name
41-
* @param componentName The component name (e.g., "DsButton")
42+
* @param componentName The component name (e.g., "DsButton" or "Button")
4243
* @returns The tag name (e.g., "ds-button")
4344
*/
4445
export function componentNameToTagName(componentName: string): string {

packages/angular-mcp-server/src/lib/tools/ds/shared/utils/regex-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ export const COMPONENT_REGEXES = {
6060
.toLowerCase(),
6161

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

6868
/**
6969
* Extracts component name from coverage titles

0 commit comments

Comments
 (0)