feat(nestjs): migrate to NestJS

This commit is contained in:
Ahmed Bouhuolia
2025-04-07 11:51:24 +02:00
parent f068218a16
commit 55fcc908ef
3779 changed files with 631 additions and 195332 deletions

View File

@@ -0,0 +1,67 @@
import { get } from 'lodash';
import * as accounting from 'accounting';
import * as Currencies from 'js-money/lib/currency';
const getNegativeFormat = (formatName) => {
switch (formatName) {
case 'parentheses':
return '(%s%v)';
case 'mines':
return '-%s%v';
}
};
const getCurrencySign = (currencyCode) => {
return get(Currencies, `${currencyCode}.symbol`);
};
export interface IFormatNumberSettings {
precision?: number;
divideOn1000?: boolean;
excerptZero?: boolean;
negativeFormat?: string;
thousand?: string;
decimal?: string;
zeroSign?: string;
money?: boolean;
currencyCode?: string;
symbol?: string;
}
export const formatNumber = (
balance,
{
precision = 2,
divideOn1000 = false,
excerptZero = false,
negativeFormat = 'mines',
thousand = ',',
decimal = '.',
zeroSign = '',
money = true,
currencyCode,
symbol = '',
}: IFormatNumberSettings,
) => {
const formattedSymbol = getCurrencySign(currencyCode);
const negForamt = getNegativeFormat(negativeFormat);
const format = '%s%v';
let formattedBalance = parseFloat(balance);
if (divideOn1000) {
formattedBalance /= 1000;
}
return accounting.formatMoney(
formattedBalance,
money ? formattedSymbol : symbol ? symbol : '',
precision,
thousand,
decimal,
{
pos: format,
neg: negForamt,
zero: excerptZero ? zeroSign : format,
},
);
};