@coingecko/cryptoformat
Advanced tools
@@ -155,3 +155,3 @@ 'use strict'; | ||
| // Use primitive fallback | ||
| return generateFallbackFormatter(isoCode, locale, numDecimals); | ||
| return generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig); | ||
| } | ||
@@ -161,3 +161,3 @@ } | ||
| // Generates a primitive fallback formatter with no symbol support. | ||
| function generateFallbackFormatter(isoCode, locale, numDecimals = 2) { | ||
| function generateFallbackFormatter(isoCode, locale, numDecimals = 2, maximumSignificantDigits = 4) { | ||
| isoCode = isoCode.toUpperCase(); | ||
@@ -176,5 +176,11 @@ | ||
| format: (value) => { | ||
| let formattedValue = value; | ||
| // try using Intl.NumberFormat when possible to support max significant digits | ||
| try { | ||
| formattedValue = new Intl.NumberFormat(locale, { maximumSignificantDigits }).format(value); | ||
| } catch (e) {} | ||
| return isCrypto(isoCode) | ||
| ? `${value.toLocaleString(locale)} ${isoCode}` | ||
| : `${isoCode} ${value.toLocaleString(locale)}`; | ||
| ? `${formattedValue.toLocaleString(locale)} ${isoCode}` | ||
| : `${isoCode} ${formattedValue.toLocaleString(locale)}`; | ||
| }, | ||
@@ -209,3 +215,3 @@ }; | ||
| ? generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig) | ||
| : generateFallbackFormatter(isoCode, locale, numDecimals); | ||
| : generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig); | ||
| } | ||
@@ -212,0 +218,0 @@ |
@@ -151,3 +151,3 @@ // A map of supported currency codes to currency symbols. | ||
| // Use primitive fallback | ||
| return generateFallbackFormatter(isoCode, locale, numDecimals); | ||
| return generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig); | ||
| } | ||
@@ -157,3 +157,3 @@ } | ||
| // Generates a primitive fallback formatter with no symbol support. | ||
| function generateFallbackFormatter(isoCode, locale, numDecimals = 2) { | ||
| function generateFallbackFormatter(isoCode, locale, numDecimals = 2, maximumSignificantDigits = 4) { | ||
| isoCode = isoCode.toUpperCase(); | ||
@@ -172,5 +172,11 @@ | ||
| format: (value) => { | ||
| let formattedValue = value; | ||
| // try using Intl.NumberFormat when possible to support max significant digits | ||
| try { | ||
| formattedValue = new Intl.NumberFormat(locale, { maximumSignificantDigits }).format(value); | ||
| } catch (e) {} | ||
| return isCrypto(isoCode) | ||
| ? `${value.toLocaleString(locale)} ${isoCode}` | ||
| : `${isoCode} ${value.toLocaleString(locale)}`; | ||
| ? `${formattedValue.toLocaleString(locale)} ${isoCode}` | ||
| : `${isoCode} ${formattedValue.toLocaleString(locale)}`; | ||
| }, | ||
@@ -205,3 +211,3 @@ }; | ||
| ? generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig) | ||
| : generateFallbackFormatter(isoCode, locale, numDecimals); | ||
| : generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig); | ||
| } | ||
@@ -208,0 +214,0 @@ |
@@ -157,3 +157,3 @@ (function (global, factory) { | ||
| // Use primitive fallback | ||
| return generateFallbackFormatter(isoCode, locale, numDecimals); | ||
| return generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig); | ||
| } | ||
@@ -163,3 +163,3 @@ } | ||
| // Generates a primitive fallback formatter with no symbol support. | ||
| function generateFallbackFormatter(isoCode, locale, numDecimals = 2) { | ||
| function generateFallbackFormatter(isoCode, locale, numDecimals = 2, maximumSignificantDigits = 4) { | ||
| isoCode = isoCode.toUpperCase(); | ||
@@ -178,5 +178,11 @@ | ||
| format: (value) => { | ||
| let formattedValue = value; | ||
| // try using Intl.NumberFormat when possible to support max significant digits | ||
| try { | ||
| formattedValue = new Intl.NumberFormat(locale, { maximumSignificantDigits }).format(value); | ||
| } catch (e) {} | ||
| return isCrypto(isoCode) | ||
| ? `${value.toLocaleString(locale)} ${isoCode}` | ||
| : `${isoCode} ${value.toLocaleString(locale)}`; | ||
| ? `${formattedValue.toLocaleString(locale)} ${isoCode}` | ||
| : `${isoCode} ${formattedValue.toLocaleString(locale)}`; | ||
| }, | ||
@@ -211,3 +217,3 @@ }; | ||
| ? generateIntlNumberFormatter(isoCode, locale, numDecimals, numSigFig) | ||
| : generateFallbackFormatter(isoCode, locale, numDecimals); | ||
| : generateFallbackFormatter(isoCode, locale, numDecimals, numSigFig); | ||
| } | ||
@@ -214,0 +220,0 @@ |
+1
-1
| { | ||
| "name": "@coingecko/cryptoformat", | ||
| "version": "0.8.1", | ||
| "version": "0.8.2", | ||
| "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
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
56993
1.91%1450
1.05%1
Infinity%