Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ar to BigInt #116

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 12 additions & 21 deletions lib/i18n/ar.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import AbstractLanguage from '../classes/AbstractLanguage.js';

export class Arabic extends AbstractLanguage {
integerValue = 0;

decimalValue = 0;

number = 0;
number;

arabicOnes = [
'', 'واحد', 'اثنان', 'ثلاثة', 'أربعة', 'خمسة', 'ستة', 'سبعة', 'ثمانية',
@@ -61,24 +57,22 @@ export class Arabic extends AbstractLanguage {
const hundreds = groupNumber / 100;
let retVal = '';

if (Math.trunc(hundreds) > 0) {
retVal = (
tens == 0 && Math.trunc(hundreds) == 2
) ? this.arabicAppendedTwos[0] : this.arabicHundreds[Math.trunc(hundreds)];
if (hundreds > 0) {
retVal = (tens == 0 && Math.trunc(hundreds) == 2 ? this.arabicAppendedTwos[0] : this.arabicHundreds[Math.trunc(hundreds)]);
}

if (tens > 0) {
if (tens < 20) {
if (tens == 2 && Math.trunc(hundreds) == 0 && groupLevel > 0) {
retVal = ([
2000, 2000000, 2000000000, 2000000000000, 2000000000000000, 2000000000000000000
].indexOf(this.integerValue) != -1) ? this.arabicAppendedTwos[
Math.trunc(groupLevel)] : this.arabicTwos[Math.trunc(groupLevel)
];
].indexOf(this.number) != -1) ? this.arabicAppendedTwos[groupLevel] : this.arabicTwos[groupLevel];
} else {
// Add divider
if (retVal != '') {
retVal += ' و ';
}

if (tens == 1 && groupLevel > 0 && hundreds == 0) {
retVal += '';
} else if (
@@ -114,23 +108,20 @@ export class Arabic extends AbstractLanguage {
}

toCardinal(number) {
/** @todo Convert class to work with BigInt */
number = Number(number);

if (number == 0) {
return this.zero;
}

this.number = number;
let tempNumber = number;
this.integerValue = number;
let retVal = '';
let group = 0;
let retVal = '';

while (tempNumber > 0) {
const numberToProcess = tempNumber % 1000;
tempNumber = Math.trunc(tempNumber / 1000);
const numberToProcess = Number(tempNumber % 1000n); // Maximum: 807
tempNumber = tempNumber / 1000n;

const groupDescription = this.processArabicGroup(numberToProcess, group, Math.floor(tempNumber));
const groupDescription = this.processArabicGroup(numberToProcess, group, tempNumber);

if (groupDescription != '') {
if (group > 0) {
@@ -158,7 +149,7 @@ export class Arabic extends AbstractLanguage {
retVal = groupDescription + ' ' + retVal;
}

group += 1;
group++;
}

return retVal.trim();
20 changes: 4 additions & 16 deletions lib/i18n/ru.js
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ export class N2WordsRU extends AbstractLanguage {
return words.join(' ');
}

splitByX(n, x, formatInt = true) {
splitByX(n, x) {
const results = [];
const l = n.length;
let result;
@@ -153,28 +153,16 @@ export class N2WordsRU extends AbstractLanguage {
if (start > 0) {
result = n.slice(0, start);

if (formatInt) {
results.push(BigInt(result));
} else {
results.push(result);
}
results.push(BigInt(result));
}

for (let i = start; i < l; i += x) {
result = n.slice(i, i + x);

if (formatInt) {
results.push(BigInt(result));
} else {
results.push(result);
}
results.push(BigInt(result));
}
} else {
if (formatInt) {
results.push(BigInt(n));
} else {
results.push(n);
}
results.push(BigInt(n));
}

return results;
92 changes: 46 additions & 46 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@
"ava": "^5.3.0",
"babel-loader": "^9.1.2",
"benchmark": "^2.1.4",
"c8": "^7.14.0",
"c8": "^8.0.0",
"chalk": "^5.2.0",
"chromedriver": "^114.0.2",
"core-js": "^3.31.0",
@@ -107,7 +107,7 @@
"eslint-plugin-node": "^11.1.0",
"microtime": "^3.1.1",
"selenium-webdriver": "^4.10.0",
"webpack": "^5.86.0",
"webpack": "^5.87.0",
"webpack-cli": "^5.1.4"
},
"engines": {