GithubHelp home page GithubHelp logo

lutangar / ethtools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ethereum/meteor-package-tools

0.0 2.0 0.0 46 KB

Formatting and value conversion for ethereum currencies.

JavaScript 100.00%
ethereum cryptocurrencies formatting ethjs bignumber

ethtools's Introduction

Ethereum tools

Build Status

Formatting and value conversion for ethereum currencies.

This package is an alternative of https://github.com/ethereum/meteor-package-tools for node and the browser. The API is therefore as close as possible.

Installation

$ npm install --save ethtools

Usage

formatBalance (or formatWei)

Format a number of wei to another ether unit.

  • number : (String|Number|BN) - the number of wei to format
  • format : (String) - the format see numeral.js for more examples (0,0.[00000000] $ by default)
  • unit : (String) - any ethereum units see ethjs-unit supported units (ether by default)
  • options : (Object) - a list of options. Currently supported options are:
    • etherSymbol : (String) - if unit is ether will use this symbol for the unit instead (Ξ by default)
    • locale : (String) - a custom locale (en by default)
import { formatBalance } from 'ethtools';

formatBalance('1000000000000000000');
// => 1.0 Ξ

formatNumber

Format a number using numeral.js formats.

this function is used internally by formatBalance

  • number (String|Number|BN) - the number to format
  • format (String) - the format see numeral.js for more examples
Number Format String
1000.234 $0,0.00 Ξ1,000.23
1000.2 0,0[.]00 $ 1,000.20 Ξ
1001 $ 0,0[.]00 Ξ 1,001
-1000.234 ($0,0) (Ξ1,000)
-1000.234 $0.00 -Ξ1000.23
1230974 ($ 0.00 a) Ξ 1.23 m
  • unit (String) - any custom unit/currencies, will replace the $ sign
  • options : (Object) - a list of options. Currently supported options are:
    • etherSymbol : (String) - if unit is ether will use this symbol for the unit instead (Ξ by default)
    • locale : (String) - a custom locale (en by default)

Example

import { formatNumber } from 'ethtools';

formatNumber('1000000000000000000', '0,0.0[00]');
// => 1,000,000,000,000,000,000.0

toWei

A proxy method to toWei method of ethjs-unit

fetchPrices

Promise-based helper to fetch current ether price information via cryptocompare.com public API

Example

import { fetchPrices } from 'ethtools';

fetchPrices().then(({response, json }) => console.log(json));
// { BTC: 0.07353, USD: 297.5, EUR: 250.78 }

Tests

Simply clone the repo, npm install, and run npm test.

Links

ethtools's People

Contributors

derron avatar dev-dan avatar evertonfraga avatar frozeman avatar lutangar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.