Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

ethjs-unit

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethjs-unit - npm Package Compare versions

Comparing version
0.0.1
to
0.0.2
+122
.github/CONTRIBUTING.md
# Contributing to ethjs-unit
Love ethjs-unit and want to help? Thanks so much, there's something to do for everybody!
Please take a moment to review this document in order to make the contribution process easy and effective for everyone involved.
Following these guidelines helps to communicate that you respect the time of the developers managing and developing this open source project. In return, they should reciprocate that respect in addressing your issue or assessing patches and features.
## Using the issue tracker
The [issue tracker](https://github.com/ethjs/ethjs-unit/issues) is
the preferred channel for [bug reports](#bugs), [features requests](#features)
and [submitting pull requests](#pull-requests).
<a name="bugs"></a>
## Bug reports
A bug is a _demonstrable problem_ that is caused by the code in the repository.
Good bug reports are extremely helpful - thank you!
Guidelines for bug reports:
1. **Use the GitHub issue search** &mdash; check if the issue has already been reported.
2. **Check if the issue has been fixed** &mdash; try to reproduce it using the latest `master` or development branch in the repository.
3. **Isolate the problem** &mdash;
A good bug report shouldn't leave others needing to chase you up for more information. Please try to be as detailed as possible in your report. What is your environment? What steps will reproduce the issue? What browser(s) and OS
experience the problem? What would you expect to be the outcome? All these details will help people to fix any potential bugs.
Example:
> Short and descriptive example bug report title
>
> A summary of the issue and the browser/OS environment in which it occurs. If
> suitable, include the steps required to reproduce the bug.
>
> 1. This is the first step
> 2. This is the second step
> 3. Further steps, etc.
>
> `<url>` - a link to the reduced test case
>
> Any other information you want to share that is relevant to the issue being
> reported. This might include the lines of code that you have identified as
> causing the bug, and potential solutions (and your opinions on their
> merits).
<a name="features"></a>
## Feature requests
Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. It's up to *you* to make a strong case to convince the project's developers of the merits of this feature. Please provide as much detail and context as possible.
<a name="pull-requests"></a>
## Pull requests
Good pull requests - patches, improvements, new features - are a fantastic
help. They should remain focused in scope and avoid containing unrelated
commits.
**Please ask first** before embarking on any significant pull request (e.g.
implementing features, refactoring code, porting to a different language),
otherwise you risk spending a lot of time working on something that the
project's developers might not want to merge into the project.
Please adhere to the coding conventions used throughout a project (indentation,
accurate comments, etc.) and any other requirements (such as test coverage).
Adhering to the following process is the best way to get your work
included in the project:
1. [Fork](https://help.github.com/articles/fork-a-repo/) the project, clone your fork, and configure the remotes:
```bash
# Clone your fork of the repo into the current directory
git clone https://github.com/<your-username>/default.git
# Navigate to the newly cloned directory
cd default
# Assign the original repo to a remote called "upstream"
git remote add upstream https://github.com/ethjs/ethjs-unit.git
```
2. If you cloned a while ago, get the latest changes from upstream:
```bash
git checkout master
git pull upstream master
```
3. Create a new topic branch (off the main project development branch) to contain your feature, change, or fix:
```bash
git checkout -b <topic-branch-name>
```
4. Commit your changes in logical chunks. Please adhere to these [git commit message guidelines](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) or your code is unlikely be merged into the main project. Use Git's [interactive rebase](https://help.github.com/articles/about-git-rebase/) feature to tidy up your commits before making them public.
5. Locally merge (or rebase) the upstream development branch into your topic branch:
```bash
git pull [--rebase] upstream master
```
6. Push your topic branch up to your fork:
```bash
git push origin <topic-branch-name>
```
7. [Open a Pull Request](https://help.github.com/articles/using-pull-requests/)
with a clear title and description.
**DESIGN NOTE**: default follows the UNIX programming philosophy. Please consider this before contributing, keep your commits/modules concise and to the point.
Read more here:
http://www.catb.org/esr/writings/taoup/html/ch01s06.html
**IMPORTANT**: By submitting a patch, you agree to allow the project
owners to license your work under the terms of the [MIT License](LICENSE.txt).
# ethjs-unit
Before opening a new issue, please take a moment to review our [**community guidelines**](https://github.com/ethjs/ethjs-unit/blob/master/.github/CONTRIBUTING.md) to make the contribution process easy and effective for everyone involved.
**Before opening a new issue, you may find an answer in already closed issues**:
https://github.com/ethjs/ethjs-unit/issues?q=is%3Aissue+is%3Aclosed
## Issue Type
- [ ] Bug (https://github.com/ethjs/ethjs-unit/blob/master/.github/CONTRIBUTING.md#bug-reports)
- [ ] Feature (https://github.com/ethjs/ethjs-unit/blob/master/.github/CONTRIBUTING.md#feature-requests)
## Description
(Add images if possible)
## Steps to reproduce
(Add link to a demo on https://jsfiddle.net or similar if possible)
# Versions
- Node/NPM:
- Browser:
## ethjs-unit
Thank you for contributing! Please take a moment to review our [**contributing guidelines**](https://github.com/ethjs/ethjs-unit/blob/master/.github/CONTRIBUTING.md)
to make the process easy and effective for everyone involved.
**Please open an issue** before embarking on any significant pull request, especially those that
add a new library or change existing tests, otherwise you risk spending a lot of time working
on something that might not end up being merged into the project.
Before opening a pull request, please ensure:
- [ ] You have followed our [**contributing guidelines**](https://github.com/ethjs/ethjs-unit/blob/master/.github/CONTRIBUTING.md)
- [ ] Pull request has tests (we are going for 100% coverage!)
- [ ] Code is well-commented, linted and follows project conventions
- [ ] Documentation is updated (if necessary)
- [ ] Internal code generators and templates are updated (if necessary)
- [ ] Description explains the issue/use-case resolved and auto-closes related issues
Be kind to code reviewers, please try to keep pull requests as small and focused as possible :)
**IMPORTANT**: By submitting a patch, you agree to allow the project
owners to license your work under the terms of the [MIT License](https://github.com/ethjs/ethjs-unit/blob/master/LICENSE.md).
+6
-0

@@ -0,1 +1,7 @@

# 0.0.2 -- ethjs-unit
1. More test coverage
2. Config
3. More docs
# 0.0.1 -- ethjs-unit

@@ -2,0 +8,0 @@

+26
-20
{
"name": "ethjs-unit",
"version": "0.0.1",
"version": "0.0.2",
"description": "A simple module for handling Ethereum units (e.g. 'ether', 'wei', etc...)",

@@ -15,7 +15,29 @@ "main": "./src/index.js",

"lint:staged": "lint-staged",
"coveralls": "cat ./coverage/lcov/lcov.info | coveralls"
"test-travis": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- src/tests/**/*.js -R spec --timeout 2000000",
"coveralls": "npm run test-travis && cat ./coverage/lcov.info | coveralls"
},
"engines": {
"npm": ">=3",
"node": ">=6.5.0"
},
"dependencies": {
"bignumber.js": "^3.0.1"
"bignumber.js": "3.0.1"
},
"devDependencies": {
"babel-eslint": "7.1.0",
"chai": "3.5.0",
"coveralls": "2.11.9",
"eslint": "2.10.1",
"istanbul": "0.4.5",
"eslint-config-airbnb": "9.0.1",
"eslint-import-resolver-webpack": "0.2.4",
"eslint-plugin-import": "1.8.0",
"eslint-plugin-jsx-a11y": "1.2.0",
"eslint-plugin-react": "5.1.1",
"eventsource-polyfill": "0.9.6",
"lint-staged": "1.0.1",
"mocha": "3.1.2",
"pre-commit": "1.1.3",
"web3": "0.17.0-beta"
},
"keywords": [

@@ -56,21 +78,5 @@ "ethereum",

"type": "git",
"url": "git://github.com/silentcicero/ethjs-unit"
"url": "git://github.com/ethjs/ethjs-unit"
},
"license": "MIT",
"devDependencies": {
"babel-eslint": "7.1.0",
"chai": "^3.5.0",
"coveralls": "2.11.9",
"eslint": "2.10.1",
"eslint-config-airbnb": "9.0.1",
"eslint-import-resolver-webpack": "0.2.4",
"eslint-plugin-import": "1.8.0",
"eslint-plugin-jsx-a11y": "1.2.0",
"eslint-plugin-react": "5.1.1",
"eventsource-polyfill": "0.9.6",
"lint-staged": "1.0.1",
"mocha": "^3.1.2",
"pre-commit": "1.1.3",
"web3": "^0.17.0-beta"
},
"babel": {

@@ -77,0 +83,0 @@ "presets": [

@@ -5,4 +5,4 @@ ## ethjs-unit

<!-- Dependency Status -->
<a href="https://david-dm.org/SilentCicero/ethjs-unit">
<img src="https://david-dm.org/SilentCicero/ethjs-unit.svg"
<a href="https://david-dm.org/ethjs/ethjs-unit">
<img src="https://david-dm.org/ethjs/ethjs-unit.svg"
alt="Dependency Status" />

@@ -12,9 +12,9 @@ </a>

<!-- devDependency Status -->
<a href="https://david-dm.org/SilentCicero/ethjs-unit#info=devDependencies">
<img src="https://david-dm.org/SilentCicero/ethjs-unit/dev-status.svg" alt="devDependency Status" />
<a href="https://david-dm.org/ethjs/ethjs-unit#info=devDependencies">
<img src="https://david-dm.org/ethjs/ethjs-unit/dev-status.svg" alt="devDependency Status" />
</a>
<!-- Build Status -->
<a href="https://travis-ci.org/SilentCicero/ethjs-unit">
<img src="https://travis-ci.org/SilentCicero/ethjs-unit.svg"
<a href="https://travis-ci.org/ethjs/ethjs-unit">
<img src="https://travis-ci.org/ethjs/ethjs-unit.svg"
alt="Build Status" />

@@ -29,2 +29,7 @@ </a>

<!-- Test Coverage -->
<a href="https://coveralls.io/r/ethjs/ethjs-unit">
<img src="https://coveralls.io/repos/github/ethjs/ethjs-unit/badge.svg" alt="Test Coverage" />
</a>
<!-- Javascript Style -->

@@ -73,3 +78,2 @@ <a href="http://airbnb.io/javascript/">

fromWei <Function (value, unit) : (BigNumber)>
getValueOfUnit <Function (value) : (BigNumber)>
```

@@ -135,3 +139,3 @@

We communicate via [issues](https://github.com/SilentCicero/ethjs-unit/issues) and [pull requests](https://github.com/SilentCicero/ethjs-unit/pulls).
We communicate via [issues](https://github.com/ethjs/ethjs-unit/issues) and [pull requests](https://github.com/ethjs/ethjs-unit/pulls).

@@ -142,3 +146,3 @@ ## Important documents

- [Code of Conduct](CODE_OF_CONDUCT.md)
- [License](https://raw.githubusercontent.com/SilentCicero/ethjs-unit/master/LICENSE)
- [License](https://raw.githubusercontent.com/ethjs/ethjs-unit/master/LICENSE)

@@ -145,0 +149,0 @@ ## Licence

@@ -146,3 +146,2 @@ const BigNumber = require('bignumber.js');

fromWei,
getValueOfUnit,
};

@@ -7,10 +7,10 @@ const units = require('../index.js'); // eslint-disable-line

function testRandomUnitAndNumber() {
function testRandomunitsAndNumber() {
const stringTestValue = String(Math.floor((Math.random() * 1000000000000000) + 1));
const testValue = new BigNumber(stringTestValue);
const totalTypes = Object.keys(units.unitMap).length;
const randomUnitType = Object.keys(units.unitMap)[Math.floor((Math.random() * (totalTypes - 1)) + 1)];
const randomunitsType = Object.keys(units.unitMap)[Math.floor((Math.random() * (totalTypes - 1)) + 1)];
assert.equal(units.toWei(testValue, randomUnitType).toString(10), web3.toWei(testValue, randomUnitType).toString(10));
assert.equal(units.fromWei(testValue, randomUnitType).toString(10), web3.fromWei(testValue, randomUnitType).toString(10));
assert.equal(units.toWei(testValue, randomunitsType).toString(10), web3.toWei(testValue, randomunitsType).toString(10));
assert.equal(units.fromWei(testValue, randomunitsType).toString(10), web3.fromWei(testValue, randomunitsType).toString(10));
}

@@ -22,3 +22,3 @@

for (var i = 0; i < 100000; i++) { // eslint-disable-line
testRandomUnitAndNumber();
testRandomunitsAndNumber();
}

@@ -28,1 +28,108 @@ });

});
describe('fromWei', () => {
it('should return the correct value', () => {
assert.equal(units.fromWei(1000000000000000000, 'wei').toString(10), '1000000000000000000');
assert.equal(units.fromWei(1000000000000000000, 'kwei').toString(10), '1000000000000000');
assert.equal(units.fromWei(1000000000000000000, 'mwei').toString(10), '1000000000000');
assert.equal(units.fromWei(1000000000000000000, 'gwei').toString(10), '1000000000');
assert.equal(units.fromWei(1000000000000000000, 'szabo').toString(10), '1000000');
assert.equal(units.fromWei(1000000000000000000, 'finney').toString(10), '1000');
assert.equal(units.fromWei(1000000000000000000, 'ether').toString(10), '1');
assert.equal(units.fromWei(1000000000000000000, 'kether').toString(10), '0.001');
assert.equal(units.fromWei(1000000000000000000, 'grand').toString(10), '0.001');
assert.equal(units.fromWei(1000000000000000000, 'mether').toString(10), '0.000001');
assert.equal(units.fromWei(1000000000000000000, 'gether').toString(10), '0.000000001');
assert.equal(units.fromWei(1000000000000000000, 'tether').toString(10), '0.000000000001');
});
});
describe('toWei', () => {
it('should return the correct value', () => {
assert.equal(units.toWei(1, 'wei').toString(10), '1');
assert.equal(units.toWei(1, 'kwei').toString(10), '1000');
assert.equal(units.toWei(1, 'Kwei').toString(10), '1000');
assert.equal(units.toWei(1, 'babbage').toString(10), '1000');
assert.equal(units.toWei(1, 'mwei').toString(10), '1000000');
assert.equal(units.toWei(1, 'Mwei').toString(10), '1000000');
assert.equal(units.toWei(1, 'lovelace').toString(10), '1000000');
assert.equal(units.toWei(1, 'gwei').toString(10), '1000000000');
assert.equal(units.toWei(1, 'Gwei').toString(10), '1000000000');
assert.equal(units.toWei(1, 'shannon').toString(10), '1000000000');
assert.equal(units.toWei(1, 'szabo').toString(10), '1000000000000');
assert.equal(units.toWei(1, 'finney').toString(10), '1000000000000000');
assert.equal(units.toWei(1, 'ether').toString(10), '1000000000000000000');
assert.equal(units.toWei(1, 'kether').toString(10), '1000000000000000000000');
assert.equal(units.toWei(1, 'grand').toString(10), '1000000000000000000000');
assert.equal(units.toWei(1, 'mether').toString(10), '1000000000000000000000000');
assert.equal(units.toWei(1, 'gether').toString(10), '1000000000000000000000000000');
assert.equal(units.toWei(1, 'tether').toString(10), '1000000000000000000000000000000');
assert.equal(units.toWei(1, 'kwei').toString(10), units.toWei(1, 'femtoether').toString(10));
assert.equal(units.toWei(1, 'szabo').toString(10), units.toWei(1, 'microether').toString(10));
assert.equal(units.toWei(1, 'finney').toString(10), units.toWei(1, 'milliether').toString(10));
assert.equal(units.toWei(1, 'milli').toString(10), units.toWei(1, 'milliether').toString(10));
assert.equal(units.toWei(1, 'milli').toString(10), units.toWei(1000, 'micro').toString(10));
assert.throws(() => { units.toWei(1, 'wei1'); }, Error);
});
});
const tests = [
{ value: function () {}, is: false }, // eslint-disable-line
{ value: new Function(), is: false }, // eslint-disable-line
{ value: 'function', is: false },
{ value: {}, is: false },
{ value: new String('hello'), is: false }, // eslint-disable-line
{ value: new BigNumber(0), is: true },
{ value: 132, is: false },
{ value: '0x12', is: false },
];
describe('isBigNumber', () => {
tests.forEach((test) => {
it(`shoud test if value ${test.value} is BigNumber: ${test.is}`, () => {
assert.equal(units.isBigNumber(test.value), test.is);
});
});
});
const toBigNumberTests = [
{ value: 1, expected: '1' },
{ value: '1', expected: '1' },
{ value: '0x1', expected: '1' },
{ value: '0x01', expected: '1' },
{ value: 15, expected: '15' },
{ value: '15', expected: '15' },
{ value: '0xf', expected: '15' },
{ value: '0x0f', expected: '15' },
{ value: new BigNumber('f', 16), expected: '15' },
{ value: -1, expected: '-1' },
{ value: '-1', expected: '-1' },
{ value: '-0x1', expected: '-1' },
{ value: '-0x01', expected: '-1' },
{ value: -15, expected: '-15' },
{ value: '-15', expected: '-15' },
{ value: '-0xf', expected: '-15' },
{ value: '-0x0f', expected: '-15' },
{ value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935' },
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933' },
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935' },
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933' },
{ value: 0, expected: '0' },
{ value: '0', expected: '0' },
{ value: '0x0', expected: '0' },
{ value: -0, expected: '0' },
{ value: '-0', expected: '0' },
{ value: '-0x0', expected: '0' },
{ value: new BigNumber(0), expected: '0' },
];
describe('toBigNumber', () => {
toBigNumberTests.forEach((test) => {
it(`should turn ${test.value} to 4 ${test.expected}`, () => {
assert.equal(units.toBigNumber(test.value).toString(10), test.expected);
});
});
});

Sorry, the diff of this file is not supported yet