Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@coingecko/cryptoformat

Package Overview
Dependencies
Maintainers
4
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coingecko/cryptoformat - npm Package Compare versions

Comparing version
0.8.1
to
0.8.2
+11
-5
lib/cryptoformat.cjs.js

@@ -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 @@

{
"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",