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

@kktestdev/kksort

v1.0.4

Published

TypeScript sorting and searching algorithms library with tree-shakable imports and full type safety

Readme

KKsort

A TypeScript library for sorting and searching algorithms.

Demo / Playground

Try it live at https://kksort-web.vercel.app/

Demo features:

  • Choose the algorithm you want to test
  • Enter custom input data and target values
  • See results from each method instantly

Installation

npm install @kktestdev/kksort

or

pnpm add @kktestdev/kksort

Usage

1) Sort

import { quickSort } from '@kktestdev/kksort/quick-sort';

const numbers = [5, 2, 8, 1, 9];
const sorted = quickSort(numbers, (a, b) => a - b);
console.log(sorted); // [1, 2, 5, 8, 9]

2) Search

import { binarySearch } from '@kktestdev/kksort/binary';

const sortedNumbers = [1, 3, 5, 7, 9];
const index = binarySearch(sortedNumbers, 7);
console.log(index); // 3

Function Signatures

// Pseudo type signatures used by functions in this library.
// The default comparator (when no compareFn is provided) supports only:
// number | string | bigint | boolean | Date
//
// In practice, T can also be an object when you supply your own compareFn.

type DefaultComparable = number | string | bigint | boolean | Date;
type Comparable = DefaultComparable | object;

// Sort
// When using a type supported by the default comparator: compareFn is optional
declare function sortFn<T extends Comparable>(
  arr: T[],
  // If arr is object[], provide compareFn to specify how elements are compared
  compareFn?: (a: T, b: T) => number
): T[];

// For other types: compareFn is always required
declare function sortFn<T>(
  arr: T[],
  compareFn: (a: T, b: T) => number
): T[];

// Search
// When using a type supported by the default comparator: compareFn is optional
declare function searchFn<T extends Comparable>(
  arr: T[],
  target: T,
  // If arr is object[], provide compareFn to specify how elements are compared
  compareFn?: (a: T, b: T) => number
): number;

// For other types: compareFn is always required
declare function searchFn<T>(
  arr: T[],
  target: T,
  compareFn: (a: T, b: T) => number
): number;

Notes:

  • Search functions return the found index, or -1 if not found.
  • The default comparator (when no compareFn is provided) supports only number, string, bigint, boolean, and Date.
    • NaN is not supported for number — a TypeError will be thrown if encountered.
    • Invalid Date values (where getTime() returns NaN) are not supported and will throw a TypeError.
  • When no compareFn is provided, all values in arr and target must be the same type and one of the supported types above. Mixed types (e.g. number and string together) will cause defaultCompare to throw a TypeError.
  • For object types or any other unsupported types, you must supply your own compareFn.
  • Search functions that require a pre-sorted array: binarySearch and jumpSearch only — linearSearch and quickSearch work on unsorted arrays.

Function Details & Trade-offs

Sorting Functions

| Function | Import | Pros | Cons | Notes | |---|---|---|---|---| | bubbleSort | @kktestdev/kksort/bubble | Easy to understand, stable, great for teaching | Slow O(n²) on large inputs | Does not mutate original array | | insertionSort | @kktestdev/kksort/insertion | Excellent on nearly-sorted data, stable | Poor on large inputs (O(n²)) | Does not mutate original array | | selectionSort | @kktestdev/kksort/selection | Simple code, minimal swaps | O(n²) in all cases, not stable | Mutates original array | | mergeSort | @kktestdev/kksort/merge | Guaranteed O(n log n), stable | Extra memory O(n) | Does not mutate original array | | quickSort | @kktestdev/kksort/quick-sort | Fast in practice, good general-purpose choice | Worst case O(n²) | Does not mutate original array | | heapSort | @kktestdev/kksort/heap | Guaranteed O(n log n), low extra memory | Not stable, often slower than quicksort in practice | Mutates original array |

Search Functions

| Function | Import | Pros | Cons | Notes | |---|---|---|---|---| | binarySearch | @kktestdev/kksort/binary | Very fast O(log n) | Requires a sorted array | Does not mutate original array | | linearSearch | @kktestdev/kksort/linear | Works on unsorted arrays | Slow on large inputs (O(n)) | Does not mutate original array | | jumpSearch | @kktestdev/kksort/jump | Faster than linear on sorted data | Still slower than binary search | Requires a sorted array, does not mutate original array | | quickSearch | @kktestdev/kksort/quick-search | Fast on average for unsorted data | Worst case O(n²), rearranges elements | Mutates original array |