Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: only strip camel case if hyphenated (#316)
Fixes #315
  • Loading branch information
bcoe committed Sep 9, 2020
1 parent d39ed80 commit 95a9e78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/string-utils.ts
Expand Up @@ -30,7 +30,7 @@ export function decamelize (str: string, joinString?: string): string {
for (let i = 0; i < str.length; i++) {
const chrLower = lowercase.charAt(i)
const chrString = str.charAt(i)
if (chrLower !== chrString) {
if (chrLower !== chrString && i > 0) {
notCamelcase += `${joinString}${lowercase.charAt(i)}`
} else {
notCamelcase += chrString
Expand Down
2 changes: 1 addition & 1 deletion lib/yargs-parser.ts
Expand Up @@ -421,7 +421,7 @@ export class YargsParser {

if (configuration['strip-aliased']) {
;([] as string[]).concat(...Object.keys(aliases).map(k => aliases[k])).forEach(alias => {
if (configuration['camel-case-expansion']) {
if (configuration['camel-case-expansion'] && alias.includes('-')) {
delete argv[alias.split('.').map(prop => camelCase(prop)).join('.')]
}

Expand Down
17 changes: 17 additions & 0 deletions test/yargs-parser.cjs
Expand Up @@ -3636,6 +3636,23 @@ describe('yargs-parser', function () {
'test-value': 1
})
})

it('only removes camel case expansion if keys have hyphen', function () {
const argv = parser(['--foo', '1', '-a', '2'], {
configuration: {
'strip-aliased': true
},
alias: {
aliased1: ['Foo'],
aliased2: ['A']
}
})
argv.should.deep.equal({
_: [],
foo: 1,
a: 2
})
})
})

describe('prototype collisions', () => {
Expand Down

0 comments on commit 95a9e78

Please sign in to comment.