diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 06:08:49 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 06:08:49 +0300 |
commit | 996c6bf06f602ada62e3f754c121c17051072892 (patch) | |
tree | c7568793468de0faef693795e00f34c07da8e793 /app/assets/javascripts/lib/utils | |
parent | 0a0e82d1440b06650e5fc524168b1f50a8feec68 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/lib/utils')
-rw-r--r-- | app/assets/javascripts/lib/utils/text_utility.js | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/app/assets/javascripts/lib/utils/text_utility.js b/app/assets/javascripts/lib/utils/text_utility.js index 9ed286826cc..f857e618d89 100644 --- a/app/assets/javascripts/lib/utils/text_utility.js +++ b/app/assets/javascripts/lib/utils/text_utility.js @@ -142,11 +142,25 @@ export const stripHtml = (string, replace = '') => { }; /** - * Converts snake_case string to camelCase + * Converts a snake_cased string to camelCase. + * Leading and trailing underscores are ignored. * - * @param {*} string + * @param {String} string The snake_cased string to convert + * @returns {String} A camelCased version of the string + * + * @example + * + * // returns "aSnakeCasedString" + * convertToCamelCase('a_snake_cased_string') + * + * // returns "_leadingUnderscore" + * convertToCamelCase('_leading_underscore') + * + * // returns "trailingUnderscore_" + * convertToCamelCase('trailing_underscore_') */ -export const convertToCamelCase = string => string.replace(/(_\w)/g, s => s[1].toUpperCase()); +export const convertToCamelCase = string => + string.replace(/([a-z0-9])_([a-z0-9])/gi, (match, p1, p2) => `${p1}${p2.toUpperCase()}`); /** * Converts camelCase string to snake_case |