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 🙏

© 2024 – Pkg Stats / Ryan Hefner

sort-ids

v3.0.1

Published

Calculate sorting identifiers

Downloads

29

Readme

sort-ids test

Sort input array, return sorted ids of the array items, keeping the initial array unchanged.

Useful to perform linked sorting of multiple arrays, where linked array[s] should be sorted the same way as the primary one.

npm install sort-ids

import sortIds from 'sort-ids'
import reorder from 'array-rearrange'

const rates = [.12, .47, .52, .97, ...sourceNumbers]
const names = ['John', 'Alexa', 'Jimmy', 'Kate', ...linkedItems]

const ids = sortIds(rates)

const sortedRates = reorder(rates, ids)
const sortedNames = reorder(names, ids)

ids = sortIds(array, ids?, precise=true)

Calculate ids corresponding to sorted input array. The input array isn't changed. Optionally pass input ids - some initial order of ids. precise flag makes sure no missorts took place and resolves them, if any. Disabling that can save ~30ms for 1e6 items input arrays.

See also array-rearrange for reordering input array based on a list of ids.

Motivation

This package is >= 6 times faster compared to sorting function. That is achieved by packing input value - id pairs into a single float64 value and performing native sort on that Float64Array, then unpacking the ids back.

Acknowledgement

The idea was proposed by Robert Monfera for snap-points-2d and eventually implemented. But there may be other applications, like sorting colors etc.

License

(c) 2018 Dmitry Iv. MIT License