@coingecko/cryptoformat
Advanced tools
@@ -188,2 +188,4 @@ 'use strict'; | ||
| let currencyFormatterVeryVerySmall; | ||
| let currencyFormatter15DP; | ||
| let currencyFormatter18DP; | ||
@@ -223,2 +225,8 @@ // If a page has to display multiple currencies, formatters would have to be created for each of them | ||
| : generateFormatter(isoCode, locale, 12); | ||
| currencyFormatter15DP = cachedFormatter | ||
| ? cachedFormatter.currencyFormatter15DP | ||
| : generateFormatter(isoCode, locale, 15); | ||
| currencyFormatter18DP = cachedFormatter | ||
| ? cachedFormatter.currencyFormatter18DP | ||
| : generateFormatter(isoCode, locale, 18); | ||
@@ -235,2 +243,4 @@ // Save in cache | ||
| formattersCache[cacheKey].currencyFormatterVeryVerySmall = currencyFormatterVeryVerySmall; | ||
| formattersCache[cacheKey].currencyFormatter15DP = currencyFormatter15DP; | ||
| formattersCache[cacheKey].currencyFormatter18DP = currencyFormatter18DP; | ||
| } | ||
@@ -351,4 +361,3 @@ } | ||
| ); | ||
| } else { | ||
| // Crypto amount < 0.000001, show 12 fraction digits | ||
| } else if (price >= 10**-9 && price < 10**-6) { | ||
| return formatCurrencyOverride( | ||
@@ -358,2 +367,12 @@ currencyFormatterVeryVerySmall.format(amount), | ||
| ); | ||
| } else if (price >= 10**-12 && price < 10**-9) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter15DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price < 10**-12) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter18DP.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -363,5 +382,9 @@ } else { | ||
| if (raw) { | ||
| if (unsigned_amount < 0.00001) { | ||
| if (unsigned_amount < 10**-12) { | ||
| return amount.toFixed(18); | ||
| } else if (unsigned_amount < 10**-9) { | ||
| return amount.toFixed(15); | ||
| } else if (unsigned_amount < 10**-6) { | ||
| return amount.toFixed(12); | ||
| } else if (unsigned_amount < 0.001) { | ||
| } else if (unsigned_amount < 10**-3) { | ||
| return amount.toFixed(8); | ||
@@ -380,4 +403,14 @@ } else if (unsigned_amount < 1.0) { | ||
| ); | ||
| } else if (unsigned_amount < 0.000001) { | ||
| } else if (unsigned_amount < 10**-12) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter18DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (unsigned_amount < 10**-9) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter15DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (unsigned_amount < 10**-6) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVeryVerySmall.format(amount), | ||
@@ -384,0 +417,0 @@ locale |
@@ -184,2 +184,4 @@ // A map of supported currency codes to currency symbols. | ||
| let currencyFormatterVeryVerySmall; | ||
| let currencyFormatter15DP; | ||
| let currencyFormatter18DP; | ||
@@ -219,2 +221,8 @@ // If a page has to display multiple currencies, formatters would have to be created for each of them | ||
| : generateFormatter(isoCode, locale, 12); | ||
| currencyFormatter15DP = cachedFormatter | ||
| ? cachedFormatter.currencyFormatter15DP | ||
| : generateFormatter(isoCode, locale, 15); | ||
| currencyFormatter18DP = cachedFormatter | ||
| ? cachedFormatter.currencyFormatter18DP | ||
| : generateFormatter(isoCode, locale, 18); | ||
@@ -231,2 +239,4 @@ // Save in cache | ||
| formattersCache[cacheKey].currencyFormatterVeryVerySmall = currencyFormatterVeryVerySmall; | ||
| formattersCache[cacheKey].currencyFormatter15DP = currencyFormatter15DP; | ||
| formattersCache[cacheKey].currencyFormatter18DP = currencyFormatter18DP; | ||
| } | ||
@@ -347,4 +357,3 @@ } | ||
| ); | ||
| } else { | ||
| // Crypto amount < 0.000001, show 12 fraction digits | ||
| } else if (price >= 10**-9 && price < 10**-6) { | ||
| return formatCurrencyOverride( | ||
@@ -354,2 +363,12 @@ currencyFormatterVeryVerySmall.format(amount), | ||
| ); | ||
| } else if (price >= 10**-12 && price < 10**-9) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter15DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price < 10**-12) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter18DP.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -359,5 +378,9 @@ } else { | ||
| if (raw) { | ||
| if (unsigned_amount < 0.00001) { | ||
| if (unsigned_amount < 10**-12) { | ||
| return amount.toFixed(18); | ||
| } else if (unsigned_amount < 10**-9) { | ||
| return amount.toFixed(15); | ||
| } else if (unsigned_amount < 10**-6) { | ||
| return amount.toFixed(12); | ||
| } else if (unsigned_amount < 0.001) { | ||
| } else if (unsigned_amount < 10**-3) { | ||
| return amount.toFixed(8); | ||
@@ -376,4 +399,14 @@ } else if (unsigned_amount < 1.0) { | ||
| ); | ||
| } else if (unsigned_amount < 0.000001) { | ||
| } else if (unsigned_amount < 10**-12) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter18DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (unsigned_amount < 10**-9) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter15DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (unsigned_amount < 10**-6) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVeryVerySmall.format(amount), | ||
@@ -380,0 +413,0 @@ locale |
@@ -190,2 +190,4 @@ (function (global, factory) { | ||
| let currencyFormatterVeryVerySmall; | ||
| let currencyFormatter15DP; | ||
| let currencyFormatter18DP; | ||
@@ -225,2 +227,8 @@ // If a page has to display multiple currencies, formatters would have to be created for each of them | ||
| : generateFormatter(isoCode, locale, 12); | ||
| currencyFormatter15DP = cachedFormatter | ||
| ? cachedFormatter.currencyFormatter15DP | ||
| : generateFormatter(isoCode, locale, 15); | ||
| currencyFormatter18DP = cachedFormatter | ||
| ? cachedFormatter.currencyFormatter18DP | ||
| : generateFormatter(isoCode, locale, 18); | ||
@@ -237,2 +245,4 @@ // Save in cache | ||
| formattersCache[cacheKey].currencyFormatterVeryVerySmall = currencyFormatterVeryVerySmall; | ||
| formattersCache[cacheKey].currencyFormatter15DP = currencyFormatter15DP; | ||
| formattersCache[cacheKey].currencyFormatter18DP = currencyFormatter18DP; | ||
| } | ||
@@ -353,4 +363,3 @@ } | ||
| ); | ||
| } else { | ||
| // Crypto amount < 0.000001, show 12 fraction digits | ||
| } else if (price >= 10**-9 && price < 10**-6) { | ||
| return formatCurrencyOverride( | ||
@@ -360,2 +369,12 @@ currencyFormatterVeryVerySmall.format(amount), | ||
| ); | ||
| } else if (price >= 10**-12 && price < 10**-9) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter15DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price < 10**-12) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter18DP.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -365,5 +384,9 @@ } else { | ||
| if (raw) { | ||
| if (unsigned_amount < 0.00001) { | ||
| if (unsigned_amount < 10**-12) { | ||
| return amount.toFixed(18); | ||
| } else if (unsigned_amount < 10**-9) { | ||
| return amount.toFixed(15); | ||
| } else if (unsigned_amount < 10**-6) { | ||
| return amount.toFixed(12); | ||
| } else if (unsigned_amount < 0.001) { | ||
| } else if (unsigned_amount < 10**-3) { | ||
| return amount.toFixed(8); | ||
@@ -382,4 +405,14 @@ } else if (unsigned_amount < 1.0) { | ||
| ); | ||
| } else if (unsigned_amount < 0.000001) { | ||
| } else if (unsigned_amount < 10**-12) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter18DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (unsigned_amount < 10**-9) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatter15DP.format(amount), | ||
| locale | ||
| ); | ||
| } else if (unsigned_amount < 10**-6) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVeryVerySmall.format(amount), | ||
@@ -386,0 +419,0 @@ locale |
+1
-1
| { | ||
| "name": "@coingecko/cryptoformat", | ||
| "version": "0.4.4", | ||
| "version": "0.5.4", | ||
| "description": "Javascript library to format and display cryptocurrencies and fiat", | ||
@@ -5,0 +5,0 @@ "main": "lib/cryptoformat.cjs.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
46914
8.57%1257
8.55%1
Infinity%