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

evolite

v1.2.0

Published

A lightweight and efficient genetic algorithm library for TypeScript and JavaScript.

Readme

Evolite

NPM Version NPM Unpacked Size NPM License

Evolite is a lightweight genetic algorithm library for TypeScript and JavaScript. It gives you a small async API for evolving any data shape as long as you can provide fitness, selection, crossover, and mutation functions.

Features

  • Small, dependency-free runtime API
  • Async fitness, selection, crossover, and mutation hooks
  • Built-in selection strategies
  • Maximize or minimize optimization modes
  • Early stop when a fitness objective is reached
  • Optional generation logging

Install

npm install evolite

If you are using Bun:

bun add evolite

Quick Start

import { GeneticAlgorithm, Optimize, randomSelection } from "evolite";

type Individual = {
  value: number;
  fitness?: number;
};

const ga = new GeneticAlgorithm<Individual>({
  initialPopulation: [{ value: 1 }, { value: 5 }, { value: 10 }, { value: 20 }],
  maxPopulationSize: 4,
  mutationRate: 0.1,
  fittestAlwaysSurvives: true,
  optimization: Optimize.Maximize,
  fitnessObjective: 100,
  logging: false,
})
  .setFitnessFunction(async (individual) => individual.value * 10)
  .setSelectionMethod(randomSelection)
  .setCrossoverMethod(async (parent1, parent2) => ({
    value: Math.round((parent1.value + parent2.value) / 2),
  }))
  .setMutationMethod(async (individual) => ({
    ...individual,
    value: individual.value + 1,
  }));

const fittest = await ga.evolve(20);
console.log(fittest);

API

GeneticAlgorithm

Create a new optimizer with:

  • initialPopulation: required array of individuals
  • maxPopulationSize: maximum population size, default 20
  • mutationRate: probability of mutation, default 0.01
  • fittestAlwaysSurvives: keep the top individual in each generation, default true
  • optimization: Optimize.Maximize or Optimize.Minimize, default Optimize.Maximize
  • fitnessObjective: optional target fitness to stop early
  • logging: print generation progress, default false
  • loggingInterval: how often to log generations, default 1
  • yieldEvery: number of generations before yielding control back to the event loop, default 0

Note yieldEvery is disabled by default (0) for maximum performance. In a browser environment, it should be set to 1 or higher to prevent the algorithm from blocking the main thread, allowing the UI to re-render and update smoothly across generations.

You then wire in the four async hooks:

  • setFitnessFunction(fitnessFunction)
  • setSelectionMethod(selectionMethod)
  • setCrossoverMethod(crossoverMethod)
  • setMutationMethod(mutationMethod)

Finally, run evolution with:

  • await evolve(generations, callback?)

It returns the fittest individual from the final population.

Callback Parameter

You can optionally pass a callback function to evolve() that gets invoked after each generation:

await ga.evolve(20, (generation, population, fittest) => {
  console.log(`Generation ${generation}: Best fitness = ${fittest.fitness}`);
  // Your custom logic here
});

The callback receives:

  • generation: current generation number
  • population: entire population array
  • fittest: the best individual in the current generation

This is useful for tracking progress, updating UI, or implementing custom stopping conditions.

Optimize

  • Optimize.Maximize: Maximizes the fitness value
  • Optimize.Minimize: Minimizes the fitness value

Built-in Selection Methods

Evolite exports these ready-to-use selection helpers:

  • fittestSelection(population) - returns the first two individuals, assuming the population is already sorted by fitness
  • randomSelection(population) - returns two random individuals
  • tournamentSelection(population) - returns winners from repeated pairwise tournaments
  • linearRankingSelection(population) - selects by rank after sorting by fitness
  • rouletteWheelSelection(population) - selects proportionally to fitness

Each selection method expects a population with at least two individuals.

Types

Individuals should include an optional fitness field:

type WithFitness = {
  fitness?: number;
};

The async hooks use these shapes internally:

  • fitnessFunction(individual) => Promise<number>
  • selectionMethod(population) => Promise<[parent1, parent2]>
  • mutationMethod(individual) => Promise<individual>
  • crossoverMethod(parent1, parent2) => Promise<individual>

Development

bun install
bun run test
bun run build
bun run lint

Repository

  • GitHub: https://github.com/Seyronh/Evolite
  • Issues: https://github.com/Seyronh/Evolite/issues

License

MIT