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.3.0 to 1.0.0

.prettierrc

47

package.json
{
"name": "bitcoin-units",
"version": "0.3.0",
"description": "Convert between BTC, mBTC, μBTC, satoshi and custom units.",
"version": "1.0.0",
"description": "Convert between BTC, mBTC, μBTC, satoshis and custom units.",
"homepage": "https://github.com/ruigomeseu/bitcoin-units",
"bugs": "https://github.com/ruigomeseu/bitcoin-units/issues",
"main": "./lib/bitcoin.cjs.js",
"module": "./lib/bitcoin.esm.js",
"browser": "./lib/bitcoin.umd.js",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"test": "mocha --recursive",
"build": "rollup -c",
"test": "yarn run build && jest",
"build": "tsup ./src",
"cover": "istanbul cover _mocha -- --recursive",
"lint": "eslint src test"
"lint": "eslint src tests --ext .ts"
},

@@ -35,20 +35,19 @@ "keywords": [

"devDependencies": {
"chai": "^4.2.0",
"codecov": "^3.1.0",
"cross-env": "^5.2.0",
"eslint": "^5.9.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"istanbul": "^1.0.0-alpha",
"mocha": "^5.0.0",
"rimraf": "^2.6.2",
"rollup": "^0.67.1",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-node-resolve": "^3.0.0"
"@swc/core": "^1.3.68",
"@types/big.js": "^6.1.6",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.1.0",
"tslib": "^2.5.3",
"tsup": "^7.1.0",
"typescript": "^5.1.3"
},
"dependencies": {
"big.js": "^5.2.2"
"big.js": "^6.1.6"
}
}
}
![](https://ruigomes.me/bitcoin-units.png?v=2)
# bitcoin-units
[![Build Status](https://img.shields.io/travis/ruigomeseu/bitcoin-units.svg)](https://travis-ci.org/ruigomeseu/bitcoin-units) [![codecov](https://img.shields.io/codecov/c/github/ruigomeseu/bitcoin-units.svg)](https://codecov.io/gh/ruigomeseu/bitcoin-units) [![npm version](https://badge.fury.io/js/bitcoin-units.svg)](https://badge.fury.io/js/bitcoin-units)
Convert between any bitcoin unit - BTC, mBTC, μBTC, satoshi and even your own custom units! Available for ES6 and Node.js.
[![Build Status](https://img.shields.io/travis/ruigomeseu/bitcoin-units.svg)](https://travis-ci.org/ruigomeseu/bitcoin-units)
[![codecov](https://img.shields.io/codecov/c/github/ruigomeseu/bitcoin-units.svg)](https://codecov.io/gh/ruigomeseu/bitcoin-units)
[![npm version](https://badge.fury.io/js/bitcoin-units.svg)](https://badge.fury.io/js/bitcoin-units)
[![npm](https://img.shields.io/npm/dt/bitcoin-units.svg)](https://www.npmjs.com/package/bitcoin-units)
[![Twitter Follow](https://img.shields.io/twitter/follow/8bitgomes.svg?style=social)](https://twitter.com/8bitgomes)
```js
bitcoin(1, 'mBTC').to('BTC').value()
0.001
Convert between any bitcoin unit - BTC, mBTC, μBTC, satoshi and even your own custom units.
bitcoin(100000, 'satoshi').to('BTC').format()
'0.001 BTC'
```ts
new BitcoinUnit(10000, 'sats').to('BTC').getValue();
// 0.001;
new BitcoinUnit(21000, 'sats').to('BTC').format();
// '0.00021000 BTC';
```
👉 [Try the demo](https://bitcoinunits.app)
## Installation
Add `bitcoin-units` to your Javascript project dependencies using Yarn:
```bash
yarn add bitcoin-units
```
Or NPM:
```bash

@@ -29,12 +40,13 @@ npm install bitcoin-units --save

### Importing
Import using ES6:
Import using ESM:
```js
import bitcoin from 'bitcoin-units';
import BitcoinUnit from 'bitcoin-units';
```
Or AMD:
Or CJS:
```js
var bitcoin = require('bitcoin-units');
const BitcoinUnit = require('bitcoin-units');
```

@@ -45,5 +57,6 @@

Basic unit conversions are done using the `to(unit)` function:
```js
bitcoin(1, 'mBTC').to('BTC').value()
0.001
new BitcoinUnit(1, 'mBTC').to('BTC').getValue();
// 0.001;
```

@@ -58,30 +71,31 @@

- `btc`: `bitcoin` or `bitcoins`
- `btc`: `bitcoin`or `bitcoins`
- `mbtc`: `millibtc`
- `bit`: `μbtc` or `microbtc`
- `bit`: `microbtc`
- `satoshi`: `sat`, `sats`, `satoshi`, `satoshis`
- `sats`: `sat`, `satoshi`, `satoshis`
#### Available getters
`getValue()` returns a `Number`:
#### Available getters
`value()` returns a `Number`:
```js
bitcoin(1, 'mBTC').to('BTC').value()
0.001
new BitcoinUnit(1, 'mBTC').to('BTC').value();
// 0.001;
```
`toString()` returns a `string`:
```js
bitcoin(100000, 'satoshi').to('BTC').toString()
'0.001'
new BitcoinUnit(100000, 'satoshi').to('BTC').toString();
// '0.001';
```
`format()` returns a string with the value and unit:
```js
bitcoin(100000, 'satoshi').to('BTC').format()
'0.001 BTC'
new BitcoinUnit(100000, 'satoshi').to('BTC').format();
// '0.00100000 BTC';
```

@@ -92,22 +106,25 @@

#### Custom Format
You can set your own custom formats using the `bitcoin.setDisplay(unit, options)`:
You can set your own custom formats using the `BitcoinUnit.setDisplay(unit, options)`:
```js
bitcoin.setDisplay('satoshi', {
format: '{amount} sats'
BitcoinUnit.setDisplay('sats', {
format: '{amount} something',
});
bitcoin(1, 'BTC').to('satoshi').format();
new BitcoinUnit(1, 'BTC').to('satoshi').format();
'100,000,000 sats'
// '100,000,000 something';
```
#### 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);
BitcoinUnit.setUnit('custom', 1 / 1e2);
bitcoin(1, 'btc').to('custom').value();
new BitcoinUnit(1, 'btc').to('custom').value();
100
// 100;
```

@@ -120,16 +137,17 @@

bitcoin.setUnit('usd', 1 / 8000);
BitcoinUnit.setUnit('usd', 1 / 8000);
bitcoin(1, 'satoshi').to('usd').value();
new BitcoinUnit(1, 'satoshi').to('usd').value();
0.00008
// 0.00008;
```
There's a shorthand to this function named `bitcoin.setFiat(unit, rate)`:
```js
bitcoin.setFiat('usd', 8000);
BitcoinUnit.setFiat('usd', 8000);
bitcoin(1, 'satoshi').to('usd').value();
new BitcoinUnit(1, 'satoshi').to('usd').value();
0.00008
// 0.00008;
```

@@ -140,3 +158,3 @@

Rui Gomes
https://ruigomes.me
https://ruigomes.me

@@ -143,0 +161,0 @@ ## License

Sorry, the diff of this file is not supported yet

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