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

genetic-lab

v1.0.1

Published

A lightweight genetic algorithm library.

Readme

Genetic Lab

npm version

License: MIT

A lightweight genetic algorithm library.

Changelog [1.0.1]

  • Added support for custom configuration, ex. custom randomizer function

For a more detailed list of updates, see CHANGELOG.

Getting Started

Installation

Add to existing project using npm or yarn.

npm install genetic-lab --save
yarn add genetic-lab

Usage

Import the library to your project.

const GeneticLab = require("genetic-lab");

// using ES6 import
// import GeneticLab from 'genetic-lab';

const { Selection, Mutation, Crossover } = GeneticLab;

const {
  createRoulleteWheelSelection,
  createStochasticUniversalSampling,
  createRankSelection,
  createTournamentSelection
} = Selection;

const { pointCrossover, uniquePointCrossover } = Crossover;

const { mutateOrder, createMutation } = Mutation;

Check the examples for additional reference on using this library.

Fitness

A fitness function should check the fitness of a single individual and return a number based on it's fitness score.

For example:

// A fitness function that optimizes for highest binary string value
function getFitness(individual) {
  return parseInt(individual, 2);
}

getFitness("010111"); // => 23

Selection

createRoulleteWheelSelection(getFitness, config?)

Creates a selection function that uses Roullete Wheel method.

const population = ["000", "111"];
const selection = createRoulleteWheelSelection(getFitness);
selection(population); // => ['111']

Config (Optional)

  • randomizer?: () => number; // function that replaces Math.random()

createStochasticUniversalSampling(getFitness, config)

Creates a selection function that uses Stochastic Universal Sampling method. Number of individuals selected is based on count.

const population = ["000", "111", "101"];
const selection = createStochasticUniversalSampling(getFitness, { count: 2 });
selection(population); // => ['111', '101'] or ['101', '111']

Config

  • randomizer?: () => number; // function that replaces Math.random()
  • count: number;

createRankSelection(getFitness, config)

Creates a selection function that uses Rank Selection method. Number of individuals selected is based on count.

const population = ["000", "111", "101"];
const selection = createRankSelection(getFitness, { count: 2 });
selection(population); // => ['111', '101']

Config

  • randomizer?: () => number; // function that replaces Math.random()
  • count: number;

createTournamentSelection(getFitness, tournamentSize, config?)

Creates a selection function that uses Tournament Selection method. Size of tournament is dependent on tournametSize.

const population = ["000", "111", "101"];
const selection = createTournamentSelection(getFitness, 2);
selection(population); // => ['111'] or ['101']

Config (Optional)

  • randomizer?: () => number; // function that replaces Math.random()

Mutation

mutateOrder(individual)

Swaps two genes randomly.

mutateOrder("ABC"); // => 'BAC' or 'CBA' or 'BCA'
mutateOrder("10"); // => '01'

createMutation(sample)

Creates a mutation function that randomly changes a gene based on sample.

const sample = ["1", "0"];
const mutateBinary = createMutation(sample);
mutateBinary("10"); // => '11' or '00'

Crossover

pointCrossover(parentA, parentB, index)

Creates two offspring based on parentA and parentB using index as point of crossover. If no index is provided, it would be assigned randomly.

const pair = ["ABCD", "DCBA"];
pointCrossover(...pair, 2); // => ['ABBA', 'DCCD']

uniquePointCrossover(parentA, parentB, index)

Creates two unique chromosome offsprings based on unique chromosomes of parentA and parentB using index as point of crossover. If no index is provided, it would be assigned randomly.

const pair = ["ABCD", "DCBA"];
uniquePointCrossover(...pair, 2); // => ['ABDC', 'DCAB']

License

This project is licensed under the MIT License - see the LICENSE file for details.