@santi100/eratosthenes-sieve
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Santi's Energetic Sieve of Eratosthenes

Build Status npm homepage GitHub stars License Bundlephobia stats

  • 🚀 Lightweight and fast
  • 👴 ES3-compliant
  • 💻 Portable between the browser and Node.js
  • 📘 Includes TypeScript definitions

What's this?

This is a simple, lightweight implementation of the Sieve of Eratosthenes

Installation

  • Via NPM: npm install @santi100/eratosthenes-sieve
  • Via Yarn: yarn add @santi100/eratosthenes-sieve
  • Via PNPM: pnpm install @santi100/eratosthenes-sieve

API

  • function sieve(n: number): number[]; Finds all prime numbers from 2 up to a given number n.

    Name Type Description Optional? Default
    n number The upper limit of the range of numbers to check for primes. No N/A

Usage

// Import the sieve function
const sieve = require('@santi100/eratosthenes-sieve'); // CJS
import sieve = require('@santi100/eratosthenes-sieve'); // TypeScript
import sieve from '@santi100/eratosthenes-sieve'; // ESM


// Use the sieve function to find prime numbers up to 100
const primesUpTo100 = sieve(100);

// Print the prime numbers
console.log('Prime numbers up to 100:', primesUpTo100); // outputs [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

Contribute

Wanna contribute? File an issue or pull request! Look at the contribution instructions and make sure you follow the contribution Code of Conduct.

Package Sidebar

Install

npm i @santi100/eratosthenes-sieve

Weekly Downloads

6

Version

0.0.1

License

MIT

Unpacked Size

33.5 kB

Total Files

37

Last publish

Collaborators

  • santi100a