mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
Use js-utility-belt's text utils
This commit is contained in:
parent
9e03ef2b90
commit
06c02ceecb
@ -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
|
||||
|
@ -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';
|
||||
|
||||
|
||||
/**
|
||||
|
2
js/utils/text.js
Normal file
2
js/utils/text.js
Normal file
@ -0,0 +1,2 @@
|
||||
// Re-export related utilities from js-utility-belt for easier access
|
||||
export { formatText, sprintf } from 'js-utility-belt/es6/text';
|
Loading…
Reference in New Issue
Block a user