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 🙏

© 2026 – Pkg Stats / Ryan Hefner

math-problems

v0.2.0

Published

Solve math problems easily with this utility library.

Downloads

18

Readme

math-problems

Solve math problems easily with this utility library. Includes temperature conversions, geometric area calculations, number utilities, and population statistics.

Installation

npm install math-problems

Usage

import {
  area,
  toCelsius,
  isEven,
  populationDensity,
  population,
} from 'math-problems';

// Calculate the area of a circle with radius 5
console.log(area.circle(5)); // 78

// Convert 73°F to Celsius
console.log(toCelsius(73)); // 22.777... (repeating decimal)

// Check if a number is even
console.log(isEven(4)); // true

// Calculate population density
console.log(populationDensity(11452000, 1483)); // 7724

// Access population data
console.log(population.br.sp); // 11452000

API Documentation

📐 Area Calculations

All area functions return an object with a floored area value.

  • Rectangle
    rect(base: number, height: number)
    area.rect(4, 5) ➔ 20

  • Triangle
    triangle(base: number, height: number)
    area.triangle(4, 5) ➔ 10

  • Rhombus
    rhombus(D: number, d: number)
    area.rhombus(8, 6) ➔ 24

  • Trapezoid
    trapezoid(B: number, b: number, height: number)
    area.trapezoid(10, 6, 5) ➔ 40

  • Circle
    circle(radius: number)
    area.circle(3) ➔ 28

🌡️ Temperature Conversions

Convert between Celsius (°C), Fahrenheit (°F), and Kelvin (K).

  • toCelsius
    toCelsius(temperature: number, unit?: 'F' | 'K')
    Default unit: Fahrenheit
    toCelsius(32) ➔ 0
    toCelsius(273.15, 'K') ➔ 0

  • toFahrenheit
    toFahrenheit(temperature: number, unit?: 'C' | 'K')
    Default unit: Celsius
    toFahrenheit(0) ➔ 32
    toFahrenheit(273.15, 'K') ➔ 32

  • toKelvin
    toKelvin(temperature: number, unit?: 'C' | 'F')
    Default unit: Celsius
    toKelvin(0) ➔ 273
    toKelvin(32, 'F') ➔ 273

🔢 Number Utilities

  • isEven(number)
    Returns true if the number is even.

  • isOdd(number)
    Returns true if the number is odd.

  • difference(x, y)
    Returns the floored difference between two numbers.
    difference(10, 3.8) ➔ 6

  • PI
    Math.PI constant (≈3.14159).

📊 Interpoolation and regression

  • interpolation(input: { function: (number) => number, value: number, points: number[] })
    Interpolates a set of data points from a function and value through Newton Interpolation.
interpolation({
  function: Math.log,
  value: 2,
  points: [1, 4, 6]
})

➔ 0.5658443469009827
  • regression(input: number[])
    Computes the linear and polynomial regression from a set of data points.
regression([
  [-2, -1],
  [1, 2],
  [4, 59],
  [-1, 4],
  [3, 24],
  [-4, -53]
]);

➔ {
  linear: {
    m: 10.97864768683274,
    b: 4.00355871886121
  },
  polynomial: {
    a: 6.689189189189188,
    b: 11.060810810810809,
    c: -0.34459459459459435
  }
}

📊 Population Statistics

  • populationDensity(population, area)
    Returns density (people per unit area).

  • birthRate(births, population)
    Returns births per 1000 people.

  • deathRate(deaths, population)
    Returns deaths per 1000 people.

  • Population Data
    Pre-defined population figures (as of Feb 2025):

    population.br.sp; // Brazil São Paulo: 11,452,000
    population.us.ny; // USA New York: 20,201,249

Contributing

Contributions are welcome! Please follow the contribution guidelines.

  1. Clone the repository:
    git clone https://github.com/igorwastaken/math-utils.git
  2. Install dependencies:
    npm install
  3. Run tests:
    npm test

License

MIT © Igor Figueiredo
Full License Text