wrapper-for-dinero
v0.0.2
Published
Wrapper class for the Dinero.js library that converts all inputs to minor currency before it reaches Dinero. Results are returned in major currency.
Downloads
16
Readme
wrapper-for-dinero
This is a wrapper class for Dinero.js. The purpose of it is to allow you to pass in major currency units and they will be converted to minor currency before Dinero.js performs the money math. Returned values are in the form of an object and can be accessed directly with
.amount
or you can use.toFormat()
to return a currency formatted value. Default is$0.00
.
Currently, this class sets defaults to USD with format of
$0.00
. Future plans are to allow options to be passed in that will be passed into Dinero to allow for more flexibility.
Install
npm install wrapper-for-dinero
Usage
After install you will need to require in the file.
const { Money } = require('wrapper-for-dinero');
Instantiating the class without an amount defaults to 0.
Arithmetic
This class follows the same arithmetic rules as Dinero.js. PEMDAS is not observed and all math operations are performed sequentially.
Example:
let money = new Money();
money.add(3).multiply(2).subtract(1).amount
results in 5.
Available arithmetic methods:
.add()
.subtract()
.multiply()
.divide()
License
MIT License
Copyright (c) [2019] [Lukas Nord]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.