JSPM

@fsad-labs/sortzilla

0.6.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q24040F
  • License MIT

Sorts Algorithms in your hand

Package Exports

  • @fsad-labs/sortzilla

Readme

๐Ÿ”ข @fsad-labs/sortzilla

npm version License

A TypeScript/JavaScript library that provides classic **sorting algorithms** with a clean, extensible, and object-oriented API.

Installation

npm install @fsad-labs/sortzilla
# or
yarn add @fsad-labs/sortzilla

Supported Algorithms

  • Bubble Sort
  • Insertion Sort
  • Selection Sort
  • Merge Sort
  • Quick Sort
  • Heap Sort
  • Counting Sort

Usage

Each algorithm is implemented as a class.
You can create an instance and call the sort method.

Example with Numbers

import { bubbleSort, quickSort } from '@fsad-labs/sortzilla';

const result = bubbleSort({ array: [5, 3, 8, 1] });
console.log([...result]); // [1, 3, 5, 8]

// Reuse helper functions
console.log(result.byDesc()); // [8, 5, 3, 1]
console.log(result.byAsc()); // [1, 3, 5, 8]

Example with Strings

import { selectionSort } from '@fsad-labs/sortzilla';

const result = selectionSort({
  array: ['z', 'a', 'd', 'b'],
  ascending: false,
});

console.log([...result]); // ["z", "d", "b", "a"]

Example with Objects

import { mergeSort } from '@fsad-labs/sortzilla';

type User = { id: number; name: string };

const result = mergeSort({
  array: [
    { id: 3, name: 'Alice' },
    { id: 1, name: 'Bob' },
    { id: 2, name: 'Charlie' },
  ],
  field: 'id',
  ascending: true,
});

console.log([...result]);
// [{ id: 1, name: "Bob" }, { id: 2, name: "Charlie" }, { id: 3, name: "Alice" }]

API

Method

function bubbleSort<T extends SortTypes>(props: SortProps<T>);

Params Options

sort(props: SortProps)

type SortTypes = string | number | object;

interface SortProps<T extends SortTypes> {
  array: T[];
  field?: T extends object ? keyof T : undefined;
  ascending?: boolean;
}

--props:::

  • array โ†’ input array (number[] | string[] | object[]).
  • field โ†’ (optional) field key if sorting objects.
  • ascending (boolean, default: true) โ†’ sort order.

QuickSort accepts an additional option:

type QuickSortProp = SortProps<T> & { ipivot?: number };
  • ipivot (number, default: -1) โ†’ index for pivot selection (-1 = random).

Returns a sorted array with extra helpers:

interface IOrderSort<T> {
  byDesc(): T[];
  byAsc(): T[];
}

Example Switching Order Without Re-Sorting

import { insertionSort } from '@fsad-labs/sortzilla';
const result = insertionSort({ array: [4, 2, 7, 1] });

console.log([...result]); // [1, 2, 4, 7]
console.log(result.byDesc()); // [7, 4, 2, 1]

๐Ÿค Contributing

  1. Fork this repository
  2. Create a feature branch (git checkout -b feat/my-feature)
  3. Commit changes (git commit -m 'Add new feature')
  4. Push and create a Pull Request

If my work has helped you or saved you some time, consider Buy Me a Coffeeโ˜•. It keeps me energized and motivated to keep creating and improving.


๐Ÿ“„ License

This project is licensed under the MIT License ยฉ drixev