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

ts-array-sort

v1.0.10

Published

A simple array sorter built on typescript

Readme

ts-array-sort

GitHub Workflow Status Coverage Status npm NPM License npm bundle size

ts-array-sort is a simple utility to assist in sorting arrays for Typescript/Javascript. It supports sorting of numbers, strings, and objects out of the box and is very flexible when it comes to sorting objects with multiple or nested properties.

  • number and string sorting made easy
  • nested object property sorting is supported.
  • multiple object property sorting in a single, readable statement.
  • No run-time dependencies
  • ~3kb in size

Usage


Install the package from npm

npm i ts-array-sort

Import the ArraySorter and SortOrder module members.

import { ArraySorter, SortOrder } from 'ts-array-sorter';

Build the sort function and pass it into Array.sort()

import { ArraySorter, SortOrder } from 'ts-array-sorter';
// ...

// Inline example using config object
console.log([3,5,7,1].sort(new ArraySorter({sortOrder: SortOrder.desc}).sort()))
// outputs [7,5,3,1]

API


constructor

const sorter = new ArraySorter();

or you can pass in an optional config object

const sorter = new ArraySorter({sortOrder: SortOrder.desc, properties: ['myProp1', 'myProp2']})

Methods


sortOrder

Method that changes the sort order used by the built sort function. the sort order defaults to ascending, meaning you should only ever have to use this function to change to descending or back from descending.

  • @param sortOrder: SortOrder
  • @returns ArraySorter (this)
new ArraySorter().sortOrder(SortOrder.desc);

sortBy

Method that adds a property to be sorted on. This function should only need to be called when sorting objects.
Note: Any calls to this function when sorting string or number arrays will be ignored.

  • @param property: PropertyKey
  • @returns ArraySorter (this)
// basic usage
new ArraySorter().sortBy('myProperty');

When sorting objects and no properties are provided or properties that do not exist on the objects are provided, an error will be thrown with a corresponding error message.

You can specify a n amount of properties as long as they exist on every object in the array. If you specify more then 1 property to sort on, the sort is applied in the order in which you add them.

Additionally, ts-array-sort supports sorting on properties that are contained within nested data structures. To do this, seperate the object properties with a . as you would normally do with dot notation in JS, just in string form.

// nested property example
new ArraySorter().sortBy('nestedProp.id');
// adds an entry to sort on that looks like {nestedProp: {id: 1}}

// double nested
new ArraySorter().sortBy('user.name.firstName');
// adds an entry to sort on that looks like
// {user: {name: {firstName: 'Chris'}}}

sort

Method which provides the sort function that takes into account all the previously selected config options (i.e. sort order, properties). Pass this function into the built in Array.propotype.sort() method and it will sort the array based on the previously entered configuration.

  • @returns (a: T, b: T) => number
// example usage
const sorter = new ArraySorter().sortOrder(SortOrder.desc).sort();
myArray.sort(sorter);