Merged in SW-3490-set-metadata-for-routes (pull request #2881)
SW-3490 set metadata for routes * feat(SW-3490): Set metadata title for hotelreservation paths Approved-by: Anton Gunnarsson
This commit is contained in:
27
packages/common/utils/toCapitalCase.test.ts
Normal file
27
packages/common/utils/toCapitalCase.test.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
import { toCapitalCase } from "./toCapitalCase"
|
||||
|
||||
describe("toCapitalCase", () => {
|
||||
it("should return same value for null or undefined", () => {
|
||||
expect(toCapitalCase(null)).toBe(null)
|
||||
expect(toCapitalCase(undefined)).toBe(undefined)
|
||||
})
|
||||
|
||||
it("should return empty string for empty input", () => {
|
||||
expect(toCapitalCase("")).toBe("")
|
||||
})
|
||||
|
||||
it("should capitalize the first letter and lowercase the rest", () => {
|
||||
expect(toCapitalCase("hello")).toBe("Hello")
|
||||
expect(toCapitalCase("HELLO")).toBe("Hello")
|
||||
expect(toCapitalCase("hElLo")).toBe("Hello")
|
||||
expect(toCapitalCase("h")).toBe("H")
|
||||
expect(toCapitalCase("H")).toBe("H")
|
||||
})
|
||||
|
||||
it("should handle strings with spaces", () => {
|
||||
expect(toCapitalCase(" hello ")).toBe("Hello")
|
||||
expect(toCapitalCase(" ")).toBe("")
|
||||
})
|
||||
})
|
||||
13
packages/common/utils/toCapitalCase.ts
Normal file
13
packages/common/utils/toCapitalCase.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export function toCapitalCase(value: string): string
|
||||
export function toCapitalCase(value: null): null
|
||||
export function toCapitalCase(value: undefined): undefined
|
||||
export function toCapitalCase(
|
||||
value: string | null | undefined
|
||||
): string | null | undefined {
|
||||
if (!value) return value
|
||||
|
||||
value = value.trim()
|
||||
if (!value) return value
|
||||
|
||||
return value[0].toUpperCase() + value.slice(1).toLowerCase()
|
||||
}
|
||||
Reference in New Issue
Block a user