@coingecko/cryptoformat
Advanced tools
+71
-19
@@ -7,3 +7,3 @@ 'use strict'; | ||
| const supportedCurrencySymbols = { | ||
| BTC: "Ƀ", | ||
| BTC: "₿", | ||
| ETH: "Ξ", | ||
@@ -65,3 +65,7 @@ USD: "$", | ||
| function IntlNumberFormatSupported() { | ||
| return !!(typeof Intl == "object" && Intl && typeof Intl.NumberFormat == "function"); | ||
| return !!( | ||
| typeof Intl == "object" && | ||
| Intl && | ||
| typeof Intl.NumberFormat == "function" | ||
| ); | ||
| } | ||
@@ -86,4 +90,11 @@ | ||
| const overrideObj = symbolOverrides[code]; | ||
| if (overrideObj && overrideObj.location.start && overrideObj.forLocales[locale]) { | ||
| return formattedCurrency.replace(currencyCodeFrontMatch[0], supportedCurrencySymbols[code]); | ||
| if ( | ||
| overrideObj && | ||
| overrideObj.location.start && | ||
| overrideObj.forLocales[locale] | ||
| ) { | ||
| return formattedCurrency.replace( | ||
| currencyCodeFrontMatch[0], | ||
| supportedCurrencySymbols[code] | ||
| ); | ||
| } else { | ||
@@ -101,3 +112,7 @@ return formattedCurrency; | ||
| const overrideObj = symbolOverrides[code]; | ||
| if (overrideObj && overrideObj.location.end && overrideObj.forLocales[locale]) { | ||
| if ( | ||
| overrideObj && | ||
| overrideObj.location.end && | ||
| overrideObj.forLocales[locale] | ||
| ) { | ||
| return formattedCurrency.replace(code, supportedCurrencySymbols[code]); | ||
@@ -205,6 +220,10 @@ } else { | ||
| formattersCache[cacheKey].currencyFormatterNormal = currencyFormatterNormal; | ||
| formattersCache[cacheKey].currencyFormatterNoDecimal = currencyFormatterNoDecimal; | ||
| formattersCache[ | ||
| cacheKey | ||
| ].currencyFormatterNoDecimal = currencyFormatterNoDecimal; | ||
| formattersCache[cacheKey].currencyFormatterMedium = currencyFormatterMedium; | ||
| formattersCache[cacheKey].currencyFormatterSmall = currencyFormatterSmall; | ||
| formattersCache[cacheKey].currencyFormatterVerySmall = currencyFormatterVerySmall; | ||
| formattersCache[ | ||
| cacheKey | ||
| ].currencyFormatterVerySmall = currencyFormatterVerySmall; | ||
| } | ||
@@ -240,15 +259,33 @@ } | ||
| if (amount === 0.0) { | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price >= LARGE_CRYPTO_THRESHOLD) { | ||
| // Large crypto amount, show no decimal value | ||
| return formatCurrencyOverride(currencyFormatterNoDecimal.format(amount), locale); | ||
| } else if (price >= MEDIUM_CRYPTO_THRESHOLD && price < LARGE_CRYPTO_THRESHOLD) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNoDecimal.format(amount), | ||
| locale | ||
| ); | ||
| } else if ( | ||
| price >= MEDIUM_CRYPTO_THRESHOLD && | ||
| price < LARGE_CRYPTO_THRESHOLD | ||
| ) { | ||
| // Medium crypto amount, show 3 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterMedium.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterMedium.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price >= 1.0 && price < MEDIUM_CRYPTO_THRESHOLD) { | ||
| // crypto amount, show 6 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterSmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterSmall.format(amount), | ||
| locale | ||
| ); | ||
| } else { | ||
| // Crypto amount < 1, show 8 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterVerySmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVerySmall.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -267,12 +304,27 @@ } else { | ||
| if (amount === 0.0) { | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount < 0.05) { | ||
| return formatCurrencyOverride(currencyFormatterVerySmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVerySmall.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount < 1.0) { | ||
| return formatCurrencyOverride(currencyFormatterSmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterSmall.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount > 20000) { | ||
| return formatCurrencyOverride(currencyFormatterNoDecimal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNoDecimal.format(amount), | ||
| locale | ||
| ); | ||
| } else { | ||
| // Let the formatter do what it seems best. In particular, we should not set any fraction amount for Japanese Yen | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -282,4 +334,4 @@ } | ||
| exports.isCrypto = isCrypto; | ||
| exports.clearCache = clearCache; | ||
| exports.formatCurrency = formatCurrency; | ||
| exports.isCrypto = isCrypto; |
+71
-19
| // A map of supported currency codes to currency symbols. | ||
| const supportedCurrencySymbols = { | ||
| BTC: "Ƀ", | ||
| BTC: "₿", | ||
| ETH: "Ξ", | ||
@@ -60,3 +60,7 @@ USD: "$", | ||
| function IntlNumberFormatSupported() { | ||
| return !!(typeof Intl == "object" && Intl && typeof Intl.NumberFormat == "function"); | ||
| return !!( | ||
| typeof Intl == "object" && | ||
| Intl && | ||
| typeof Intl.NumberFormat == "function" | ||
| ); | ||
| } | ||
@@ -81,4 +85,11 @@ | ||
| const overrideObj = symbolOverrides[code]; | ||
| if (overrideObj && overrideObj.location.start && overrideObj.forLocales[locale]) { | ||
| return formattedCurrency.replace(currencyCodeFrontMatch[0], supportedCurrencySymbols[code]); | ||
| if ( | ||
| overrideObj && | ||
| overrideObj.location.start && | ||
| overrideObj.forLocales[locale] | ||
| ) { | ||
| return formattedCurrency.replace( | ||
| currencyCodeFrontMatch[0], | ||
| supportedCurrencySymbols[code] | ||
| ); | ||
| } else { | ||
@@ -96,3 +107,7 @@ return formattedCurrency; | ||
| const overrideObj = symbolOverrides[code]; | ||
| if (overrideObj && overrideObj.location.end && overrideObj.forLocales[locale]) { | ||
| if ( | ||
| overrideObj && | ||
| overrideObj.location.end && | ||
| overrideObj.forLocales[locale] | ||
| ) { | ||
| return formattedCurrency.replace(code, supportedCurrencySymbols[code]); | ||
@@ -200,6 +215,10 @@ } else { | ||
| formattersCache[cacheKey].currencyFormatterNormal = currencyFormatterNormal; | ||
| formattersCache[cacheKey].currencyFormatterNoDecimal = currencyFormatterNoDecimal; | ||
| formattersCache[ | ||
| cacheKey | ||
| ].currencyFormatterNoDecimal = currencyFormatterNoDecimal; | ||
| formattersCache[cacheKey].currencyFormatterMedium = currencyFormatterMedium; | ||
| formattersCache[cacheKey].currencyFormatterSmall = currencyFormatterSmall; | ||
| formattersCache[cacheKey].currencyFormatterVerySmall = currencyFormatterVerySmall; | ||
| formattersCache[ | ||
| cacheKey | ||
| ].currencyFormatterVerySmall = currencyFormatterVerySmall; | ||
| } | ||
@@ -235,15 +254,33 @@ } | ||
| if (amount === 0.0) { | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price >= LARGE_CRYPTO_THRESHOLD) { | ||
| // Large crypto amount, show no decimal value | ||
| return formatCurrencyOverride(currencyFormatterNoDecimal.format(amount), locale); | ||
| } else if (price >= MEDIUM_CRYPTO_THRESHOLD && price < LARGE_CRYPTO_THRESHOLD) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNoDecimal.format(amount), | ||
| locale | ||
| ); | ||
| } else if ( | ||
| price >= MEDIUM_CRYPTO_THRESHOLD && | ||
| price < LARGE_CRYPTO_THRESHOLD | ||
| ) { | ||
| // Medium crypto amount, show 3 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterMedium.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterMedium.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price >= 1.0 && price < MEDIUM_CRYPTO_THRESHOLD) { | ||
| // crypto amount, show 6 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterSmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterSmall.format(amount), | ||
| locale | ||
| ); | ||
| } else { | ||
| // Crypto amount < 1, show 8 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterVerySmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVerySmall.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -262,12 +299,27 @@ } else { | ||
| if (amount === 0.0) { | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount < 0.05) { | ||
| return formatCurrencyOverride(currencyFormatterVerySmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVerySmall.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount < 1.0) { | ||
| return formatCurrencyOverride(currencyFormatterSmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterSmall.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount > 20000) { | ||
| return formatCurrencyOverride(currencyFormatterNoDecimal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNoDecimal.format(amount), | ||
| locale | ||
| ); | ||
| } else { | ||
| // Let the formatter do what it seems best. In particular, we should not set any fraction amount for Japanese Yen | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -277,2 +329,2 @@ } | ||
| export { isCrypto, clearCache, formatCurrency }; | ||
| export { clearCache, formatCurrency, isCrypto }; |
+71
-19
@@ -9,3 +9,3 @@ (function (global, factory) { | ||
| const supportedCurrencySymbols = { | ||
| BTC: "Ƀ", | ||
| BTC: "₿", | ||
| ETH: "Ξ", | ||
@@ -67,3 +67,7 @@ USD: "$", | ||
| function IntlNumberFormatSupported() { | ||
| return !!(typeof Intl == "object" && Intl && typeof Intl.NumberFormat == "function"); | ||
| return !!( | ||
| typeof Intl == "object" && | ||
| Intl && | ||
| typeof Intl.NumberFormat == "function" | ||
| ); | ||
| } | ||
@@ -88,4 +92,11 @@ | ||
| const overrideObj = symbolOverrides[code]; | ||
| if (overrideObj && overrideObj.location.start && overrideObj.forLocales[locale]) { | ||
| return formattedCurrency.replace(currencyCodeFrontMatch[0], supportedCurrencySymbols[code]); | ||
| if ( | ||
| overrideObj && | ||
| overrideObj.location.start && | ||
| overrideObj.forLocales[locale] | ||
| ) { | ||
| return formattedCurrency.replace( | ||
| currencyCodeFrontMatch[0], | ||
| supportedCurrencySymbols[code] | ||
| ); | ||
| } else { | ||
@@ -103,3 +114,7 @@ return formattedCurrency; | ||
| const overrideObj = symbolOverrides[code]; | ||
| if (overrideObj && overrideObj.location.end && overrideObj.forLocales[locale]) { | ||
| if ( | ||
| overrideObj && | ||
| overrideObj.location.end && | ||
| overrideObj.forLocales[locale] | ||
| ) { | ||
| return formattedCurrency.replace(code, supportedCurrencySymbols[code]); | ||
@@ -207,6 +222,10 @@ } else { | ||
| formattersCache[cacheKey].currencyFormatterNormal = currencyFormatterNormal; | ||
| formattersCache[cacheKey].currencyFormatterNoDecimal = currencyFormatterNoDecimal; | ||
| formattersCache[ | ||
| cacheKey | ||
| ].currencyFormatterNoDecimal = currencyFormatterNoDecimal; | ||
| formattersCache[cacheKey].currencyFormatterMedium = currencyFormatterMedium; | ||
| formattersCache[cacheKey].currencyFormatterSmall = currencyFormatterSmall; | ||
| formattersCache[cacheKey].currencyFormatterVerySmall = currencyFormatterVerySmall; | ||
| formattersCache[ | ||
| cacheKey | ||
| ].currencyFormatterVerySmall = currencyFormatterVerySmall; | ||
| } | ||
@@ -242,15 +261,33 @@ } | ||
| if (amount === 0.0) { | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price >= LARGE_CRYPTO_THRESHOLD) { | ||
| // Large crypto amount, show no decimal value | ||
| return formatCurrencyOverride(currencyFormatterNoDecimal.format(amount), locale); | ||
| } else if (price >= MEDIUM_CRYPTO_THRESHOLD && price < LARGE_CRYPTO_THRESHOLD) { | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNoDecimal.format(amount), | ||
| locale | ||
| ); | ||
| } else if ( | ||
| price >= MEDIUM_CRYPTO_THRESHOLD && | ||
| price < LARGE_CRYPTO_THRESHOLD | ||
| ) { | ||
| // Medium crypto amount, show 3 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterMedium.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterMedium.format(amount), | ||
| locale | ||
| ); | ||
| } else if (price >= 1.0 && price < MEDIUM_CRYPTO_THRESHOLD) { | ||
| // crypto amount, show 6 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterSmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterSmall.format(amount), | ||
| locale | ||
| ); | ||
| } else { | ||
| // Crypto amount < 1, show 8 fraction digits | ||
| return formatCurrencyOverride(currencyFormatterVerySmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVerySmall.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -269,12 +306,27 @@ } else { | ||
| if (amount === 0.0) { | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount < 0.05) { | ||
| return formatCurrencyOverride(currencyFormatterVerySmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterVerySmall.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount < 1.0) { | ||
| return formatCurrencyOverride(currencyFormatterSmall.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterSmall.format(amount), | ||
| locale | ||
| ); | ||
| } else if (amount > 20000) { | ||
| return formatCurrencyOverride(currencyFormatterNoDecimal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNoDecimal.format(amount), | ||
| locale | ||
| ); | ||
| } else { | ||
| // Let the formatter do what it seems best. In particular, we should not set any fraction amount for Japanese Yen | ||
| return formatCurrencyOverride(currencyFormatterNormal.format(amount), locale); | ||
| return formatCurrencyOverride( | ||
| currencyFormatterNormal.format(amount), | ||
| locale | ||
| ); | ||
| } | ||
@@ -284,5 +336,5 @@ } | ||
| exports.isCrypto = isCrypto; | ||
| exports.clearCache = clearCache; | ||
| exports.formatCurrency = formatCurrency; | ||
| exports.isCrypto = isCrypto; | ||
@@ -289,0 +341,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
+10
-10
| { | ||
| "name": "@coingecko/cryptoformat", | ||
| "version": "0.3.2", | ||
| "version": "0.3.3", | ||
| "description": "Javascript library to format and display cryptocurrencies and fiat", | ||
@@ -25,11 +25,11 @@ "main": "lib/cryptoformat.cjs.js", | ||
| "devDependencies": { | ||
| "@babel/core": "^7.2.2", | ||
| "@babel/preset-env": "^7.3.1", | ||
| "babel-jest": "^24.1.0", | ||
| "jest": "^24.1.0", | ||
| "regenerator-runtime": "^0.13.1", | ||
| "rollup": "^1.1.2", | ||
| "rollup-plugin-commonjs": "^9.2.0", | ||
| "rollup-plugin-copy": "^0.2.3", | ||
| "rollup-plugin-node-resolve": "^4.0.0" | ||
| "@babel/core": "^7.6.2", | ||
| "@babel/preset-env": "^7.6.2", | ||
| "babel-jest": "^24.9.0", | ||
| "jest": "^24.9.0", | ||
| "regenerator-runtime": "^0.13.3", | ||
| "rollup": "^1.22.0", | ||
| "rollup-plugin-commonjs": "^10.1.0", | ||
| "rollup-plugin-copy": "^3.1.0", | ||
| "rollup-plugin-node-resolve": "^5.2.0" | ||
| }, | ||
@@ -36,0 +36,0 @@ "types": "lib/index.d.ts", |
33199
3.81%911
20.66%