first commit

This commit is contained in:
Samandar Turgunboyev
2025-10-18 17:14:59 +05:00
parent edf364b389
commit 036a36ce90
92 changed files with 14614 additions and 135 deletions

View File

@@ -1,32 +1,38 @@
import i18n from '@/shared/config/i18n';
import { LanguageRoutes } from '@/shared/config/i18n/type';
import i18n from "@/shared/config/i18n";
import { LanguageRoutes } from "@/shared/config/i18n/type";
/**
* Format price. With label.
* @param amount Price
* @param withLabel Show label. Default false
* @returns string. Ex. X XXX XXX sum
* @returns string. Ex. 1 000 000 som
*/
const formatPrice = (amount: number | string, withLabel?: boolean) => {
const formatPrice = (amount: number | string, withLabel = false): string => {
const locale = i18n.language;
const label = withLabel
? locale == LanguageRoutes.RU
? ' сум'
: locale == LanguageRoutes.KI
? ' сўм'
: ' som'
: '';
const parts = String(amount).split('.');
const dollars = parts[0];
const cents = parts.length > 1 ? parts[1] : '00';
? locale === LanguageRoutes.RU
? " сум"
: locale === LanguageRoutes.UZ
? " сўм"
: " som"
: "";
const formattedDollars = dollars.replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
// Agar qiymat bosh yoki 0 bolsa — hech narsa korsatmaymiz
if (
amount === "" ||
amount === null ||
amount === undefined ||
Number(amount) === 0
)
return "";
if (String(amount).length == 0) {
return formattedDollars + '.' + cents + label;
} else {
return formattedDollars + label;
}
// Faqat raqamlarni qoldiramiz
const numeric = String(amount).replace(/\D/g, "");
// Raqamni 3 xonadan ajratamiz
const formatted = numeric.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
return formatted + label;
};
export default formatPrice;