Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ export function padRight(str: string, length: number): string {
}

export function camelcase(input: string): string {
return input.replaceAll(/([a-z])-([a-z])/g, (_, p1, p2) => {
return p1 + p2.toUpperCase()
return input.replaceAll(/-+([a-z\d])/gi, (_, p1) => {
return p1.toUpperCase()
})
}

Expand Down
21 changes: 21 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,24 @@ test('reads process.argv when called, not when imported', () => {
process.argv = original
})
})

test('camelcase option names with numbers', () => {
const cli = cac()

cli
.option('--step-1-name <name>', 'step name')
.option('--api-v1-key <key>', 'api key')
.option('--utf-8-mode', 'utf-8 mode')
.option('--web-v2-api <endpoint>', 'web v2 api')

const { options } = cli.parse(
`node bin --step-1-name compile --api-v1-key secret --utf-8-mode --web-v2-api /v2`.split(
' ',
),
)

expect(options.step1Name).toBe('compile')
expect(options.apiV1Key).toBe('secret')
expect(options.utf8Mode).toBe(true)
expect(options.webV2Api).toBe('/v2')
})