DeFi Numbers
Number formatting and utilities for DeFi apps.
Usage
npm i defi-numbers
Basic Usage
import { fNum } from "defi-numbers";
fNum("token", "12345");
fNum("token", "12345", { abbreviated: false });
fNum("token", "0.001234");
fNum("token", "0.00001");
fNum("fiat", "1234.56");
fNum("fiat", "1234.56", { abbreviated: false });
fNum("fiat", "0.001");
fNum("percentage", "0.10");
fNum("percentage", "0.001");
fNum("percentage", "0.00001");
fNum("integer", "1234567");
fNum("integer", "0.123");
Utility Functions
import { bn, safeSum, blockInvalidNumberInput } from "defi-numbers";
bn("123.456").gte(100);
safeSum(["0.1", "0.2", "0.3"]);
<input type="number" onKeyDown={blockInvalidNumberInput} />;
Contributors