Commit f93bb6e6 authored by Illya Klymov's avatar Illya Klymov

Merge branch 'nfriend-fix-convert-to-snake-case' into 'master'

Make `convertToSnakeCase` gracefully handle edge cases

See merge request gitlab-org/gitlab!33528
parents 196e1da9 fa7d4f4e
...@@ -168,7 +168,7 @@ export const convertToCamelCase = string => ...@@ -168,7 +168,7 @@ export const convertToCamelCase = string =>
* @param {*} string * @param {*} string
*/ */
export const convertToSnakeCase = string => export const convertToSnakeCase = string =>
slugifyWithUnderscore(string.match(/([a-zA-Z][^A-Z]*)/g).join(' ')); slugifyWithUnderscore((string.match(/([a-zA-Z][^A-Z]*)/g) || [string]).join(' '));
/** /**
* Converts a sentence to lower case from the second word onwards * Converts a sentence to lower case from the second word onwards
......
...@@ -126,6 +126,8 @@ describe('text_utility', () => { ...@@ -126,6 +126,8 @@ describe('text_utility', () => {
${'snake case'} | ${'snake_case'} ${'snake case'} | ${'snake_case'}
${'snake_case'} | ${'snake_case'} ${'snake_case'} | ${'snake_case'}
${'snakeCasesnake Case'} | ${'snake_casesnake_case'} ${'snakeCasesnake Case'} | ${'snake_casesnake_case'}
${'123'} | ${'123'}
${'123 456'} | ${'123_456'}
`('converts string $txt to $result string', ({ txt, result }) => { `('converts string $txt to $result string', ({ txt, result }) => {
expect(textUtils.convertToSnakeCase(txt)).toEqual(result); expect(textUtils.convertToSnakeCase(txt)).toEqual(result);
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment