diff --git a/js/utils/general.js b/js/utils/general.js index 7d7c1f96..cf6705e8 100644 --- a/js/utils/general.js +++ b/js/utils/general.js @@ -37,35 +37,7 @@ export function sumNumList(l) { return sum; } -/* - Taken from http://stackoverflow.com/a/4795914/1263876 - Behaves like C's format string function */ -export function formatText() { - let args = arguments, - string = args[0], - i = 1; - return string.replace(/%((%)|s|d)/g, (m) => { - // m is the matched format, e.g. %s, %d - let val = null; - if (m[2]) { - val = m[2]; - } else { - val = args[i]; - // A switch statement so that the formatter can be extended. Default is %s - switch (m) { - case '%d': - val = parseFloat(val); - if (isNaN(val)) { - val = 0; - } - break; - } - i++; - } - return val; - }); -} /** * Checks a list of objects for key duplicates and returns a boolean diff --git a/js/utils/lang.js b/js/utils/lang.js index 932fd28b..b204b741 100644 --- a/js/utils/lang.js +++ b/js/utils/lang.js @@ -2,7 +2,7 @@ import { getBrowserLang } from 'js-utility-belt/es6/lang'; import languages from '../constants/languages'; -import { formatText } from './general'; +import { formatText } from './text'; /** diff --git a/js/utils/text.js b/js/utils/text.js new file mode 100644 index 00000000..28483bd5 --- /dev/null +++ b/js/utils/text.js @@ -0,0 +1,2 @@ +// Re-export related utilities from js-utility-belt for easier access +export { formatText, sprintf } from 'js-utility-belt/es6/text';