eth-junt 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nick Dodson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ ## ethjs-unit
2
+
3
+ <div>
4
+ <!-- Dependency Status -->
5
+ <a href="https://david-dm.org/ethjs/ethjs-unit">
6
+ <img src="https://david-dm.org/ethjs/ethjs-unit.svg"
7
+ alt="Dependency Status" />
8
+ </a>
9
+
10
+ <!-- devDependency Status -->
11
+ <a href="https://david-dm.org/ethjs/ethjs-unit#info=devDependencies">
12
+ <img src="https://david-dm.org/ethjs/ethjs-unit/dev-status.svg" alt="devDependency Status" />
13
+ </a>
14
+
15
+ <!-- Build Status -->
16
+ <a href="https://travis-ci.org/ethjs/ethjs-unit">
17
+ <img src="https://travis-ci.org/ethjs/ethjs-unit.svg"
18
+ alt="Build Status" />
19
+ </a>
20
+
21
+ <!-- NPM Version -->
22
+ <a href="https://www.npmjs.org/package/ethjs-unit">
23
+ <img src="http://img.shields.io/npm/v/ethjs-unit.svg"
24
+ alt="NPM version" />
25
+ </a>
26
+
27
+ <!-- Test Coverage -->
28
+ <a href="https://coveralls.io/r/ethjs/ethjs-unit">
29
+ <img src="https://coveralls.io/repos/github/ethjs/ethjs-unit/badge.svg" alt="Test Coverage" />
30
+ </a>
31
+
32
+ <!-- Javascript Style -->
33
+ <a href="http://airbnb.io/javascript/">
34
+ <img src="https://img.shields.io/badge/code%20style-airbnb-brightgreen.svg" alt="js-airbnb-style" />
35
+ </a>
36
+ </div>
37
+
38
+ <br />
39
+
40
+ A simple module for handling Ethereum unit convertion.
41
+
42
+ ## Install
43
+
44
+ ```
45
+ npm install --save ethjs-unit
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ```js
51
+ const unit = require('ethjs-unit');
52
+
53
+ var val1 = unit.toWei(249824778, 'ether');
54
+
55
+ // result <BN ...> 249824778000000000000000000
56
+
57
+ var val2 = unit.fromWei('249824778000000000000000000', 'ether');
58
+
59
+ // result '249824778'
60
+ ```
61
+
62
+ ## About
63
+
64
+ A port from the `web3.js` library, that just handles the unit convertion between the various types of Ethereum currency units.
65
+
66
+ Note, the `toWei` returns a BN instance while `fromWei` always returns a string number.
67
+
68
+ ## Amorphic Data Formatting
69
+
70
+ `ethjs-unit` uses the [number-to-bn](http://github.com/silentcicero/number-to-bn) module to format all number values (hex or otherwise) into digestable BN.js number instances.
71
+
72
+ ## Methods Available & Objects
73
+
74
+ ```
75
+ unitMap { unitName: singleUnitWeiValue, ... }
76
+ getValueOfUnit <Function (unit) : (BN)>
77
+ toWei <Function (value, unit) : (BN)>
78
+ fromWei <Function (value, unit) : (String)>
79
+ ```
80
+
81
+ ## Supported Units
82
+
83
+ ```
84
+ 'wei': '1',
85
+ 'kwei': '1000',
86
+ 'Kwei': '1000',
87
+ 'babbage': '1000',
88
+ 'femtoether': '1000',
89
+ 'mwei': '1000000',
90
+ 'Mwei': '1000000',
91
+ 'lovelace': '1000000',
92
+ 'picoether': '1000000',
93
+ 'gwei': '1000000000',
94
+ 'Gwei': '1000000000',
95
+ 'shannon': '1000000000',
96
+ 'nanoether': '1000000000',
97
+ 'nano': '1000000000',
98
+ 'szabo': '1000000000000',
99
+ 'microether': '1000000000000',
100
+ 'micro': '1000000000000',
101
+ 'finney': '1000000000000000',
102
+ 'milliether': '1000000000000000',
103
+ 'milli': '1000000000000000',
104
+ 'ether': '1000000000000000000',
105
+ 'kether': '1000000000000000000000',
106
+ 'grand': '1000000000000000000000',
107
+ 'mether': '1000000000000000000000000',
108
+ 'gether': '1000000000000000000000000000',
109
+ 'tether': '1000000000000000000000000000000'
110
+ ```
111
+
112
+ ## Why BN.js?
113
+
114
+ `ethjs` has made a policy of using `BN.js` accross all of our modules. Here are some reasons why:
115
+
116
+ 1. Lighter than alternatives (BigNumber.js)
117
+ 2. Faster than most alternatives, see [benchmarks](https://github.com/indutny/bn.js/issues/89)
118
+ 3. Used by the Ethereum foundation across all [`ethereumjs`](https://github.com/ethereumjs) repositories
119
+ 4. Is already used by a critical JS dependency of many ethereum packages, see package [`elliptic`](https://github.com/indutny/elliptic)
120
+ 5. Does not support decimals or floats (for greater precision), remember, the Ethereum blockchain cannot and will not support float values or decimal numbers
121
+
122
+ ## Contributing
123
+
124
+ Please help better the ecosystem by submitting issues and pull requests to default. We need all the help we can get to build the absolute best linting standards and utilities. We follow the AirBNB linting standard and the unix philosophy.
125
+
126
+ ## Guides
127
+
128
+ You'll find more detailed information on using `ethjs-unit` and tailoring it to your needs in our guides:
129
+
130
+ - [User guide](docs/user-guide.md) - Usage, configuration, FAQ and complementary tools.
131
+ - [Developer guide](docs/developer-guide.md) - Contributing to `ethjs-unit`, writing coverage and updates.
132
+
133
+ ## Help out
134
+
135
+ There is always a lot of work to do, and will have many rules to maintain. So please help out in any way that you can:
136
+
137
+ - Create, enhance, and debug ethjs rules (see our guide to ["Working on rules"](./github/CONTRIBUTING.md)).
138
+ - Improve documentation.
139
+ - Chime in on any open issue or pull request.
140
+ - Open new issues about your ideas for making `ethjs-unit` better, and pull requests to show us how your idea works.
141
+ - Add new tests to *absolutely anything*.
142
+ - Create or contribute to ecosystem tools, like modules for encoding or contracts.
143
+ - Spread the word.
144
+
145
+ Please consult our [Code of Conduct](CODE_OF_CONDUCT.md) docs before helping out.
146
+
147
+ We communicate via [issues](https://github.com/ethjs/ethjs-unit/issues) and [pull requests](https://github.com/ethjs/ethjs-unit/pulls).
148
+
149
+ ## Important documents
150
+
151
+ - [Changelog](CHANGELOG.md)
152
+ - [Code of Conduct](CODE_OF_CONDUCT.md)
153
+ - [License](https://raw.githubusercontent.com/ethjs/ethjs-unit/master/LICENSE)
154
+
155
+ ## Licence
156
+
157
+ This project is licensed under the MIT license, Copyright (c) 2016 Nick Dodson. For more information see LICENSE.md.
158
+
159
+ ```
160
+ The MIT License
161
+
162
+ Copyright (c) 2016 Nick Dodson. nickdodson.com
163
+
164
+ Permission is hereby granted, free of charge, to any person obtaining a copy
165
+ of this software and associated documentation files (the "Software"), to deal
166
+ in the Software without restriction, including without limitation the rights
167
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
168
+ copies of the Software, and to permit persons to whom the Software is
169
+ furnished to do so, subject to the following conditions:
170
+
171
+ The above copyright notice and this permission notice shall be included in
172
+ all copies or substantial portions of the Software.
173
+
174
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
175
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
176
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
177
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
178
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
179
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
180
+ THE SOFTWARE.
181
+ ```