### Install @coingecko/cryptoformat via npm Source: https://github.com/coingecko/cryptoformat/blob/master/README.md Use npm to install the cryptoformat package. This is the primary method for adding the library to your project. ```bash npm i @coingecko/cryptoformat ``` -------------------------------- ### Build and Deploy Cryptoformat Source: https://github.com/coingecko/cryptoformat/blob/master/README.md Commands for building the project and submitting a deployment. These are typically used during the development lifecycle. ```bash npm run build && npm run submit ``` -------------------------------- ### Format Currency Values with cryptoformat Source: https://github.com/coingecko/cryptoformat/blob/master/README.md Import and use the formatCurrency function to format numbers into currency strings. It supports specifying currency, locale, and options for raw output, decimal places, or significant figures. ```javascript import { formatCurrency } from "@coingecko/cryptoformat"; formatCurrency(123, "USD", "en"); // "$123.00" ``` ```javascript formatCurrency(0.00123, "USD", "en"); // "$0.00123000" ``` ```javascript // Provide raw = true to remove formatting and symbol formatCurrency(0.00123, "USD", "en", true); // "0.00123000" ``` ```javascript formatCurrency(123400, "IDR", "id"); // "Rp123.400" ``` ```javascript formatCurrency(123400, "EUR", "de"); // "123.400 €" ``` ```javascript // Provide noDecimal = true to explicitly remove decimal for numbers above > 1.0 formatCurrency(4000.23, "USD", "en", false, true); // "$4,000" ``` ```javascript // Provide number of decimal places or significant figures formatCurrency(1.234, "USD", "en", false, { decimalPlaces: 2 }); // "$1.23" ``` ```javascript formatCurrency(1234, "USD", "en", false, { significantFigures: 2 }); // "$1,200" ``` ```javascript // Provide number of significant figures only up to specified number of decimal places formatCurrency(0.1234, "USD", "en", false, { decimalPlaces: 2, significantFigures: 3 }); // "$0.12" ``` -------------------------------- ### Format currencies using formatCurrency Source: https://context7.com/coingecko/cryptoformat/llms.txt Use the formatCurrency function to convert numeric values into formatted strings based on the currency code and locale. It supports both major cryptocurrencies and various fiat currencies. ```javascript import { formatCurrency } from "@coingecko/cryptoformat"; // Cryptocurrencies with symbols formatCurrency(1, "BTC", "en"); // Output: "₿1.000000" formatCurrency(1, "ETH", "en"); // Output: "Ξ1.000000" // Major fiat currencies formatCurrency(100, "USD", "en"); // Output: "$100.00" formatCurrency(100, "EUR", "en"); // Output: "€100.00" formatCurrency(100, "GBP", "en"); // Output: "£100.00" formatCurrency(100, "JPY", "en"); // Output: "¥100" formatCurrency(100, "CNY", "en"); // Output: "CN¥100.00" // Regional currencies with symbol overrides formatCurrency(100, "MYR", "en"); // Output: "RM100.00" formatCurrency(100, "SGD", "en"); // Output: "S$100.00" formatCurrency(100, "PHP", "en"); // Output: "₱100.00" formatCurrency(100, "THB", "en"); // Output: "THB100.00" formatCurrency(100, "KRW", "en"); // Output: "₩100" formatCurrency(100, "INR", "en"); // Output: "₹100.00" // Other supported currencies formatCurrency(100, "AUD", "en"); // Output: "A$100.00" formatCurrency(100, "CAD", "en"); // Output: "CA$100.00" formatCurrency(100, "BRL", "en"); // Output: "R$100.00" formatCurrency(100, "TRY", "en"); // Output: "₺100.00" ``` -------------------------------- ### formatCurrency Source: https://context7.com/coingecko/cryptoformat/llms.txt Formats a numeric amount into a locale-specific currency string, with automatic precision adjustment for small values. ```APIDOC ## formatCurrency ### Description Formats an amount into a currency string based on the provided ISO code and locale. It automatically handles decimal precision based on value magnitude. ### Parameters - **amount** (number) - Required - The numeric value to format. - **currencyCode** (string) - Required - The ISO currency code (e.g., 'USD', 'BTC'). - **locale** (string) - Required - The locale string (e.g., 'en', 'de'). - **raw** (boolean) - Optional - If true, returns the number without currency symbols. - **options** (object) - Optional - Configuration object for decimalPlaces, significantFigures, or maximumDecimalTrailingZeroes. - **abbreviate** (boolean) - Optional - If true, abbreviates large numbers (e.g., '1M', '1B'). ``` -------------------------------- ### Format currency values with formatCurrency Source: https://context7.com/coingecko/cryptoformat/llms.txt Formats numeric values into locale-specific currency strings with support for automatic precision, raw output, and custom formatting options. ```javascript import { formatCurrency } from "@coingecko/cryptoformat"; // Basic formatting with locale support formatCurrency(123, "USD", "en"); // Output: "$123.00" formatCurrency(123400, "EUR", "de"); // Output: "123.400 €" formatCurrency(123400, "IDR", "id"); // Output: "Rp123.400" // Cryptocurrency formatting with automatic precision formatCurrency(0.00123, "USD", "en"); // Output: "$0.00123000" formatCurrency(1.5, "BTC", "en"); // Output: "₿1.500000" formatCurrency(0.0000005, "BTC", "en"); // Output: "₿0.000000500000" formatCurrency(1.1, "DOGE", "en"); // Output: "1.100000 DOGE" // Raw output without formatting symbols formatCurrency(0.00123, "USD", "en", true); // Output: "0.00123000" formatCurrency(0.00001, "BTC", "en", true); // Output: "0.000010000000" // Remove decimals for large amounts formatCurrency(4000.23, "USD", "en", false, true); // Output: "$4,000" // Custom decimal places formatCurrency(1.234, "USD", "en", false, { decimalPlaces: 2 }); // Output: "$1.23" formatCurrency(0.19, "BTC", "en", false, { decimalPlaces: 5 }); // Output: "₿0.19000" // Significant figures formatting formatCurrency(1234, "USD", "en", false, { significantFigures: 2 }); // Output: "$1,200" formatCurrency(12311.456, "USD", "en", false, { significantFigures: 1 }); // Output: "$10,000" // Combined decimal places and significant figures formatCurrency(0.1234, "USD", "en", false, { decimalPlaces: 2, significantFigures: 3 }); // Output: "$0.12" // Decimal trailing zeroes with subscript notation formatCurrency(0.00000123, "USD", "en", false, { maximumDecimalTrailingZeroes: 3 }); // Output: "$0.05123" // Abbreviated large numbers formatCurrency(12311111, "BTC", "en", false, false, true); // Output: "₿12.311M" formatCurrency(1000000000, "USD", "en", false, false, true); // Output: "$1B" formatCurrency(10000000, "DOGE", "en", false, false, true); // Output: "10M DOGE" // Japanese locale with abbreviated format formatCurrency(1000000000, "BTC", "ja", false, false, true); // Output: "BTC 10億" formatCurrency(12000000, "USD", "ja", false, false, true); // Output: "$1200万" ``` -------------------------------- ### clearCache Source: https://context7.com/coingecko/cryptoformat/llms.txt Clears the internal cache of Intl.NumberFormat instances. ```APIDOC ## clearCache ### Description Clears the internal formatter cache to free memory or reset formatting instances. ``` -------------------------------- ### isCrypto Source: https://context7.com/coingecko/cryptoformat/llms.txt Checks if a currency code corresponds to a cryptocurrency. ```APIDOC ## isCrypto ### Description Determines if the provided currency code is a cryptocurrency. Returns true for crypto and false for recognized fiat currencies. ### Parameters - **currencyCode** (string) - Required - The ISO currency code to check. ``` -------------------------------- ### Clear formatter cache with clearCache Source: https://context7.com/coingecko/cryptoformat/llms.txt Clears the internal cache of Intl.NumberFormat instances to free memory or reset formatting state. ```javascript import { formatCurrency, clearCache } from "@coingecko/cryptoformat"; // Format several values (formatters are cached internally) formatCurrency(100, "USD", "en"); formatCurrency(200, "USD", "en"); formatCurrency(300, "EUR", "de"); // Clear all cached formatters clearCache(); // New formatters will be created on next call formatCurrency(400, "USD", "en"); // Output: "$400.00" ``` -------------------------------- ### Check currency type with isCrypto Source: https://context7.com/coingecko/cryptoformat/llms.txt Determines if a currency code is a cryptocurrency. Returns true for crypto codes and false for recognized fiat currencies. ```javascript import { isCrypto } from "@coingecko/cryptoformat"; // Major cryptocurrencies isCrypto("BTC"); // Output: true isCrypto("ETH"); // Output: true // Other cryptocurrencies (not in fiat list) isCrypto("DOGE"); // Output: true isCrypto("LTC"); // Output: true isCrypto("ADA"); // Output: true // Fiat currencies isCrypto("USD"); // Output: false isCrypto("EUR"); // Output: false isCrypto("JPY"); // Output: false isCrypto("IDR"); // Output: false // Case insensitive (lowercase also works) isCrypto("btc"); // Output: true isCrypto("usd"); // Output: true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.