All Projects → coingecko → cryptoformat

coingecko / cryptoformat

Licence: MIT license
Javascript library to format and display cryptocurrency and money

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to cryptoformat

ontwik-ui
ontwik-ui - A headless UI library
Stars: ✭ 52 (+30%)
Mutual labels:  rollup
xmind2testlink
Convert xmind to test link xml files, support xmind pro and xmind zen.
Stars: ✭ 99 (+147.5%)
Mutual labels:  conversion
pesa
A JS money lib whose precision goes up to 11 (and beyond).
Stars: ✭ 38 (-5%)
Mutual labels:  conversion
geofiddle
Geometric conversions between different formats and projections
Stars: ✭ 15 (-62.5%)
Mutual labels:  conversion
convert
The smallest & fastest library for really easy, totally type-safe unit conversions in TypeScript & JavaScript.
Stars: ✭ 47 (+17.5%)
Mutual labels:  conversion
trample
A Web/Node General Utils Library
Stars: ✭ 36 (-10%)
Mutual labels:  rollup
marc2bibframe2
Convert MARC records to BIBFRAME2 RDF
Stars: ✭ 72 (+80%)
Mutual labels:  conversion
ReSampler
High quality command-line audio sample rate converter
Stars: ✭ 120 (+200%)
Mutual labels:  conversion
rollup-plugin-external-globals
Transform external imports into global variables like output.globals.
Stars: ✭ 57 (+42.5%)
Mutual labels:  rollup
RouteConverter
The popular GPS conversion and editing tool
Stars: ✭ 123 (+207.5%)
Mutual labels:  conversion
howdyjs
一个包含Javascript插件、Vue3组件、Vue3指令的工具库
Stars: ✭ 77 (+92.5%)
Mutual labels:  rollup
web-config
A Rollup configuration to build modern web applications with sweet features as for example SCSS imports, Service Worker generation with Workbox, Karma testing, live reloading, coping resources, chunking, treeshaking, Typescript, license extraction, filesize visualizer, JSON import, budgets, build progress, minifying and compression with brotli a…
Stars: ✭ 17 (-57.5%)
Mutual labels:  rollup
hubble-contracts
Hubble optimistic rollup
Stars: ✭ 102 (+155%)
Mutual labels:  rollup
qTsConverter
A simple tool to convert qt translation file (ts) to other format (xlsx / csv) and vice versa
Stars: ✭ 26 (-35%)
Mutual labels:  conversion
aspose-words-cloud-node
Node.Js library for communicating with the Aspose.Words Cloud API
Stars: ✭ 20 (-50%)
Mutual labels:  conversion
DIVA Tools
A global host of tools used to mod/parse Project DIVA games.
Stars: ✭ 24 (-40%)
Mutual labels:  conversion
bundle
An online tool to quickly bundle & minify your projects, while viewing the compressed gzip/brotli bundle size, all running locally on your browser.
Stars: ✭ 475 (+1087.5%)
Mutual labels:  rollup
size-plugin-bot
A Github bot for size-plugin
Stars: ✭ 76 (+90%)
Mutual labels:  rollup
pansy
🛠️ A zero configuration library bundler.
Stars: ✭ 14 (-65%)
Mutual labels:  rollup
ledger2beancount
Ledger to Beancount text-based converter
Stars: ✭ 63 (+57.5%)
Mutual labels:  conversion

Cryptoformat

npm version Build Status License: MIT

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.

Install

npm i @coingecko/cryptoformat

Usage

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.

Known Issues

  1. 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.
  2. Given that country detection for locale is quite hard to do, e.g. "en-MY", 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.

Development

Deployment

npm run build && npm run submit

File Sturcture

|- lib
    |- index.js (Build with babel)
|- src
    - index.js (Main Code)
    - index.d.ts (Types for TypeScript)
    - test.js (Test with Jest)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].