Change:
and , Similar to , We can implement for underscore character as well , Proposing this will be only just underscore or just hyphen replacements and not both. Foo-Bar replaced with newfoo-newbar with case preserved will be Newfoo-Newbar and FooBar will be NewfooNewBar. Please let me know if this gets a node from you guys ? Thanks!
(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like: <!-- score: 0.706 --<!-- potentialduplicatescomment --

Discussion:
} else if (matches[0].toLowerCase() === matches[0]) { return pattern.toLowerCase(); } else if (strings.containsUppercaseCharacter(matches[0][0])) { <del> if (validateSpecificSpecialCharacter(matches, pattern, '-')) { </del> <ins> const containsHyphens = validateSpecificSpecialCharacter(matches, pattern, '-'); const containsUnderscores = validateSpecificSpecialCharacter(matches, pattern, '_'); if (containsHyphens && !containsUnderscores) { </ins> return buildReplaceStringForSpecificSpecialCharacter(matches, pattern, '-'); <ins> } else if (!containsHyphens && containsUnderscores) { return buildReplaceStringForSpecificSpecialCharacter(matches, pattern, '_'); </ins> } else { return pattern[0].toUpperCase() + pattern.substr(1); }

} function validateSpecificSpecialCharacter(matches: string[], pattern: string, specialCharacter: string): boolean { <del> const doesConatinSpecialCharacter = matches[0].indexOf(specialCharacter) !== -1 && pattern.indexOf(specialCharacter) !== -1; return doesConatinSpecialCharacter && matches[0].split(specialCharacter).length === pattern.split(specialCharacter).length; </del> <ins> const doesContainSpecialCharacter = matches[0].indexOf(specialCharacter) !== -1 && pattern.indexOf(specialCharacter) !== -1; return doesContainSpecialCharacter && matches[0].split(specialCharacter).length === pattern.split(specialCharacter).length; </ins> } function buildReplaceStringForSpecificSpecialCharacter(matches: string[], pattern: string, specialCharacter: string): string {

assert.equal(buildReplaceStringWithCasePreserved(actual, 'newfoo-newbar-newabc'), 'Newfoo-Newbar-Newabc'); actual = ['Foo-Bar-abc']; assert.equal(buildReplaceStringWithCasePreserved(actual, 'newfoo-newbar'), 'Newfoo-newbar'); <ins> actual = ['Foo_Bar']; assert.equal(buildReplaceStringWithCasePreserved(actual, 'newfoo_newbar'), 'Newfoo_Newbar'); actual = ['Foo_Bar_Abc']; assert.equal(buildReplaceStringWithCasePreserved(actual, 'newfoo_newbar_newabc'), 'Newfoo_Newbar_Newabc'); actual = ['Foo_Bar_abc']; assert.equal(buildReplaceStringWithCasePreserved(actual, 'newfoo_newbar'), 'Newfoo_newbar'); actual = ['Foo_Bar-abc']; assert.equal(buildReplaceStringWithCasePreserved(actual, 'newfoo_newbar-abc'), 'Newfoo_newbar-abc'); </ins> }); test('preserve case', () => {

replacePattern = parseReplaceString('newfoo-newbar'); actual = replacePattern.buildReplaceString(['Foo-Bar-abc'], true); assert.equal(actual, 'Newfoo-newbar'); <ins> replacePattern = parseReplaceString('newfoo_newbar'); actual = replacePattern.buildReplaceString(['Foo_Bar'], true); assert.equal(actual, 'Newfoo_Newbar'); replacePattern = parseReplaceString('newfoo_newbar_newabc'); actual = replacePattern.buildReplaceString(['Foo_Bar_Abc'], true); assert.equal(actual, 'Newfoo_Newbar_Newabc'); replacePattern = parseReplaceString('newfoo_newbar'); actual = replacePattern.buildReplaceString(['Foo_Bar_abc'], true); assert.equal(actual, 'Newfoo_newbar'); replacePattern = parseReplaceString('newfoo_newbar-abc'); actual = replacePattern.buildReplaceString(['Foo_Bar-abc'], true); assert.equal(actual, 'Newfoo_newbar-abc'); </ins> }); });