Skip to content

Commit

Permalink
feat(format): add 'fullPostfix' to json output
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadanaraki committed Jul 2, 2024
1 parent 2fd902d commit 20650f7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/format/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface FormattedObject {
value?: string;
prefix: string;
postfix: string;
fullPostfix?: string;
sign: string;
wholeNumber: string;
}
Expand Down Expand Up @@ -381,6 +382,26 @@ class NumberFormatter {
Qt: ' میلیون همت',
};

const fullScaleUnits = template.match(/^(number|percent)$/g)
? {
'': '',
K: ' هزار',
M: ' میلیون',
B: ' میلیارد',
T: ' تریلیون',
Qd: ' کادریلیون',
Qt: ' کنتیلیون',
}
: {
'': '',
K: ' هزار تومان',
M: ' میلیون تومان',
B: ' میلیارد تومان',
T: ' هزار میلیارد تومان',
Qd: ' کادریلیون تومان',
Qt: ' کنتیلیون تومان',
};

let parts = /^(-)?(\d+)\.?([0]*)(\d*)$/g.exec(numberString);

if (!parts) {
Expand Down Expand Up @@ -556,6 +577,12 @@ class NumberFormatter {
return String(scaleUnits[c as keyof typeof scaleUnits]);
});

formattedObject.fullPostfix = unitPostfix
.replace(/[0-9]/g, c => String.fromCharCode(c.charCodeAt(0) + 1728))
.replace(/(K|M|B|T|Qt|Qd)/g, function (c: string) {
return String(fullScaleUnits[c as keyof typeof fullScaleUnits]);
});

formattedObject.postfix = formattedObject.postfix
.replace(/[0-9]/g, c => String.fromCharCode(c.charCodeAt(0) + 1728))
.replace(/(K|M|B|T|Qt|Qd)/g, function (c: string) {
Expand Down

0 comments on commit 20650f7

Please sign in to comment.