mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 17:52:22 +00:00
* Finish localizeNumber ctch null - Incomplete null catch: accidentally called string replace on an array - Call lang resolution on array just incase service is passing valid lang array (linting hasn't been checked) * Got my local linter working
This commit is contained in:
parent
5b4cf5d158
commit
967cd1f47f
1 changed files with 19 additions and 6 deletions
|
|
@ -1,7 +1,21 @@
|
|||
// Lang resolution (passed into replace)
|
||||
const langRes = [
|
||||
// Strip beyond @ symbol to allow custom languages
|
||||
[/@(?:.+)$/, ''],
|
||||
// We use underscore, this mthd uses dash
|
||||
['_', '-'],
|
||||
];
|
||||
|
||||
// Lang resolution reducer
|
||||
const langReduce = (str, params) => str.replace(...params);
|
||||
|
||||
export default function localizeNumber (valIn, lang, optIn = {}) {
|
||||
// Extra catch just incase non number
|
||||
const val = (typeof valIn === 'number') ? valIn : parseFloat(valIn);
|
||||
|
||||
// Catch lang null
|
||||
const langCatch = (lang || []);
|
||||
|
||||
// Options Management
|
||||
const { toFixed } = optIn;
|
||||
const optOut = {};
|
||||
|
|
@ -11,12 +25,11 @@ export default function localizeNumber (valIn, lang, optIn = {}) {
|
|||
}
|
||||
|
||||
return val.toLocaleString(
|
||||
// Catch null just incase
|
||||
(lang || [])
|
||||
// Strip beyond @ symbol to allow custom languages
|
||||
.replace(/@(?:.+)$/, '')
|
||||
// We use underscore, this mthd uses dash
|
||||
.replace('_', '-'),
|
||||
langCatch instanceof Array
|
||||
// Must use map with array
|
||||
? langCatch.map(each => langRes.reduce(langReduce, each))
|
||||
// Parse to string as final backup
|
||||
: langRes.reduce(langReduce, langCatch.toString()),
|
||||
optOut,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue