
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
TokenUnit is a conversion library for Ethereum-based tokens to easily scale tokens and convert between tokens and ether. Future releases will include the ability to convert between tokens at real-time prices based on passing in an Oracle class.
$ npm install --save token-unit
If you want the ES5 version, use:
$ npm install --save token-unit-es5
const TokenUnit = require('token-unit');
// Or for ES5 compatible, use:
// var TokenUnit = require('token-unit-es5');
let purchaseValue = new TokenUnit(10, 'ether');
let myTokenAmount = purchaseValue.to('myToken');
let newAmount = myTokenAmount.add(new TokenUnit(200, 'kwei'));
let executeOrderAmount = newAmount.get('anchorAmount');
{
scaledUnit (string),
scaledAmount (string representing a number),
anchorUnit (string),
anchorAmount (string representing a number),
etherEquivalent (string representing a number)
}
We treat the calling object as immutable, hence all public methods return new instances of a TokenUnit with the new values from the operation.
new TokenUnit(amount, unit, options = {}): Create a new TokenUnit of the specified amount and unit combination. Optional options object (unsupported as of yet). Returns a new TokenUnit.to(unit): Convert the TokenUnit to the new specified unit. This function either does either a scaling or currency conversion. A scaling conversion, which is re-classifying the same unit into a new scale value (i.e. changing cents to dollars), is done when the two units share a common nominal base unit. A currency conversion occurs when the two units do not share a common nominal base unit (i.e. changing cents to yuan). This method returns a new TokenUnit.add(tokenUnit): Add a TokenUnit to another TokenUnit. If the two do not share a common nominal base unit, then we do a currency conversion using the to() method. Returns a new TokenUnit of the same scale as the calling TokenUnit.subtract(tokenUnit): Subtract a TokenUnit to another TokenUnit. If the two do not share a common nominal base unit, then we do a currency conversion using the to() method. Returns a new TokenUnit of the same scale as the calling TokenUnit.sub(tokenUnit): A facade method for subtract() because how many times do developers get confused if it's sub() or subtract() in libraries?!toString(): Output the minimal information needed for console logging. It actually returns an object.get(key): Get a specific key from the toString() object. Useful if you want to display the data.Since we made this library compatible with both NodeJS and React, we realized that there is an issue with Webpack and ES6 files. To solve this, we released an ES5 compatible version of the library as v0.2.1. Moving forward, we will transpile our ES6 code to ES5 standards for publishing on NPM.
Reach out to the Airswap team at team@airswap.io with any questions or comments. We welcome well-constructed PRs into this library.
FAQs
Convert between token units and ether units
We found that token-unit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.