{"id":21420205,"url":"https://github.com/ethjs/ethjs-unit","last_synced_at":"2025-04-13T03:13:26.415Z","repository":{"id":55965356,"uuid":"74910803","full_name":"ethjs/ethjs-unit","owner":"ethjs","description":"A simple module for handling Ethereum units.","archived":false,"fork":false,"pushed_at":"2024-08-27T20:34:48.000Z","size":117,"stargazers_count":24,"open_issues_count":8,"forks_count":21,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T03:12:24.059Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/ethjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2016-11-27T19:58:46.000Z","updated_at":"2024-12-31T12:16:01.000Z","dependencies_parsed_at":"2025-02-15T14:11:16.453Z","dependency_job_id":"138bd72f-da4c-43b9-9b41-70b955ae9adc","html_url":"https://github.com/ethjs/ethjs-unit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethjs%2Fethjs-unit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethjs%2Fethjs-unit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethjs%2Fethjs-unit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethjs%2Fethjs-unit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethjs","download_url":"https://codeload.github.com/ethjs/ethjs-unit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248657923,"owners_count":21140846,"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-22T20:13:24.443Z","updated_at":"2025-04-13T03:13:26.395Z","avatar_url":"https://github.com/ethjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ethjs-unit\n\n\u003cdiv\u003e\n  \u003c!-- Dependency Status --\u003e\n  \u003ca href=\"https://david-dm.org/ethjs/ethjs-unit\"\u003e\n    \u003cimg src=\"https://david-dm.org/ethjs/ethjs-unit.svg\"\n    alt=\"Dependency Status\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- devDependency Status --\u003e\n  \u003ca href=\"https://david-dm.org/ethjs/ethjs-unit#info=devDependencies\"\u003e\n    \u003cimg src=\"https://david-dm.org/ethjs/ethjs-unit/dev-status.svg\" alt=\"devDependency Status\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Build Status --\u003e\n  \u003ca href=\"https://travis-ci.org/ethjs/ethjs-unit\"\u003e\n    \u003cimg src=\"https://travis-ci.org/ethjs/ethjs-unit.svg\"\n    alt=\"Build Status\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- NPM Version --\u003e\n  \u003ca href=\"https://www.npmjs.org/package/ethjs-unit\"\u003e\n    \u003cimg src=\"http://img.shields.io/npm/v/ethjs-unit.svg\"\n    alt=\"NPM version\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Test Coverage --\u003e\n  \u003ca href=\"https://coveralls.io/r/ethjs/ethjs-unit\"\u003e\n    \u003cimg src=\"https://coveralls.io/repos/github/ethjs/ethjs-unit/badge.svg\" alt=\"Test Coverage\" /\u003e\n  \u003c/a\u003e\n\n  \u003c!-- Javascript Style --\u003e\n  \u003ca href=\"http://airbnb.io/javascript/\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/code%20style-airbnb-brightgreen.svg\" alt=\"js-airbnb-style\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\nA simple module for handling Ethereum unit convertion.\n\n## Install\n\n```\nnpm install --save ethjs-unit\n```\n\n## Usage\n\n```js\nconst unit = require('ethjs-unit');\n\nvar val1 = unit.toWei(249824778, 'ether');\n\n// result \u003cBN ...\u003e 249824778000000000000000000\n\nvar val2 = unit.fromWei('249824778000000000000000000', 'ether');\n\n// result '249824778'\n```\n\n## About\n\nA port from the `web3.js` library, that just handles the unit convertion between the various types of Ethereum currency units.\n\nNote, the `toWei` returns a BN instance while `fromWei` always returns a string number.\n\n## Amorphic Data Formatting\n\n`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.\n\n## Methods Available \u0026 Objects\n\n```\nunitMap         { unitName: singleUnitWeiValue, ... }\ngetValueOfUnit  \u003cFunction (unit) : (BN)\u003e\ntoWei           \u003cFunction (value, unit) : (BN)\u003e\nfromWei         \u003cFunction (value, unit) : (String)\u003e\n```\n\n## Supported Units\n\n```\n'wei':          '1',\n'kwei':         '1000',\n'Kwei':         '1000',\n'babbage':      '1000',\n'femtoether':   '1000',\n'mwei':         '1000000',\n'Mwei':         '1000000',\n'lovelace':     '1000000',\n'picoether':    '1000000',\n'gwei':         '1000000000',\n'Gwei':         '1000000000',\n'shannon':      '1000000000',\n'nanoether':    '1000000000',\n'nano':         '1000000000',\n'szabo':        '1000000000000',\n'microether':   '1000000000000',\n'micro':        '1000000000000',\n'finney':       '1000000000000000',\n'milliether':   '1000000000000000',\n'milli':        '1000000000000000',\n'ether':        '1000000000000000000',\n'kether':       '1000000000000000000000',\n'grand':        '1000000000000000000000',\n'mether':       '1000000000000000000000000',\n'gether':       '1000000000000000000000000000',\n'tether':       '1000000000000000000000000000000'\n```\n\n## Why BN.js?\n\n`ethjs` has made a policy of using `BN.js` accross all of our modules. Here are some reasons why:\n\n  1. Lighter than alternatives (BigNumber.js)\n  2. Faster than most alternatives, see [benchmarks](https://github.com/indutny/bn.js/issues/89)\n  3. Used by the Ethereum foundation across all [`ethereumjs`](https://github.com/ethereumjs) repositories\n  4. Is already used by a critical JS dependency of many ethereum packages, see package [`elliptic`](https://github.com/indutny/elliptic)\n  5. Does not support decimals or floats (for greater precision), remember, the Ethereum blockchain cannot and will not support float values or decimal numbers\n\n## Contributing\n\nPlease 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.\n\n## Guides\n\nYou'll find more detailed information on using `ethjs-unit` and tailoring it to your needs in our guides:\n\n- [User guide](docs/user-guide.md) - Usage, configuration, FAQ and complementary tools.\n- [Developer guide](docs/developer-guide.md) - Contributing to `ethjs-unit`, writing coverage and updates.\n\n## Help out\n\nThere 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:\n\n- Create, enhance, and debug ethjs rules (see our guide to [\"Working on rules\"](./github/CONTRIBUTING.md)).\n- Improve documentation.\n- Chime in on any open issue or pull request.\n- Open new issues about your ideas for making `ethjs-unit` better, and pull requests to show us how your idea works.\n- Add new tests to *absolutely anything*.\n- Create or contribute to ecosystem tools, like modules for encoding or contracts.\n- Spread the word.\n\nPlease consult our [Code of Conduct](CODE_OF_CONDUCT.md) docs before helping out.\n\nWe communicate via [issues](https://github.com/ethjs/ethjs-unit/issues) and [pull requests](https://github.com/ethjs/ethjs-unit/pulls).\n\n## Important documents\n\n- [Changelog](CHANGELOG.md)\n- [Code of Conduct](CODE_OF_CONDUCT.md)\n- [License](https://raw.githubusercontent.com/ethjs/ethjs-unit/master/LICENSE)\n\n## Licence\n\nThis project is licensed under the MIT license, Copyright (c) 2016 Nick Dodson. For more information see LICENSE.md.\n\n```\nThe MIT License\n\nCopyright (c) 2016 Nick Dodson. nickdodson.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethjs%2Fethjs-unit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethjs%2Fethjs-unit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethjs%2Fethjs-unit/lists"}