fix(utils/camelToSnakeCase): better number handling

This commit is contained in:
Julien Fontanet 2016-08-18 15:23:57 +02:00
parent 27a2853ee8
commit 5d0b40f752
2 changed files with 3 additions and 1 deletions

View File

@ -60,7 +60,7 @@ export const streamToBuffer = getStream.buffer
export function camelToSnakeCase (string) {
return string.replace(
/([a-z])([A-Z])/g,
/([a-z0-9])([A-Z])/g,
(_, prevChar, currChar) => `${prevChar}_${currChar.toLowerCase()}`
)
}

View File

@ -20,10 +20,12 @@ import {
describe('camelToSnakeCase()', function () {
it('converts a string from camelCase to snake_case', function () {
expect(camelToSnakeCase('fooBar')).to.equal('foo_bar')
expect(camelToSnakeCase('ipv4Allowed')).to.equal('ipv4_allowed')
})
it('does not alter snake_case strings', function () {
expect(camelToSnakeCase('foo_bar')).to.equal('foo_bar')
expect(camelToSnakeCase('ipv4_allowed')).to.equal('ipv4_allowed')
})
it('does not alter upper case letters expect those from the camelCase', function () {