aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-shared/src/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-08-23 06:44:46 +0800
committerFabio Berger <me@fabioberger.com>2018-08-23 06:44:46 +0800
commit27d329ff2559c643b54489d0796bb2c2fcda264f (patch)
tree93b47dd6aef43f063f12c7c3882cafc9b30acb1d /packages/react-shared/src/utils
parenta6cdc38d532b897442bac74bc3fd1735c85317ba (diff)
downloaddexon-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/src/utils')
-rw-r--r--packages/react-shared/src/utils/utils.ts21
1 files changed, 2 insertions, 19 deletions
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,