Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

defi-numbers

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defi-numbers

Number formatting and utilities for DeFi apps.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
0
Weekly downloads
 
Created
Source

DeFi Numbers

Number formatting and utilities for DeFi apps.

👪 All Contributors: 2 🤝 Code of Conduct: Kept 🧪 Coverage 📝 License: MIT 📦 npm version 💪 TypeScript: Strict

Usage

npm i defi-numbers

Basic Usage

import { fNum } from "defi-numbers";

// Token amounts
fNum("token", "12345"); // -> 12.35k
fNum("token", "12345", { abbreviated: false }); // -> 12,345
fNum("token", "0.001234"); // -> 0.0012
fNum("token", "0.00001"); // -> < 0.00001

// Fiat values
fNum("fiat", "1234.56"); // -> 1.23k
fNum("fiat", "1234.56", { abbreviated: false }); // -> 1,234.56
fNum("fiat", "0.001"); // -> < 0.01

// Percentages
fNum("percentage", "0.10"); // -> 10%
fNum("percentage", "0.001"); // -> 0.1%
fNum("percentage", "0.00001"); // -> < 0.01%

// Integers
fNum("integer", "1234567"); // -> 1,234,567
fNum("integer", "0.123"); // -> 0

Utility Functions

import { bn, safeSum, blockInvalidNumberInput } from "defi-numbers";

// Create BigNumber instances
bn("123.456").gte(100); // -> true

// Sum array of numbers safely
safeSum(["0.1", "0.2", "0.3"]); // -> "0.6"

// Block invalid number input in React
<input type="number" onKeyDown={blockInvalidNumberInput} />;

Contributors

Gareth Fuller
Gareth Fuller

💻 🖋 📖 🤔 🚇 🚧 📆 🔧

FAQs

Package last updated on 01 Nov 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc