@annapawl/math_library v2.0.0
JavaScript Math Library
This is a lightweight JavaScript library that extends the functionality of the number object.
Getting Started
Run the following command in your project folder:
npm install @annapawl/math_library --save
Then add this to your index.js file
require('@annapawl/src/math_library')
Golden Ratio
goldenRatio()
This function returns the golden ratio
Number.goldenRatio()
→ 1.61803398875
Rounding Methods
round()
This method rounds a specified number
'9.99.round()
→ 10
roundDown()
This method rounds a specified number down
'9.99.roundDown()
→ 9
roundUp()
This method rounds a specified number up
'9.2.roundUp()
→ 10
Degrees ↔ Radians
degToRad(n)
This methods converts degrees to radians
45.degToRad()
→ 0.785
radToDeg(n)
This methods converts radians to degrees
.785.RadTodeg()
→ 44.977
Money Methods
toDollars(amount)
This methods takes in a numeric value and returns a string behinning with '$' and rounded to two decimal palces
3.9.toDollars()
→ '$3.90'
plusTax(rate)
This methods takes in a numeric value and returns the amount with tax
10.plusTax(.2)
→ '$12'
plusInterest(total, year, rate)
This methods calculates interests over a specified timeline
Number.plusInterest(100,2,2)
→ 104.04
mortgage(principal, year, rate)
This methods calculates mortgage
Number.mortgage(10,5,10)
→ 100.00
Random Methods
random(n)
This method returns an integer between 0 and n-1
'random(10)
→ 8
randomRange(min,max)
This method returns an integer between specified min and max
'randomRange(50,100)
→ 71
randomColor()
This method returns a random hex value
'randomColor()
→ 8a7f43
Test Coverage
npx jest --coverage
----------|----------|----------|----------|----------|-------------------| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ----------|----------|----------|----------|----------|-------------------| All files | 100 | 100 | 100 | 100 | | index.js | 100 | 100 | 100 | 100 | | ----------|----------|----------|----------|----------|-------------------|