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

ts-x-prime

v0.1.0

Published

Library for working with prime numbers

Readme

ts-x-prime

A lightweight TypeScript library for working with prime numbers: generate primes, test for primality, and use the AKS primality test.

npm license types


Installation

npm install ts-x-prime

or with pnpm:

pnpm add ts-x-prime

or with yarn:

yarn add ts-x-prime

Features

| Function | Description | | ----------------------------- | ---------------------------------------------------------------- | | generateSieve(n) | Generates a boolean sieve of Eratosthenes up to n | | sieveToPrimes(s) | Converts a sieve to a list of primes | | isPrimeSieve(n, s) | Checks if n is prime using a precomputed sieve | | isPrime(n) | Checks if n is prime using the 6k ± 1 optimization | | isPrimeAKS(n) | Checks if n is prime using the AKS primality test (slow) | | zetaReal(s, terms) | Approximates the Riemann zeta function for real s | | zetaEuler(s, max) | Evaluates ζ(s) via the Euler product using primes up to max | | gamma(z) | Computes the gamma function for a complex number z | | eta(s, terms) | Dirichlet eta function η(s) for complex s with specified terms | | zeta(s, terms) | Approximates ζ(s) for complex s using analytic continuation | | new Goldbach(n).getPairs() | Getting goldbach pairs for n | | new Goldbach(n).getPrimes() | Getting goldbach primes for n |


Usage Examples

import {
  generateSieve,
  sieveToPrimes,
  isPrimeSieve,
  isPrime,
  isPrimeAKS,
  zetaReal,
  zetaEuler,
  gamma,
  eta,
  zeta,
  Complex,
  Goldbach,
} from 'ts-x-prime'

// Generate primes using sieve
const sieve = generateSieve(100)
const primes = sieveToPrimes(sieve) // [2, 3, 5, 7, 11, ..., 97]

// Check using sieve
console.log(isPrimeSieve(37, sieve)) // true
console.log(isPrimeSieve(40, sieve)) // false

// Check using 6k ± 1 method
console.log(isPrime(29)) // true
console.log(isPrime(35)) // false

// Check using AKS (slow)
console.log(isPrimeAKS(13)) // true
console.log(isPrimeAKS(15)) // false

// Real zeta function
console.log(zetaReal(2)) // ~1.6449 (π²/6)

// Zeta via Euler product
console.log(zetaEuler(2)) // ~1.6449

// Gamma function
console.log(gamma(new Complex(0.5, 0))) // ~1.772 (√π)

// Dirichlet eta
console.log(eta(new Complex(1, 0), 10000)) // ~ln(2)

// Full zeta function (complex)
console.log(zeta(new Complex(2, 0))) // ~1.6449

// Getting goldbach pairs for 10
console.log(new Goldbach(10).getPairs()) // [[3, 7], [5, 5]]

Notes

  • isPrimeAKS uses the deterministic AKS algorithm and is intended for theoretical or educational use. It's very slow for large inputs.
  • isPrime uses the 6k ± 1 method, which is efficient for medium-sized numbers.
  • zetaReal, zetaEuler, zeta, eta, and gamma are provided for exploration of analytic number theory.
  • For large batches of prime checks, prefer generating a sieve first.

License

MIT © rekmixa