fix: use lodash/startCase to format key parts

Signed-off-by: Rich Barton-Cooper <rich@syntasso.io>
This commit is contained in:
Rich Barton-Cooper
2024-08-23 12:56:11 +01:00
parent 8dd6ef65bf
commit 23ac83be20
2 changed files with 6 additions and 7 deletions
@@ -45,7 +45,7 @@ describe('formatKey', () => {
});
it('should leave a top-level key untouched', () => {
expect(formatKey('topLevel')).toBe('TopLevel');
expect(formatKey('topLevel')).toBe('Top Level');
});
it('should handle keys with a leading slash', () => {
@@ -70,13 +70,11 @@ describe('formatKey', () => {
it('should handle keys with spaces', () => {
expect(formatKey('parent/child with spaces')).toBe(
'Parent > Child with spaces',
'Parent > Child With Spaces',
);
});
it('should handle keys with special characters', () => {
expect(formatKey('parent/child@!#$%^&*()')).toBe(
'Parent > Child@!#$%^&*()',
);
it('should remove special characters', () => {
expect(formatKey('parent/child@!#$%^&*()')).toBe('Parent > Child');
});
});
@@ -15,6 +15,7 @@
*/
import { JsonObject, JsonValue } from '@backstage/types';
import { startCase } from 'lodash';
export function isJsonObject(value?: JsonValue): value is JsonObject {
return typeof value === 'object' && value !== null && !Array.isArray(value);
@@ -25,6 +26,6 @@ export function formatKey(key: string): string {
const parts = key.split('/');
return parts
.filter(Boolean)
.map(part => part.charAt(0).toLocaleUpperCase('en-US') + part.slice(1))
.map(part => startCase(part))
.join(' > ');
}