diff options
author | Fabio Berger <me@fabioberger.com> | 2018-08-04 00:28:56 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-08-04 00:28:56 +0800 |
commit | a728247d6c4819d15a7fadd4cd6dd582f150b258 (patch) | |
tree | 4f0758c9561d83d54f263e4381391f4a3a0fd2f3 /packages/react-shared/src/utils | |
parent | 36d615318d7a0d63c254b42f029d393aea04c674 (diff) | |
download | dexon-sol-tools-a728247d6c4819d15a7fadd4cd6dd582f150b258.tar.gz dexon-sol-tools-a728247d6c4819d15a7fadd4cd6dd582f150b258.tar.zst dexon-sol-tools-a728247d6c4819d15a7fadd4cd6dd582f150b258.zip |
Display camelCase names all-caps properly
Diffstat (limited to 'packages/react-shared/src/utils')
-rw-r--r-- | packages/react-shared/src/utils/utils.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/react-shared/src/utils/utils.ts b/packages/react-shared/src/utils/utils.ts index 93c7e9f7b..6dd0b9993 100644 --- a/packages/react-shared/src/utils/utils.ts +++ b/packages/react-shared/src/utils/utils.ts @@ -33,6 +33,28 @@ export const utils = { convertDashesToSpaces(text: string): string { 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' }; + _.each(exceptions, (spaced, normal) => { + console.log(finalText, spaced, normal); + if (_.includes(finalText, spaced)) { + finalText = finalText.replace(spaced, normal); + } + }); + return finalText; + }, getEtherScanLinkIfExists( addressOrTxHash: string, networkId: number, |