diff --git a/website/client/src/filters/localizeNumber.js b/website/client/src/filters/localizeNumber.js index c4e6fd03e9..4e7e63d7df 100644 --- a/website/client/src/filters/localizeNumber.js +++ b/website/client/src/filters/localizeNumber.js @@ -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, ); }