Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Migrate to typescript #10

Merged
merged 3 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
package-lock.json
dist
.nyc_output
coverage
3 changes: 3 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@ethereumjs/config-nyc"
}
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
.vscode
package.json
dist
.nyc_output
docs
47 changes: 26 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# SYNOPSIS
# SYNOPSIS

[![NPM Package](https://img.shields.io/npm/v/fixed-bn.js.svg?style=flat-square)](https://www.npmjs.org/package/fixed-bn.js)
[![Build Status](https://img.shields.io/travis/ewasm/fixed-bn.js.svg?branch=master&style=flat-square)](https://travis-ci.org/ewasm/fixed-bn.js)
[![Coverage Status](https://img.shields.io/coveralls/ewasm/fixed-bn.js.svg?style=flat-square)](https://coveralls.io/r/ewasm/fixed-bn.js)

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

a bn.js factory wrapper that constrains numbers to a fixed width

# USAGE

```javascript
const FixedBN = require('fixed-bn.js')

Expand All @@ -22,85 +24,88 @@ bnNum.toBuffer()

// you can also create an arbitary fixed lenght bn
// max bit lenght is 199 bits and min length is 2 bits
const I199 = FixedBN(199, 2)
const I199 = FixedBN(199, 2)
const newBnNum = new I199(390248)
```

# API
Since this module extends [BN.js](https://github.com/indutny/bn.js/) it has the methods as it does plus a few extras.

Since this module extends [BN.js](https://github.com/indutny/bn.js/) it has the methods as it does plus a few extras.

## factory

[./index.js:11-87](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L11-L87 "Source code on GitHub")
[./index.js:11-87](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L11-L87 'Source code on GitHub')

A factory that produces BN.js constructors for a given width

**Parameters**

- `maxWidth` **Integer** the max length in bits that the bn.js instance can handle
- `minWidth` **Integer** the min length in bits that the bn.js instance can handle
- `maxWidth` **Integer** the max length in bits that the bn.js instance can handle
- `minWidth` **Integer** the min length in bits that the bn.js instance can handle

Returns **bn.js** returns a bn.js constuctor that that is constained to `maxWidth` and `minWidth`

## builtin length

the factory has the following builtins

- `FixedBN.U64`
- `FixedBN.U128`
- `FixedBN.U160`
- `FixedBN.U256`

## bn.js instance

Each instance has the following additional methods

## maxWidth

[./index.js:35-37](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L35-L37 "Source code on GitHub")
[./index.js:35-37](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L35-L37 'Source code on GitHub')

retuns Max Width

Returns **integer**
Returns **integer**

## minWidth

[./index.js:43-45](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L43-L45 "Source code on GitHub")
[./index.js:43-45](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L43-L45 'Source code on GitHub')

retuns Min Width

Returns **integer**
Returns **integer**

## fromBuffer

[./index.js:66-68](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L66-L68 "Source code on GitHub")
[./index.js:66-68](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L66-L68 'Source code on GitHub')

converts a buffer to a fixed-bn.js

**Parameters**

- `value` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | integer)**
- `endain` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `endian` (optional, default `'be'`)
- `value` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | integer)**
- `endain` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `endian` (optional, default `'be'`)

## isFixBN

[./index.js:74-76](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L74-L76 "Source code on GitHub")
[./index.js:74-76](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L74-L76 'Source code on GitHub')

checks if a BN instance is a fixed BN instance

**Parameters**

- `bn` **bn.js**
- `bn` **bn.js**

## isSameWidth

[./index.js:82-84](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L82-L84 "Source code on GitHub")
[./index.js:82-84](https://github.com/ewasm/fixedBN/blob/814e88711940f48efc341ed0c1296f7fa6cdd111/./index.js#L82-L84 'Source code on GitHub')

checks if a fixed-bn instance is the same width as the contructor

**Parameters**

- `fixBN` **bn.js**

- `fixBN` **bn.js**

# LICENSE
[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2))

[MPL-2.0](<https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)>)
94 changes: 0 additions & 94 deletions index.js

This file was deleted.

41 changes: 33 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,48 @@
"name": "fixed-bn.js",
"version": "0.0.2",
"description": "bn.js wrapper that constrains numbers to a fixed width",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"coverage": "istanbul cover ./tests/index.js",
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
"lint": "standard",
"test": "tape ./tests/index.js"
"build": "ethereumjs-config-build",
"prepublishOnly": "npm run test && npm run build",
"coverage": "ethereumjs-config-coverage",
"coveralls": "ethereumjs-config-coveralls",
"format": "ethereumjs-config-format",
"format:fix": "ethereumjs-config-format-fix",
"tslint": "ethereumjs-config-tslint",
"tslint:fix": "ethereumjs-config-tslint-fix",
"tsc": "ethereumjs-config-tsc",
"lint": "ethereumjs-config-lint",
"lint:fix": "ethereumjs-config-lint-fix",
"unitTests": "npm run build && tape ./tests/*.js",
"test": "npm run lint && npm run unitTests",
"test:fix": "npm run lint:fix && npm run unitTests",
"docs:build": "typedoc --out docs --mode file --readme none --theme markdown --mdEngine github --gitRevision master --excludeNotExported src/*.ts"
},
"keywords": [
"bn.js"
],
"author": "mjbecze <[email protected]>",
"license": "MPL-2.0",
"devDependencies": {
"@ethereumjs/config-nyc": "^1.1.1",
"@ethereumjs/config-prettier": "^1.1.1",
"@ethereumjs/config-tsc": "^1.1.1",
"@ethereumjs/config-tslint": "^1.1.1",
"@types/bn.js": "^4.11.4",
"@types/node": "^11.11.3",
"@types/tape": "^4.2.33",
"coveralls": "^3.0.0",
"istanbul": "^0.4.5",
"standard": "^11.0.0",
"tape": "^4.6.3"
"nyc": "^13.3.0",
"prettier": "^1.16.4",
"tape": "^4.6.3",
"ts-node": "^8.0.3",
"tslint": "^5.14.0",
"typedoc": "^0.14.2",
"typedoc-plugin-markdown": "^1.1.27",
"typescript": "^3.3.3333",
"typestrict": "^1.0.2"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@ethereumjs/config-prettier')
Loading