# chai-bn

> Chai assertions for comparing arbitrary-precision integers using the bignumber.js library

Latest version **0.3.1** (published 2022-01-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install chai-bn
pnpm add chai-bn
yarn add chai-bn
bun add chai-bn
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2022-01-25 |
| First published | 2018-12-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Nicolas Venturo |
| Maintainers | frangio, nventuro |
| Keywords | chai, chai-plugin, math, test, arbitrary, precision, arithmetic, big, number, decimal, float, bignumber, bn |

## Links

- npm: https://www.npmjs.com/package/chai-bn
- Repository: https://github.com/ZeppelinSolutions/chai-bn
- Homepage: https://github.com/ZeppelinSolutions/chai-bn#readme
- Issues: https://github.com/ZeppelinSolutions/chai-bn/issues
- npm.io page: https://npm.io/package/chai-bn

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2022-01-25
- 0.3.0 — 2021-07-22
- 0.2.2 — 2021-06-11
- 0.2.1 — 2020-03-09
- 0.2.0 — 2019-09-19
- 0.1.1 — 2019-01-17
- 0.1.0 — 2019-01-11
- 0.1.0-beta.0 — 2018-12-29
- 0.1.0-alpha.2 — 2018-12-28
- 0.1.0-alpha.1 — 2018-12-28
- 0.1.0-alpha.0 — 2018-12-27

## README

# chai-bn

[![NPM Package](https://img.shields.io/npm/v/chai-bn.svg?style=flat-square)](https://www.npmjs.org/package/chai-bn)
[![Build Status](https://travis-ci.com/OpenZeppelin/chai-bn.svg?branch=master)](https://travis-ci.com/OpenZeppelin/chai-bn)

[`Chai`](https://www.chaijs.com/) assertions for comparing arbitrary-precision integers using the [bn.js](https://github.com/indutny/bn.js) library. Forked from [chai-bignumber](https://github.com/asmarques/chai-bignumber), which uses the [bignumber.js](https://github.com/MikeMcl/bignumber.js) library.

## Installation

```bash
npm install --save-dev chai-bn
```

## Usage

```javascript
const chai = require('chai');
const BN = require('bn.js');

// Enable and inject BN dependency
chai.use(require('chai-bn')(BN));
```

## Assertions

The following assertion methods are provided and will override the existing builtin assertions if the `bignumber` property is set as part of the assertion chain:
- equal/equals/eq
- above/gt/greaterThan
- least/gte
- below/lt/lessThan
- most/lte
- closeTo

A set of additional assertion properties is also provided:
- negative
- zero

Both actual values (the values being asserted) and expected values (the values the actual value is expected to match) can be either instances of `BN`, or strings which can be converted into a valid number. This is a key difference with [chai-bignumber](https://github.com/asmarques/chai-bignumber), which automatically converts JavaScript numbers to `BigNumber` instances for both actual and expected values.

Only BDD style (`expect` or `should`) assertions are supported.

## Examples

Methods:

```javascript
const actual = new BN('100000000000000000').plus(new BN('1'));
const expected = '100000000000000001';

actual.should.be.a.bignumber.that.equals(expected);
expect(actual).to.be.a.bignumber.that.is.at.most(expected);
(new BN('1000')).should.be.a.bignumber.that.is.lessThan('2000');
```

Properties:

```javascript
(new BN('-100')).should.be.a.bignumber.that.is.negative;
expect(new BN('1').sub(new BN('1'))).to.be.a.bignumber.that.is.zero;
```

Some `Chai` properties (e.g. the `that.is` chain) have no effect other than increasing readability, and can be dropped if less verbosity is desired.

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/chai-bn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
