Added class method formatAbsurdNumber

This commit is contained in:
Tesseract1234567890 2021-06-02 21:33:27 -04:00
parent 8fba3c3fa4
commit 75227233f3

@ -19,6 +19,7 @@ import 'numeral/locales/ru';
const extraFormats = [1e15, 1e18, 1e21, 1e24, 1e27, 1e30]; const extraFormats = [1e15, 1e18, 1e21, 1e24, 1e27, 1e30];
const extraNotations = ['q', 'Q', 's', 'S', 'o', 'n']; const extraNotations = ['q', 'Q', 's', 'S', 'o', 'n'];
class NumeralFormatter { class NumeralFormatter {
// Default Locale // Default Locale
defaultLocale = "en"; defaultLocale = "en";
@ -51,24 +52,26 @@ class NumeralFormatter {
return this.format(n, "0.000a"); return this.format(n, "0.000a");
} }
formatAbsurdNumber(n: number, decimalPlaces: string): string {
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.'+'0'.repeat(decimalPlaces))+extraNotations[i];
}
}
if(Math.abs(n) < 1000) {
return this.format(n, '0.'+'0'.repeat(decimalPlaces));
}
const str = this.format(n, '0.'+'0'.repeat(decimalPlaces) + 'a');
if(str === "NaNt") return this.format(n, '0.' + ' '.repeat(decimalPlaces) + 'e+0');
return str;
}
formatHp(n: number): string { formatHp(n: number): string {
return this.format(n, "0"); return this.format(n, "0");
} }
formatMoney(n: number): string { formatMoney(n: number): string {
if(numeral.options.currentLocale === "en") { return "$" + this.formatAbsurdNumber
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return '$'+this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "$0.00");
}
const str = this.format(n, "$0.000a");
if(str === "$NaNt") return '$'+this.format(n, '0.000e+0');
return str;
} }
formatSkill(n: number): string { formatSkill(n: number): string {
@ -76,51 +79,15 @@ class NumeralFormatter {
} }
formatExp(n: number): string { formatExp(n: number): string {
if(numeral.options.currentLocale === "en") { return this.formatAbsurdNumber(n, 3);
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatHashes(n: number): string { formatHashes(n: number): string {
if(numeral.options.currentLocale === "en") { return this.formatAbsurdNumber(n, 3);
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatReputation(n: number): string { formatReputation(n: number): string {
if(numeral.options.currentLocale === "en") { return this.formatAbsurdNumber(n, 3);
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatFavor(n: number): string { formatFavor(n: number): string {
@ -141,35 +108,11 @@ class NumeralFormatter {
} }
formatRespect(n: number): string { formatRespect(n: number): string {
if(numeral.options.currentLocale === "en") { return this.formatAbsurdNumber(n, 5);
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.00000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.00000");
}
const str = this.format(n, "0.00000a");
if(str === "NaNt") return this.format(n, '0.00000e+0');
return str;
} }
formatWanted(n: number): string { formatWanted(n: number): string {
if(numeral.options.currentLocale === "en") { return this.formatAbsurdNumber(n, 5);
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.00000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.00000");
}
const str = this.format(n, "0.00000a");
if(str === "NaNt") return this.format(n, '0.00000e+0');
return str;
} }
formatMultiplier(n: number): string { formatMultiplier(n: number): string {
@ -197,34 +140,11 @@ class NumeralFormatter {
} }
formatShares(n: number): string { formatShares(n: number): string {
if(numeral.options.currentLocale === "en") { return this.formatAbsurdNumber(n, 3);
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
} }
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str; }
formatInfiltrationSecurity(n: number): string { formatInfiltrationSecurity(n: number): string {
if(numeral.options.currentLocale === "en") { return this.formatAbsurdNumber(n, 3);
for(let i = 0; i < extraFormats.length; i++) {
if(extraFormats[i] < n && n <= extraFormats[i]*1000) {
return this.format(n/extraFormats[i], '0.000')+extraNotations[i];
}
}
}
if(Math.abs(n) < 1000) {
return this.format(n, "0.000");
}
const str = this.format(n, "0.000a");
if(str === "NaNt") return this.format(n, '0.000e+0');
return str;
} }
formatThreads(n: number): string { formatThreads(n: number): string {