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

primalib

v0.2.3

Published

PrimaLib - Complete math library with lazy sets, geometry, number theory, and more

Readme

🌟 PrimaLib: Math Made Magical ✨

"Because math should feel like poetry, not paperwork."

PrimaLib is your friendly algebraic playground for math operations, geometry, and infinite sequences using lazy sets. Think of it as a magical transformer that makes scalars, arrays, and infinite streams all dance to the same tune.

At its heart is primaSet ⭐ - the shining star that treats everything as a set: numbers, objects, trees, DOM elements, or infinite streams of primes.

🚀 Quick Start

Install

npm install primalib

Or install individual submodules:

npm install @primalib/core
npm install @primalib/num
npm install @primalib/geo
# etc.

For web development (optional, mainly for dev/tests):

npm install @primalib/web

Hello World

import { N, sq, sum } from 'primalib'

// Sum of squares of first 10 naturals: 1² + 2² + ... + 10² = 385
console.log(sum(sq(N(10))))  // → 385 ✨

// Works with arrays too!
console.log(sum(sq([1,2,3,4,5])))  // → 55

That's it! You're doing math like a wizard now. 🎩✨

⭐ Core Magic: primaSet

primaSet is PrimaLib's superpower - it treats everything as a set, seamlessly handling both finite and infinite sequences.

import { primaSet, primes, N } from 'primalib'

// Everything is a set!
primaSet(42)                    // → {42}
primaSet([1,2,3])               // → {1,2,3}
primaSet(N())                   // → {1,2,3,...} (infinite!)
primaSet(primes)                // → {2,3,5,7,11,...} (infinite primes!)
primaSet(null)                  // → {} // empty

primes.get(0)                    // → 2 (first prime)
primes.take(10)                 // → [2,3,5,7,11,13,17,19,23,29]
// Infinite sequences work like arrays
N(10).sq().sum()                // → 385 (sum of squares)

The magic: primaSet handles infinite sequences as naturally as finite arrays - no memory explosions, no precomputation, just pure lazy evaluation.

📚 Documentation

Quick Access

Module Documentation

🎯 What's Included

PrimaLib provides:

  • Infinite Sequences: Primes, naturals, integers - all as lazy sets
  • Number Theory: Prime constellations, geometric sieves, CRT addresses
  • Geometry: Points, hypercubes, hyperplanes in n-dimensional space
  • Linear Algebra: Vectors, matrices, polynomials
  • Statistics: Descriptive stats, correlation, time series
  • Topology: Simplicial complexes, homology groups, Euler characteristics
  • Trees: Tree structures with Virtual DOM foundation
  • Web Pipeline: Universal web tools for demos and examples

🎨 Examples

Infinite Primes

import { primes } from 'primalib'

primes.get(0)      // → 2
primes.get(4)     // → 11
primes.take(10)   // → [2,3,5,7,11,13,17,19,23,29]

Geometry

import { point, space } from 'primalib'

point(1,2).add(point(3,4))  // → point(4,6)
space([0,0,0], [1,1,1]).vertices()  // → 8 corner points

Linear Algebra

import { vector, matrix } from 'primalib'

vector(1,2,3).dot(vector(4,5,6))  // → 32
matrix([[1,2],[3,4]]).det()       // → -2

Statistics

import { mean, stddev, correlation } from 'primalib'

mean([1,2,3,4,5])  // → 3
correlation([1,2,3], [2,4,6])  // → 1.0

🔌 Plugin System

Add your own operations:

import { primaSet } from 'primalib'

primaSet.plugin({
  cube: x => x * x * x
})


primaSet([1,2,3]).cube()  // → [1, 8, 27]

🧪 Testing

npm test

163+ tests covering all modules and operations.

📖 Learn More

  • Quick Reference: See QUICKREF.md for quick lookup ⚡
  • Getting Started: See PRIMALIB.md for complete overview
  • Core Concepts: Read PRIMASET.md to understand the foundation
  • Module Details: Check individual module documentation for specific features
  • Examples: See examples/README.md for example guide
  • Contributing: See CONTRIBUTING.md to contribute

🎓 Philosophy

PrimaLib believes math should be playful. It bridges:

  • Imperative & Functional: Chain methods or compose functions
  • Finite & Infinite: Work with arrays or never-ending streams
  • Simple & Complex: Start with scalars, scale to hypercubes

One abstraction. Infinite possibilities. 🌌


PrimaLibMath as poetry. Sets as magic. Infinity as playground.

Ready to explore? Start with PRIMALIB.md for the complete guide, or dive into PRIMASET.md to understand the core magic.