Gathering detailed insights and metrics for goodeggs-money
Gathering detailed insights and metrics for goodeggs-money
Gathering detailed insights and metrics for goodeggs-money
Gathering detailed insights and metrics for goodeggs-money
Reliable money math with BigNumber wrapped inside Cents
npm install goodeggs-money
Typescript
Module System
TypeScript (97.24%)
JavaScript (2.76%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
133 Commits
41 Watchers
11 Branches
25 Contributors
Updated on Nov 09, 2022
Latest Version
2.0.2
Package Id
goodeggs-money@2.0.2
Unpacked Size
177.32 MB
Size
32.74 MB
File Count
24
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Reliable money math with BigNumber wrapped inside cents
npm install goodeggs-money
1Cents = require 'goodeggs-money'
2
3new Cents(10).toDollars() # 0.1
4new Cents(10).toNumber() # 10
5new Cents(10).toString() # "$0.10"
6
7cents = Cents.fromDollars(33.44) # Cents(3344)
8cents = cents.plus(1) # safe arithmetic
9cents.toDollars() # 33.45
10cents.equals new Cents(3345) # true
11cents.greaterThan new Cents(481) # true
12cents.lessThan new Cents(8021) # true
13
14_.sumCents([new Cents(1), new Cents(2)]) # Cents(3)
15
16new Cents(new Cents(4)) # Cents(4); safe to re-wrap Cents
17new Cents(33.44) # will throw
18new Cents(-1) # will throw
19new Cents(2).minus(3) # will throw
20new Cents(2).minus(3, maxZero: true) # Cents(0)
21new Cents(3).times(.5) # will throw
22new Cents(3).times(.5, transform: 'round') # Cents(2)
23new Cents(3).times(.5, transform: 'floor') # Cents(1)
Don't use numerical comparison functions, Cents
instances are objects
Built-in numerical comparisons (<
, >
, ==
, <=
, >=
) don't work properly
on objects. Instead use lessThan
, greaterThan
, equals
, lessThanOrEqual
,
or greaterThanOrEqual
.
Alleviate floating point errors
Floating-point math in computers is notorious for causing strange rounding errors. In JavaScript, this is particularly a problem. Example:
1> 0.10 + 0.20 20.30000000000000004
Obviously, when dealing with money, it won't do to have rounding errors like this. They can accumulate and eventually cause weird issues. Instead, better to use whole numbers everywhere, and do math with atomic cents instead of divisible dollars.
No negative money
This module will throw an exception if you do an operation that results in negative money. Our philosophy is to prefer always representing money with positive numbers, and use variable names to express the meaning. (What does it mean for amountOwed
to be negative? Not obvious. But having two variables, amountInAccount
and amountOwed
, is much more meaningful and explicit.)
Make things explicit
Using a module like this, every time you deal with money you'll be manipulating a Cents
object instead of just manipulating a generic Number
. This means that everyone encountering your code will know what your money variable is supposed to represent.
Additionally, there are operations we might want to take on money that we want to make sure happen the same way every time. This module makes these sorts of operations explicit and simple, at the cost of a bit of extra verbosity.
Support big numbers
This module uses a BigNumber
implementation, which supports arbitrarily large integers. No limits on your money!
Please follow our Code of Conduct when contributing to this project.
$ git clone https://github.com/goodeggs/goodeggs-money && cd goodeggs-money
$ npm install
$ npm test
Module scaffold generated by generator-goodeggs-npm.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/7 approved changesets -- score normalized to 8
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
23 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More