1.0.2 • Published 5 years ago

anmatlib v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

npm GitHub package.json version GitHub repo size GitHub last commit GitHub top language GitHub issues npm collaborators GitHub followers GitHub watchersCoverage Statusnpm

anmatlib

A Javascript math library

How to use:

goldenRatio

Returns the goldenRatio property of Number

const x = 5 x.goldenRatio // 1.61803398875

round()

Rounds a number

const x = 5.9 x.round() // 6

round()

Rounds down a number

const x = 5.9 x.floor() // 5

ceil()

Rounds up a number

const x = 1.03 x.ceil() // 2

pad(x, y)

Pads a number with x 0s before '.' and y 0s after '.'

`const x = 34.801 x.pad(4,4) // 0034.8010

const y = 34.801 y.pad(4,3) // 0034.801 `

degToRad()

Takes a number and returns the results of this formula: deg * (Math.PI / 180)

`const x = 45 x.degToRad() // 0.785

const y = "a" y.degToRad() // TypeError `

radToDeg()

Covert radians to degrees from this formula: radians * (180/pi)

`const x = 0.785 x.radToDeg() // 44.977

const y = "a" y.degToRad() // TypeError `

toDollars()

Take a numeric value and return a string beginning with a '$' and rounded to two decimal places

`const x = 34.801 x.toDollars() // $34.80;

const y = 2 y.toDollars(4,3) // $2.00 `

tax(n)

Returns the tax amount

const x = 32.01 x.tax(0.56) // 32.57

interest(total, year, rate)

Calculates the interest over time

Number.interest(100, 1, 1) // 101

mortage(principal, numberOfPayments, interestRate)

Calculates mortage: M = P i(1 + i)^n / (1 + i)^n – 1

Number.mortage(100000, 30, 3.92) // 392000

intToHex()

Converts int to hex

const x = 20 x.intToHex() // 14

random(n)

Returns an integer from 0 to n - 1

const x = Number.random(5) x < 5 // true

randomRange(min, max)

Returns an integer from min to max

const x = Number.randomRange(2, 5) x < 5 // true x > 2 // true

randomColor(n)

Returns a random hex color

const a = Number.randomColor() // returns a random color in hex

Test coverage

npx jest --coverage PASS ./test.js ✓ goldenRatio (4ms) ✓ round (1ms) ✓ floor ✓ ceil ✓ pad (1ms) ✓ degToRad (3ms) ✓ radToDeg (1ms) ✓ toDollars ✓ tax (1ms) ✓ interest ✓ mortage ✓ intToHex (1ms) ✓ random functions (9ms)

console.log test.js:76 62d839

----------|----------|----------|----------|----------|-------------------| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ----------|----------|----------|----------|----------|-------------------| All files | 90.48 | 50 | 100 | 90.48 | | index.js | 90.48 | 50 | 100 | 90.48 | 36,37,46,47 | ----------|----------|----------|----------|----------|-------------------| Test Suites: 1 passed, 1 total Tests: 13 passed, 13 total Snapshots: 0 total Time: 2.103s Ran all test suites.

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago