Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@coingecko/cryptoformat
Advanced tools
Javascript library to format and display cryptocurrencies and fiat
cryptoformat
is used by CoinGecko (https://www.coingecko.com) to format crypto and fiat values.
Often an altcoin can be worth much less than $0.01 USD, and thus we need to format this value by providing more decimal places in the formatting to prevent losing precious information.
cryptoformat
also tries to handle different locales and currency formatting by deferring the work to the browser's Intl.NumberFormat
. If Intl.NumberFormat
is not supported by the browser, cryptoformat
provides a primitive fallback for currency display.
npm i @coingecko/cryptoformat
import { formatCurrency } from "@coingecko/cryptoformat";
formatCurrency(123, "USD", "en");
// "$123.00"
formatCurrency(0.00123, "USD", "en");
// "$0.00123000"
// Provide raw = true to remove formatting and symbol
formatCurrency(0.00123, "USD", "en", true);
// "0.00123000"
formatCurrency(123400, "IDR", "id");
// "Rp123.400"
formatCurrency(123400, "EUR", "de");
// "123.400 €"
// Provide noDecimal = true to explicitly remove decimal for numbers above > 1.0
formatCurrency(4000.23, "USD", "en", false, true);
// "$4,000"
// Provide number of decimal places or significant figures
formatCurrency(1.234, "USD", "en", false, { decimalPlaces: 2 });
// "$1.23"
formatCurrency(1234, "USD", "en", false, { significantFigures: 2 });
// "$1,200"
// 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"
cryptoformat
tries to cache formatters for reuse internally. If same locale and currency is used, the cached formatter will be used.
Intl.NumberFormat
does not always behave consistently across browsers. cryptoformat
does some manual overrides in order to ensure that "MYR123.00" is displayed as "RM123.00", for example.cryptoformat
does not try to do country sniffing. It is the responsibility of the caller to provide that if possible, but providing only "en" should also work for the most part, but not perfectly: users in different regions may expect a different formatting for the same language.npm run build && npm run submit
|- lib
|- index.js (Build with babel)
|- src
- index.js (Main Code)
- index.d.ts (Types for TypeScript)
- test.js (Test with Jest)
FAQs
Javascript library to format and display cryptocurrencies and fiat
The npm package @coingecko/cryptoformat receives a total of 4,665 weekly downloads. As such, @coingecko/cryptoformat popularity was classified as popular.
We found that @coingecko/cryptoformat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.