lion/packages/localize/src/number/forceCurrencyToEnd.js
Joren Broekema 09d9675963 feat(localize): add types to localize
Co-authored-by: narzac <narzac@gmail.com>
2020-08-03 17:00:26 +02:00

21 lines
831 B
JavaScript

/**
* For Dutch and Belgian amounts the currency should be at the end of the string
*
* @typedef {import('../../types/LocalizeMixinTypes').FormatNumberPart} FormatNumberPart
* @param {FormatNumberPart[]} formattedParts
* @returns {FormatNumberPart[]}
*/
export function forceCurrencyToEnd(formattedParts) {
if (formattedParts[0].type === 'currency') {
const moveCur = formattedParts.splice(0, 1);
const moveLit = formattedParts.splice(0, 1);
formattedParts.push(moveLit[0]);
formattedParts.push(moveCur[0]);
} else if (formattedParts[0].type === 'minusSign' && formattedParts[1].type === 'currency') {
const moveCur = formattedParts.splice(1, 1);
const moveLit = formattedParts.splice(1, 1);
formattedParts.push(moveLit[0]);
formattedParts.push(moveCur[0]);
}
return formattedParts;
}