JSPM

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

Convert Satoshi <-> Bitcoin

Package Exports

  • satoshi-bitcoin

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 (satoshi-bitcoin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

satoshi-bitcoin

Build Status npm version

npm module to convert between Satoshi and Bitcoin with lightweight precision.

The Problem

The problem


The Solution

The solution


Install

npm install --save satoshi-bitcoin

Usage

Node.js

var sb = require('satoshi-bitcoin');
console.log('One Bitcoin is ' + sb.toSatoshi(1) + ' Satoshi');
console.log('One Satoshi equals ' + sb.toBitcoin(1) + ' Bitcoin');

Web

<script src="https://rawgit.com/dawsonbotsford/satoshi-bitcoin/master/index.bundle.js"></script>
<script>
  console.log('One Satoshi equals ' + sb.toBitcoin(1) + ' Bitcoin');
</script>


Error Handling

try {
  sb.toSatoshi(false)); //Throws TypeError
} catch (err) {
  console.log(err);
}

API

toSatoshi(number)
toBitcoin(number)

Read more on the Wiki


FAQ

  • What is a Satoshi?

    • Satoshi is the smallest sub-unit of Bitcoin. 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 myself?

    • See here - Explanation: satoshi-bitcoin handles floating point arithmetic errors by implementing a bignum library and descriptive error handling.

Contributing

Open to pull requests.

  • After any change to index.js, update the Wiki by performing npm run wiki
  • After any change to index.js, update the browser bundle by performing npm run wiki
  • Licensed under MIT

Tests

npm test

Release History

  • 0.3.5 Improve documentation
  • 0.3.4 Add browserified pack for web usage
  • 0.3.2 Compress total package size in half and minify
  • 0.3.0 Support string input. Update README
  • 0.2.0 Error handling Implemented. Switched to grunt.
  • 0.1.2 Handle floating point corner cases and added lint tests
  • 0.1.1 README updates to reference wiki
  • 0.1.0 Initial release

Donate Bitcoin