{"id":18654968,"url":"https://github.com/ethworks/bn-chai","last_synced_at":"2025-04-11T17:31:47.266Z","repository":{"id":80049822,"uuid":"124415883","full_name":"EthWorks/bn-chai","owner":"EthWorks","description":"BN chai extends Chai with bn.js operations.","archived":false,"fork":false,"pushed_at":"2018-09-10T07:28:02.000Z","size":11,"stargazers_count":14,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T02:46:28.035Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EthWorks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-08T16:08:30.000Z","updated_at":"2022-08-11T12:11:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"23dc023b-055f-4226-bdf6-e5d0db0a7eca","html_url":"https://github.com/EthWorks/bn-chai","commit_stats":{"total_commits":5,"total_committers":3,"mean_commits":"1.6666666666666667","dds":0.4,"last_synced_commit":"7aaea9306623be87d9726e31470938c8d94a2d2b"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthWorks%2Fbn-chai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthWorks%2Fbn-chai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthWorks%2Fbn-chai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EthWorks%2Fbn-chai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EthWorks","download_url":"https://codeload.github.com/EthWorks/bn-chai/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449823,"owners_count":21105568,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T07:17:15.890Z","updated_at":"2025-04-11T17:31:43.790Z","avatar_url":"https://github.com/EthWorks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bn-chai\nbn-chai extends [Chai](http://chaijs.com/) with assertions about [bn.js](https://github.com/indutny/bn.js/) decimals.\n\n## Installation\n```bash\nnpm install -s bn-chai\n```\n\n## Setup\n```javascript\nvar chai = require('chai');\nvar expect = chai.expect;\nvar BN = require('bn.js');\nvar bnChai = require('bn-chai');\nchai.use(bnChai(BN));\n```\n\n## Usage\n\nWhen comparing two [bn.js](https://github.com/indutny/bn.js/) decimals **bn1** and **bn2**, instead of doing:\n\n```javascript\nexpect(bn1.eq(bn2)).to.be.true;\n```\n\nYou can do this instead:\n\n```javascript\nexpect(bn1).to.eq.BN(bn2);\n```\n\nThis plugin is also handy when comparing a [bn.js](https://github.com/indutny/bn.js/) decimal to an inline constant, so instead of writing:\n\n```javascript\nexpect(bn1.eq(new BN('1'))).to.be.true;\n```\n\nYou can simply write:\n\n```javascript\nexpect(bn1).to.eq.BN(1);\n```\n\nWhich is simpler and more readable.\n\n## Assertions\n\n### eq\nAsserts that the target is **equal** to the given object. \n```javascript\nexpect(new BN('1')).to.eq.BN(1);\nexpect(new BN('1')).not.to.eq.BN(0);\n```\n\n### lt\nAsserts that the target is **less than** the given object. \n```javascript\nexpect(new BN('0')).to.be.lt.BN(1);\nexpect(new BN('1')).not.to.be.lt.BN(1);\n```\n\n### lte\nAsserts that the target is **less than** or **equal** to the given object. \n```javascript\nexpect(new BN('0')).to.be.lte.BN(1);\nexpect(new BN('1')).to.be.lte.BN(1);\nexpect(new BN('2')).not.to.be.lte.BN(1);\n```\n\n### gt\nAsserts that the target is **greater than** the given object. \n```javascript\nexpect(new BN('1')).to.be.gt.BN(0);\nexpect(new BN('1')).not.to.be.gt.BN(1);\n```\n\n### gte\nAsserts that the target is **greater than** or **equal** to the given object. \n```javascript\nexpect(new BN('1')).to.be.gte.BN(0);\nexpect(new BN('1')).to.be.gte.BN(1);\nexpect(new BN('1')).not.to.be.gte.BN(2);\n```\n\n### negative\nAsserts that the target is **negative**.\n```javascript\nexpect(new BN('-1')).to.be.negative;\nexpect(new BN('1')).not.to.be.negative;\n```\n\n### even\nAsserts that the target is **even**.\n```javascript\nexpect(new BN('2')).to.be.even;\nexpect(new BN('1')).not.to.be.even;\n```\n\n### odd\nAsserts that the target is **odd**.\n```javascript\nexpect(new BN('1')).to.be.odd;\nexpect(new BN('2')).not.to.be.odd;\n```\n\n### zero\nAsserts that the target is equal to 0.\n```javascript\nexpect(new BN('0')).to.be.zero;\nexpect(new BN('1')).not.to.be.zero;\n```\n\n## Mixing BN, numbers and strings\n\nYou can mix BN with numbers and strings freely:\n\n```javascript\nexpect(new BN('1')).to.eq.BN(new BN('1'));\nexpect(new BN('1')).to.eq.BN('1');\nexpect(new BN('1')).to.eq.BN(1);\n\nexpect('1').to.eq.BN(new BN('1'));\nexpect('1').to.eq.BN('1');\nexpect('1').to.eq.BN(1);\n\nexpect(1).to.eq.BN(new BN('1'));\nexpect(1).to.eq.BN('1');\nexpect(1).to.eq.BN(1);\n```\n\n## Executing example tests\n\nExample unit tests making use of this plugin can be executed by running the following commands:\n\n```\ncd test\nnpm run test; npm run failTest\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethworks%2Fbn-chai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethworks%2Fbn-chai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethworks%2Fbn-chai/lists"}