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

datasaur-simple-sort

v3.0.1

Published

Simple single-column sorting Datasaur module

Downloads

5

Readme

An indexed sorter Datasaur module.

The datasaur-simple-sort data source provides a means to sort the original set of rows basec on the values in a given column.

Instantiation

datasaur-simple-sort sits on top of an indexed datasource. For example:

var Source = require('datasaur-local'); // v3.0.0 or higher
var Indexer = require('datasaur-indexed'); // this version must be >= that of datasaur-local
var Sorter = require('datasaur-simple-sort'); // this version must be >= that of datasaur-indexed
var dataModel = new Sorter(new Indexer(new Source));

Custom properties

datasaur-simple-sort defines a single custom shared property.

version (static property)

The version string from package.json. (This is a static property of the constructor.)

Custom methods

datasaur-simple-sort defines a single custom instance method.

sort(columnIndex, options) instance method

dataModel.sort(0); // alpha ascending by first column
options parameter

The optional options parameter may contain an object with the following properties, all of which are optional:

Name | Values --- | --- dir | 'DESC' (case-insensitive) reverses the sort. Any other value leaves the sort in ascending order. comparator | A function to be bound to columnIndex with the data source (this.next) as the calling context. This function is then passed to Array.prototype.sort

Known issues

Computed cells and columns

This sorter fails for computed cells or columns because it calls this.getValue directly instead of DatasaurIndexed.valOrFunc.

That said, it is still useable on computed columns if sorting on the uncomputed values would produce acceptable results.

Unstable sort

Array.prototype.sort does not naturally perform a stable sort, meaning that the "sorted" order of rows with identical sort arguments is undefined.

Multi-column sorting

Sorting by multiple columns, each of which may be ascending or descending, is somewhat more complicated, essentially involving dynamically adding a Sorter stage for each column to be sorted. See datasaur-filter which does something like that, but forces Array.prototype.sort to do a stable sort (which is is not naturally inclined to do), and properly handles computed cells and columns. Note: As of this writing datasaur-filter has not yet been updated to v3.0.0.

Distribution

Published as an npm module to npmjs.org to be npm installed:

npm install datasaur-simple-sort

Published as a Hypergrid Client Module to be loaded by the client with a <script> tag:

<script src="https://fin-hypergrid.github.io/datasaur-simple-sort/3.0.0/build/datasaur-simple-sort.js"></script>

The above <script> tag loads the module into fin.Hypergrid.modules['datasaur-simple-sort']. Once loaded it can be referenced from another Hypergrid client module with require(...):

var DatasaurSimpleSort = require('datasaur-simple-sort');

Or from some other script with fin.Hypergrid.require(...):

var DatasaurSimpleSort = fin.Hypergrid.require('datasaur-simple-sort');

History

  • 3.0.1
    • Sort on the unsorted data rather than the sorted data.
    • Delete the index when option.dir is falsy.
  • 3.0.0 — Initial commit.