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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rilesort

v1.0.1

Published

A lightweight npm package exposing sorting methods

Downloads

13

Readme

RileSort

A small, typed collection of classic sorting algorithms implemented in TypeScript. Includes bubble, selection, insertion, merge, quick, and radix sort. Designed to be simple, predictable, and easy to use with numbers, strings, and custom objects.

  • Pure functions (no mutations of your input array)
  • Strong TypeScript types
  • Pluggable comparator for custom ordering (except radix sort, which targets integers)
  • ESM-friendly and tree-shakeable

Installation

Using npm:

npm install rilesort

If you’re consuming it locally (not published), import from your local path instead of the package name.

Quick start

TypeScript:

import { bubbleSort, quickSort } from "rilesort";

// Numbers (ascending by default)
const nums = [4, 2, 7, 1, 3];
const sorted = bubbleSort(nums); // [1, 2, 3, 4, 7]

// Numbers (descending with comparator)
const desc = quickSort(nums, (a, b) => b - a); // [7, 4, 3, 2, 1]

// Strings
const fruits = ["banana", "apple", "cherry"];
const alpha = bubbleSort(fruits); // ["apple", "banana", "cherry"]

// Objects (custom comparator)
type User = { id: number; name: string };
const users: User[] = [{ id: 2, name: "B" }, { id: 1, name: "A" }];
const byId = quickSort(users, (a, b) => a.id - b.id); // [{id:1,...},{id:2,...}]

JavaScript (ESM):

import { insertionSort, mergeSort } from "rilesort";

const values = [5, 1, 5, 3, 1];
console.log(insertionSort(values)); // [1, 1, 3, 5, 5]
console.log(mergeSort(values));     // [1, 1, 3, 5, 5]

CommonJS (Node) via dynamic import:

(async () => {
  const { selectionSort } = await import("rilesort");
  console.log(selectionSort([3, 2, 1]));
})();

API

All algorithms (except radixSort) share the same generic signature:

  • sort (arr: T[], comparator?: (a: T, b: T) => number): T[]

Return value:

  • A new array that is sorted. The input array is not modified.

Comparator contract:

  • Return a negative number if a should come before b
  • Return 0 if they are equal in order
  • Return a positive number if a should come after b

Available functions:

  • bubbleSort (arr, comparator?)
  • selectionSort (arr, comparator?)
  • insertionSort (arr, comparator?)
  • mergeSort (arr, comparator?)
  • quickSort (arr, comparator?)
  • radixSort(arr: number[]): number[]
    • Targets integers (typically non-negative). Ignores custom comparators.

Algorithm characteristics

  • bubbleSort

    • Stable: Yes
    • Time: O(n$^2$) average/worst, O(n) best (already sorted)
    • Space: O(1)
  • selectionSort

    • Stable: No
    • Time: O(n$^2$)
    • Space: O(1)
  • insertionSort

    • Stable: Yes
    • Time: O(n$^2$) average/worst, O(n) best (nearly/already sorted)
    • Space: O(1)
  • mergeSort

    • Stable: Yes
    • Time: O(n log n)
    • Space: O(n)
  • quickSort

    • Stable: No
    • Time: O(n log n) average, O(n^2) worst (depends on pivot strategy)
    • Space: O(log n) average (due to recursion)
    • Uses median of three to select a pivot.
  • radixSort (integers)

    • Stable: Yes
    • Time: O(k·n) where k is the number of digit passes
    • Space: O(n + k)
    • Typically used for non-negative integers; behavior for negatives may require a separate pass/normalization.

Usage tips

  • If you don’t provide a comparator, numbers and strings are sorted in ascending order.
  • For custom objects, always supply a comparator that returns a number (negative/zero/positive).
  • Functions are pure: they return a new array and do not mutate your original input.
  • Stability matters if you rely on the relative order of items that compare equal. Prefer a stable algorithm ( bubbleSort, insertionSort, mergeSort, radixSort) for such cases.

Requirements

  • Node.js that supports ESM. For CommonJS projects, use a bundler or dynamic import.
  • TypeScript users benefit from bundled type declarations.

Development

  • Install dependencies:
  npm install
  • Build:
  npm run build
  • Test:
  npm test
  • Coverage:
  npm run coverage

License

MIT

Acknowledgements

Classic algorithms taught in most CS curricula, implemented in a modern TypeScript style for convenience and clarity.