bitcoin-units
Advanced tools
Comparing version 0.1.1 to 0.1.3
{ | ||
"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. |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
7992
2
140
0