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

sortcoll

v0.2.0

Published

Simple function to create a collection sort function for multiple keys

Downloads

3

Readme

sortcoll

Build Status Build Status NPM version

Simple helper to create a collection sort function for multiple keys.

NPM

Install

npm install sortcoll

Initialize

var sortcoll = require( "sortcoll" )

`sortcoll( keys, [forward=true], [fnGet] )``

Usage

var sortcoll = require( "sortcoll" )

var data = [  
  { id: 1, name: "Fritz" },
  { id: 2, name: "Müller" },
  { id: 3, name: "Meier" },
  { id: 4, name: "Fritz" }
];

var sortFunction = sortcoll( [ "name", "id" ], false );

var sorted = data.sort( sortFunction );
/*
[
    { id: 1, name: "Fritz" },
    { id: 4, name: "Fritz" },
    { id: 3, name: "Meier" },
    { id: 2, name: "Müller" }
]
*/

Arguments:

  • keys : ( String|String[] required ) A simple key to sort by or a list of keys sorted in the given order. Similar to sql ORDER BY name, id
  • forward : ( Boolean|Object optional: default = true ) Sort from a-z if true. Otherwise from z-a. You can set the direction for the sort keys separately by using an object. If you set a object key ? this will be used for every not undefined key.
  • fnGet : ( Function optional ) A optional function to get the sorting data from the element. Default is just el[key]

Advanced example

with fnGet and mixed forward

Here's a small example to use the fnGet argument with e.g. backbone.

var sortcoll = require( "sortcoll" )

var data = [  
	{ id: 13, name: "Foo", age: 42 },
	{ id: 1337, name: "Bar", age: 666 },
	{ id: 42, name: "Fizz", age: 23 },
	{ id: 23, name: "Bar", age: 23 },
	{ id: 666, name: "Buzz", age: 13 }
	{ id: 7, name: "Bar", age: 23 },
];

var fnGet = function( el, key ){
    return el.get( key )
};

var sortFunction = sortcoll( [ "name", "id" ], { age: false, "?": true }, fnGet );

myCollection = new Backbone.Collection( data, comparator: sortFunction )

var myCollection.toJSON();
/*
[
    { id: 1337, name: "Bar", age: 666 },
    { id: 13, name: "Foo", age: 42 },
    { id: 7, name: "Bar", age: 23 },
    { id: 23, name: "Bar", age: 23 },
    { id: 42, name: "Fizz", age: 23 },
    { id: 666, name: "Buzz", age: 13 }
]
*/

Release History

|Version|Date|Description| |:--:|:--:|:--|t |0.2.0|2016-03-22|added mixed forwarding| |0.1.0|2016-03-22|Added the fnGet option.| |0.0.1|2016-03-04|Initial commit|

NPM

Initially Generated with generator-mpnodemodule

Other projects

|Name|Description| |:--|:--| |node-cache|Simple and fast NodeJS internal caching. Node internal in memory cache like memcached| |rsmq|A really simple message queue based on redis| |redis-heartbeat|Pulse a heartbeat to redis. This can be used to detach or attach servers to nginx or similar problems.| |systemhealth|Node module to run simple custom checks for your machine or it's connections. It will use redis-heartbeat to send the current state to redis.| |rsmq-cli|a terminal client for rsmq| |rest-rsmq|REST interface for.| |redis-sessions|An advanced session store for NodeJS and Redis| |connect-redis-sessions|A connect or express middleware to simply use the redis sessions. With redis sessions you can handle multiple sessions per user_id.| |redis-notifications|A redis based notification engine. It implements the rsmq-worker to safely create notifications and recurring reports.| |nsq-logger|Nsq service to read messages from all topics listed within a list of nsqlookupd services.| |nsq-topics|Nsq helper to poll a nsqlookupd service for all it's topics and mirror it locally.| |nsq-nodes|Nsq helper to poll a nsqlookupd service for all it's nodes and mirror it locally.| |nsq-watch|Watch one or many topics for unprocessed messages.| |hyperrequest|A wrapper around hyperquest to handle the results| |task-queue-worker|A powerful tool for background processing of tasks that are run by making standard http requests |soyer|Soyer is small lib for server side use of Google Closure Templates with node.js.| |grunt-soy-compile|Compile Goggle Closure Templates ( SOY ) templates including the handling of XLIFF language files.| |backlunr|A solution to bring Backbone Collections together with the browser fulltext search engine Lunr.js| |domel|A simple dom helper if you want to get rid of jQuery| |obj-schema|Simple module to validate an object by a predefined schema|

The MIT License (MIT)

Copyright © 2016 M. Peter, http://www.tcs.de

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.