diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-23 06:44:46 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-23 06:44:46 +0800 |
commit | 27d329ff2559c643b54489d0796bb2c2fcda264f (patch) | |
tree | 93b47dd6aef43f063f12c7c3882cafc9b30acb1d /packages/react-shared | |
parent | a6cdc38d532b897442bac74bc3fd1735c85317ba (diff) | |
download | dexon-sol-tools-27d329ff2559c643b54489d0796bb2c2fcda264f.tar dexon-sol-tools-27d329ff2559c643b54489d0796bb2c2fcda264f.tar.gz dexon-sol-tools-27d329ff2559c643b54489d0796bb2c2fcda264f.tar.bz2 dexon-sol-tools-27d329ff2559c643b54489d0796bb2c2fcda264f.tar.lz dexon-sol-tools-27d329ff2559c643b54489d0796bb2c2fcda264f.tar.xz dexon-sol-tools-27d329ff2559c643b54489d0796bb2c2fcda264f.tar.zst dexon-sol-tools-27d329ff2559c643b54489d0796bb2c2fcda264f.zip |
Replace complicated camelCase to spaces logic with change-case package
Diffstat (limited to 'packages/react-shared')
-rw-r--r-- | packages/react-shared/package.json | 1 | ||||
-rw-r--r-- | packages/react-shared/src/utils/utils.ts | 21 |
2 files changed, 3 insertions, 19 deletions
diff --git a/packages/react-shared/package.json b/packages/react-shared/package.json index 5df4648ee..d73d6c162 100644 --- a/packages/react-shared/package.json +++ b/packages/react-shared/package.json @@ -41,6 +41,7 @@ "@types/react-dom": "*", "@types/react-scroll": "1.5.3", "basscss": "^8.0.3", + "change-case": "^3.0.2", "is-mobile": "^0.2.2", "lodash": "^4.17.5", "material-ui": "^0.17.1", diff --git a/packages/react-shared/src/utils/utils.ts b/packages/react-shared/src/utils/utils.ts index d6b2a5cf5..15c55c04b 100644 --- a/packages/react-shared/src/utils/utils.ts +++ b/packages/react-shared/src/utils/utils.ts @@ -1,3 +1,4 @@ +import changeCase = require('change-case'); import isMobile = require('is-mobile'); import * as _ from 'lodash'; import { scroller } from 'react-scroll'; @@ -34,25 +35,7 @@ export const utils = { return text.replace(/-/g, ' '); }, convertCamelCaseToSpaces(text: string): string { - const charArray = _.map(text, (char, i) => { - const isNumber = !_.eq(_.parseInt(char), NaN); - const isPrevNumber = i !== 0 && !_.eq(_.parseInt(text[i - 1]), NaN); - if (isNumber && (i === 0 || isPrevNumber)) { - return char; - } - if (char === char.toUpperCase() && i !== 0) { - return ` ${char}`; - } - return char; - }); - let finalText = charArray.join(''); - const exceptions = { 'EIP ': 'E I P', 'ZRX ': 'Z R X', 'ERC ': 'E R C', RPC: 'R P C' }; - _.each(exceptions, (spaced, normal) => { - if (_.includes(finalText, spaced)) { - finalText = finalText.replace(spaced, normal); - } - }); - return finalText; + return changeCase.snake(text).replace(/_/g, ' '); }, getEtherScanLinkIfExists( addressOrTxHash: string, |