docs: handle zero-length string

This commit is contained in:
Daniel Roe 2024-12-11 13:30:12 +00:00
parent 458ead0c8b
commit dd91ac884b
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -21,7 +21,7 @@ Code in the `shared/` directory cannot import any Vue or Nitro code.
```ts twoslash [shared/utils/capitalize.ts]
export const capitalize = (input: string) => {
return input[0].toUpperCase() + input.slice(1)
return input[0] ? input[0].toUpperCase() + input.slice(1) : ''
}
```
@ -29,7 +29,7 @@ export const capitalize = (input: string) => {
```ts twoslash [shared/utils/capitalize.ts]
export default function capitalize (input: string) {
return input[0].toUpperCase() + input.slice(1)
return input[0] ? input[0].toUpperCase() + input.slice(1) : ''
}
```