diff options
author | Kushal Pandya <kushal@gitlab.com> | 2018-02-07 18:28:41 +0530 |
---|---|---|
committer | Kushal Pandya <kushal@gitlab.com> | 2018-02-07 21:32:38 +0530 |
commit | 3976368808d3e105100291ac00f2f6bc5835dd4e (patch) | |
tree | 85d1d830ef8ac77dcf9078d3d65832c836605c7d /app | |
parent | 99a5c4b93293296b8585da9cb02f04ce9e7a89d3 (diff) | |
download | gitlab-ce-3976368808d3e105100291ac00f2f6bc5835dd4e.tar.gz |
Add `convertObjectPropsToCamelCase` helper method
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/lib/utils/common_utils.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js index 5811d059e0b..7d2cf4b634f 100644 --- a/app/assets/javascripts/lib/utils/common_utils.js +++ b/app/assets/javascripts/lib/utils/common_utils.js @@ -1,5 +1,6 @@ import axios from './axios_utils'; import { getLocationHash } from './url_utility'; +import { convertToCamelCase } from './text_utility'; export const getPagePath = (index = 0) => $('body').attr('data-page').split(':')[index]; @@ -395,6 +396,26 @@ export const spriteIcon = (icon, className = '') => { return `<svg ${classAttribute}><use xlink:href="${gon.sprite_icons}#${icon}" /></svg>`; }; +/** + * This method takes in object with snake_case property names + * and returns new object with camelCase property names + * + * Reasoning for this method is to ensure consistent property + * naming conventions across JS code. + */ +export const convertObjectPropsToCamelCase = (obj = {}) => { + if (obj === null) { + return {}; + } + + return Object.keys(obj).reduce((acc, prop) => { + const result = acc; + + result[convertToCamelCase(prop)] = obj[prop]; + return acc; + }, {}); +}; + export const imagePath = imgUrl => `${gon.asset_host || ''}${gon.relative_url_root || ''}/assets/${imgUrl}`; window.gl = window.gl || {}; |