npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

just-another-math-library

v1.0.1

Published

A library with some miscellaneous math things.

Downloads

2

Readme

Just Another Math Library

npm bundle size npm Build Status Coverage Status

A library with some miscellaneous math things.

Number Types

  • Currency() - A class that represents currency. Currency expects to be initialized with an integer representing the smallest dividable unit of currency. If nothing is passed in, the Currency class will initialize to 0.
  • GOLDEN_RATIO - A constant that represents the golden ratio.

Currency Methods

  • add(n) - Add a Currency number and n.
  • subtract(n) - Subtract n from the Currency number.
  • multiply(n) - Multiply the Currency number by n.
  • divide(n) - Divide the Currency number by n.
  • split(n) - Split the Currency number into n ways. This does not modify the Currency number.

Number Prototype Methods

  • .round() - Rounds a number normally, but callable on the number prototype.
  • .floor() - Floors a number normally, but callable on the number prototype.
  • .ceil() - Ceils a number normally, but callable on the number prototype.
  • .pad(left, right) - Pads a number with zeros, and turns it into a string. Will pad left number of zeros to the left of the decimal and right number of zeros to the right of the decimal.

Functions

  • degToRad(angle) - Converts a given angle, measured in degrees, to radians.
  • radToDeg(angle) - Converts a given angle, measured in radians, to degrees.
  • toDollars(amount) - Converts a number to a string, and makes it readable as a USD amount. It will add a dollar sign for amounts greater than or equal to a dollar, and a cent sign for amounts less than a dollar.
  • intlCurrencyFormat(amount, locales, currencyType) - This is a wrapper around Intl.NumberFormat(). It will convert an amount to a currency type, readable in the specified locale.
  • tax(amount, rate) - Calculates the tax on a given amount, given the tax rate. The tax rate must be in decimal format.
  • withTax(amount, rate) - Calculates the tax on a given amount, given the tax rate, and adds it to the amount. The tax rate must be in decimal format.
  • interest(principal, interestRate, terms) - Calculates the interest using the standard I = PRT equation. The interest rate must be in decimal format. The interest rate and terms must have the same unit of time (months, years, etc.).
  • monthlyMortgage(principal, interestRate, numberOfPayments) - Calculates monthly mortgage payments using the standard formula. The interest rate and number of payments must be using months.
  • intToHex(num) - Converts an integer in decimal to a number in hexadecimal. The number is also converted to a string.
  • randomRange(min, max) - Returns a random integer between the min and max, inclusive.
  • random(num) - Returns a random integer between 0 and the num, inclusive.
  • randomColor() - Returns a random hexadecimal color, formatted with a "#" as well.