JSPM

bgl-units

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q30460F
  • License MIT

Convert Satoshi units <-> BGL

Package Exports

  • bgl-units
  • bgl-units/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bgl-units) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bgl-units

npm module to convert between Satoshi units(smallest denomination for Bitgesell BGL) and BGL with lightweight precision.


The Problem

The problem


Install

npm install --save bgl-units

# OR

yarn add bglunits

Usage

Node.js

const bglunits= require("bgl-units");

bglunits.toSatoshiUnits(1);
//=>100 000 000

bglunits.toBGL(100000000);
//=>1

Web

<!-- package injected as "bglunits" -->
<script src="https://rawgit.com/naftalimurgor/bglunits/master/index.bundle.js"></script>
<script>
  console.log("One Satoshi equals " + bglunits.toBitcoin(1) + " Bitcoin");
</script>

Or download it with npm install bgl-units and reference it as:

<script src="node_modules/bglunits/index.bundle.js"></script>

Error Handling

try {
  bglunits.toSatoshiUnits(false); //Throws TypeError
} catch (err) {
  console.log(err);
}

API

bglunits.toSatoshiUnits(number || string) bglunits.toBGL(number || string)

Read more on the Wiki


FAQ

  • What is a Satoshi?

    • Satoshi is to Bitcoin as pennies are to the dollar. Except that there are 100,000,000 Satoshi in one Bitcoin.
  • Why do I need a module when I can just divide or multiply by 100,000,000?

    • See here - Floating point errors are a problem. So bgl-units uses a tiny bignum library (big.js) to ensure accurate conversions!

Tests

npm test

License

MIT © Forked from: Dawson Botsford