npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ethtools

v0.0.10

Published

Formatting and value conversion for ethereum currencies.

Downloads

1

Readme

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

  • https://github.com/ethjs/ethjs-unit
  • http://numeraljs.com
  • https://github.com/indutny/bn.js