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

Commit 54569db

Browse files
authored
Migrate to typescript (#10)
* Mv index.js to src/index.ts * Add ts configs * Migrate source to ts
1 parent 3082e83 commit 54569db

12 files changed

+212
-132
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules
22
package-lock.json
3+
dist
4+
.nyc_output
5+
coverage

.nycrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@ethereumjs/config-nyc"
3+
}

.prettierignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
.vscode
3+
package.json
4+
dist
5+
.nyc_output
6+
docs

README.md

+26-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# SYNOPSIS
1+
# SYNOPSIS
2+
23
[![NPM Package](https://img.shields.io/npm/v/fixed-bn.js.svg?style=flat-square)](https://www.npmjs.org/package/fixed-bn.js)
34
[![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)
45
[![Coverage Status](https://img.shields.io/coveralls/ewasm/fixed-bn.js.svg?style=flat-square)](https://coveralls.io/r/ewasm/fixed-bn.js)
56

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

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

1011
# USAGE
12+
1113
```javascript
1214
const FixedBN = require('fixed-bn.js')
1315

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

2325
// you can also create an arbitary fixed lenght bn
2426
// max bit lenght is 199 bits and min length is 2 bits
25-
const I199 = FixedBN(199, 2)
27+
const I199 = FixedBN(199, 2)
2628
const newBnNum = new I199(390248)
2729
```
2830

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

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

3335
## factory
3436

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

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

3941
**Parameters**
4042

41-
- `maxWidth` **Integer** the max length in bits that the bn.js instance can handle
42-
- `minWidth` **Integer** the min length in bits that the bn.js instance can handle
43+
- `maxWidth` **Integer** the max length in bits that the bn.js instance can handle
44+
- `minWidth` **Integer** the min length in bits that the bn.js instance can handle
4345

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

4648
## builtin length
49+
4750
the factory has the following builtins
51+
4852
- `FixedBN.U64`
4953
- `FixedBN.U128`
5054
- `FixedBN.U160`
5155
- `FixedBN.U256`
5256

5357
## bn.js instance
58+
5459
Each instance has the following additional methods
5560

5661
## maxWidth
5762

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

6065
retuns Max Width
6166

62-
Returns **integer**
67+
Returns **integer**
6368

6469
## minWidth
6570

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

6873
retuns Min Width
6974

70-
Returns **integer**
75+
Returns **integer**
7176

7277
## fromBuffer
7378

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

7681
converts a buffer to a fixed-bn.js
7782

7883
**Parameters**
7984

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

8489
## isFixBN
8590

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

8893
checks if a BN instance is a fixed BN instance
8994

9095
**Parameters**
9196

92-
- `bn` **bn.js**
97+
- `bn` **bn.js**
9398

9499
## isSameWidth
95100

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

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

100105
**Parameters**
101106

102-
- `fixBN` **bn.js**
103-
107+
- `fixBN` **bn.js**
104108

105109
# LICENSE
106-
[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2))
110+
111+
[MPL-2.0](<https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)>)

index.js

-94
This file was deleted.

package.json

+33-8
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,48 @@
22
"name": "fixed-bn.js",
33
"version": "0.0.2",
44
"description": "bn.js wrapper that constrains numbers to a fixed width",
5-
"main": "index.js",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
67
"scripts": {
7-
"coverage": "istanbul cover ./tests/index.js",
8-
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
9-
"lint": "standard",
10-
"test": "tape ./tests/index.js"
8+
"build": "ethereumjs-config-build",
9+
"prepublishOnly": "npm run test && npm run build",
10+
"coverage": "ethereumjs-config-coverage",
11+
"coveralls": "ethereumjs-config-coveralls",
12+
"format": "ethereumjs-config-format",
13+
"format:fix": "ethereumjs-config-format-fix",
14+
"tslint": "ethereumjs-config-tslint",
15+
"tslint:fix": "ethereumjs-config-tslint-fix",
16+
"tsc": "ethereumjs-config-tsc",
17+
"lint": "ethereumjs-config-lint",
18+
"lint:fix": "ethereumjs-config-lint-fix",
19+
"unitTests": "npm run build && tape ./tests/*.js",
20+
"test": "npm run lint && npm run unitTests",
21+
"test:fix": "npm run lint:fix && npm run unitTests",
22+
"docs:build": "typedoc --out docs --mode file --readme none --theme markdown --mdEngine github --gitRevision master --excludeNotExported src/*.ts"
1123
},
1224
"keywords": [
1325
"bn.js"
1426
],
1527
"author": "mjbecze <[email protected]>",
1628
"license": "MPL-2.0",
1729
"devDependencies": {
30+
"@ethereumjs/config-nyc": "^1.1.1",
31+
"@ethereumjs/config-prettier": "^1.1.1",
32+
"@ethereumjs/config-tsc": "^1.1.1",
33+
"@ethereumjs/config-tslint": "^1.1.1",
34+
"@types/bn.js": "^4.11.4",
35+
"@types/node": "^11.11.3",
36+
"@types/tape": "^4.2.33",
1837
"coveralls": "^3.0.0",
19-
"istanbul": "^0.4.5",
20-
"standard": "^11.0.0",
21-
"tape": "^4.6.3"
38+
"nyc": "^13.3.0",
39+
"prettier": "^1.16.4",
40+
"tape": "^4.6.3",
41+
"ts-node": "^8.0.3",
42+
"tslint": "^5.14.0",
43+
"typedoc": "^0.14.2",
44+
"typedoc-plugin-markdown": "^1.1.27",
45+
"typescript": "^3.3.3333",
46+
"typestrict": "^1.0.2"
2247
},
2348
"repository": {
2449
"type": "git",

prettier.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@ethereumjs/config-prettier')

0 commit comments

Comments
 (0)