New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bitcoin-units

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcoin-units - npm Package Compare versions

Comparing version 0.1.1 to 0.1.3

10

package.json
{
"name": "bitcoin-units",
"version": "0.1.1",
"description": "Easily convert between BTC, mBTC and Satoshis.",
"version": "0.1.3",
"description": "Convert between BTC, mBTC, μBTC, satoshi and custom units.",
"homepage": "https://github.com/ruigomeseu/bitcoin-units",
"bugs": "https://github.com/ruigomeseu/bitcoin-units/issues",
"main": "./lib/index.js",

@@ -26,2 +28,6 @@ "scripts": {

"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/ruigomeseu/bitcoin-units"
},
"devDependencies": {

@@ -28,0 +34,0 @@ "babel-cli": "^6.26.0",

119

README.md

@@ -1,2 +0,2 @@

![](https://ruigomes.me/bitcoin-units.png)
![](https://ruigomes.me/bitcoin-units.png?v=2)

@@ -6,3 +6,3 @@ # bitcoin-units

Convert between any bitcoin unit - BTC, mBTC, μBTC, satoshi and even your own custom units!
Convert between any bitcoin unit - BTC, mBTC, μBTC, satoshi and even your own custom units! Available for ES6 and Node.js.

@@ -26,1 +26,116 @@ ```js

```
## Usage
### Importing
Import using ES6:
```js
import bitcoin from 'bitcoin-units';
```
Or AMD:
```js
var bitcoin = require('bitcoin-units');
```
### Converting bitcoin
Basic unit conversions are done using the `to(unit)` function:
```js
bitcoin(1, 'mBTC').to('BTC').value()
0.001
```
#### Available units
There are 4 available units by default:
`btc`, `mbtc`, `bit` and `satoshi`.
You can also use any of the following aliases:
- `btc`: `bitcoin` or `bitcoins`
- `mbtc`: `millibtc`
- `bit`: `μbtc` or `microbtc`
- `satoshi`: `sat`, `sats`, `satoshi`, `satoshis`
#### Available getters
`value()` returns a `Number`:
```js
bitcoin(1, 'mBTC').to('BTC').value()
0.001
```
`toString()` returns a `string`:
```js
bitcoin(100000, 'satoshi').to('BTC').format()
'0.001'
```
`format()` returns a string with the value and unit:
```js
bitcoin(100000, 'satoshi').to('BTC').format()
'0.001 BTC'
```
### Customization
#### Format
You can set your own custom units using the `bitcoin.setDisplay(unit, options)`:
```js
bitcoin.setDisplay('satoshi', {
unit: 'custom'
});
bitcoin(1, 'BTC').to('satoshi').format();
'100000000 custom'
```
#### Custom Unit
If you want to create your own custom units, you can use the `bitcoin.setUnit(unit, value)`:
```js
bitcoin.setUnit('custom', 1 / 1E2);
bitcoin(1, 'btc').to('custom').value();
100
```
You can use this to create your own conversion to fiat currencies:
```js
// Let's suppose a rate of 1 BTC = $8000.00
bitcoin.setUnit('usd', 1 / 8000);
bitcoin(1, 'satoshi').to('usd').value();
0.00008
```
There's a shorthand to this function named `bitcoin.setFiat(unit, rate)`:
```js
bitcoin.setFiat('usd', 8000);
bitcoin(1, 'satoshi').to('usd').value();
0.00008
```
## Author
Rui Gomes
https://ruigomes.me
## License
The MIT License (MIT). Please see [LICENSE file](https://github.com/ruigomeseu/rss-feed-finder/blob/master/LICENSE.md) for more information.
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