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

simple-sort

v0.1.2

Published

Straightforward collection of sorting methods and sort functions.

Downloads

111

Readme

simple-sort

simple-sort provides a straightforward collection of sorting methods and sort functions.

Why use simple-sort?

  • It provides both sorting methods and sort functions.
  • It makes sorting by locale simple (no separate API to remember).
  • It provides functionality via plain English method names rather than hard-to-remember parameters.
  • It provides you a consistent sorting API, so you don't have to individually write all sorting methods yourself.
  • It makes your code more readable and easily understandable, even by somebody unfamiliar with the simple-sort API.

Installation

$ npm install simple-sort

Usage

Import the library:

import Sorter from 'simple-sort'; // or var Sorter = require('simple-sort').default;

Create an instance:

const sorter = new Sorter('en');

####Sorting methods:

// sample data array
const numArr = [2,3,1];

// sort values in ascending order
sorter.sortAsc(numArr);
// -> [1,2,3]

// sort values in descending order
sorter.sortDes(numArr);
// -> [3,2,1]

// sample array
const wordArr = ['Janeway', 'Picard', 'Cisco'];

// sort by locale in ascending order
sorter.sortByLocaleAsc(wordArr);
// -> ['Cisco','Janeway','Picard']

// sort by locale in descending order
sorter.sortByLocaleDes(wordArr);
// -> ['Picard','Janeway','Cisco']

// sample array
const objArr = [{num:2},{num:3},{num:1}];

// sort array of objects by property in ascending order
sorter.sortByPropAsc(objArr, 'num');
// -> [{num:1},{num:2},{num:3}]

// sort array of objects by property in descending order
sorter.sortByPropDes(objArr, 'num');
// -> [{num:3},{num:2},{num:1}]

// sample array
const objStrArr = [{name:'Janeway'},{name:'Picard'},{name:'Cisco'}];

// locale sort array of objects by property in ascending order
sorter.localeSortByPropAsc(objStrArr, 'name');
// -> [{name:'Cisco'},{name:'Janway'},{name:'Picard'}]

// locale sort array of objects by property in descending order
sorter.localSortByPropDes(objStrArr, 'name');
// -> [{name:'Picard'},{name:'Janway'},{name:'Cisco'}]

####Function-returning methods: Each of the previous sort methods are also available as sort functions to pass into Array.sort(). All function-returning methods have a Func suffix.

// sample data array
const numArr = [2,3,1];

// sort values in asending order
numArr.sort(sorter.sortAscFunc());
// numArr -> [1,2,3]

// sort values in descending order
numArr.sort(sorter.sortDesFunc());
// numArr -> [3,2,1]

// sample array
const wordArr = ['Janeway', 'Picard', 'Cisco'];

// sort by locale in ascending order
wordArr.sort(sorter.sortByLocaleAscFunc());
// wordArr -> ['Cisco','Janeway','Picard']

// sort by locale in descending order
wordArr.sort(sorter.sortByLocaleDesFunc());
// wordArr -> ['Picard','Janeway','Cisco']

// sample array
const objArr = [{num:2},{num:3},{num:1}];

// sort array of objects by property in ascending order
objArr.sort(sorter.sortByPropAscFunc('num'));
// objArr -> [{num:1},{num:2},{num:3}]

// sort array of objects by property in descending order
objArr.sort(sorter.sortByPropDesFunc('num'));
// objArr -> [{num:3},{num:2},{num:1}]

// sample array
const objStrArr = [{name:'Janeway'},{name:'Picard'},{name:'Cisco'}];

// locale sort array of objects by property in ascending order
objStrArr.sort(sorter.localeSortByPropAscFunc('name'));
// objStrArr -> [{name:'Cisco'},{name:'Janway'},{name:'Picard'}]

// locale sort array of objects by property in descending order
objStrArr.sort(sorter.localSortByPropDesFunc('name'));
// objStrArr -> [{name:'Picard'},{name:'Janway'},{name:'Cisco'}]

Docs

Documentation of all available methods can be found here.

Contributions

Contributions are welcome! If you have any issues and/or contributions you would like to make, feel free to file an issue and/or issue a pull request.

License

Apache License Version 2.0

Copyright (c) 2016 by Ryan Burgett.