0.2.0 • Published 8 years ago

unix-sort v0.2.0

Weekly downloads
2
License
BSD-2-Clause
Repository
github
Last release
8 years ago

unix-sort

Sort streams of JSON objects using the unix sort command. This allows sorting of very large data sets in a stream interface that Node normally can't handle due to memory constraints.

Install

npm install unix-sort

Usage

unix-sort expects that you are streaming it JavaScript objects and takes a single argument: an array of all the keys you want to sort by, in order. It assumes that all of the keys have a string value.

Examples

NOTE: The implementation of ArrayStream is left as an exercise to the reader

var unix_sort = require('unix-sort');

var array = ['a', 'e', 'b', 'd', 'e', 'c'];
var objects = array.map(function (el) {return {item: el}});

var readable = new ArrayStream(objects);
readable.pipe(unix_sort(['item'])); // 'a', 'b', 'c', 'd', 'e', 'e'

Now for one a bit more complex:

var dogs = [
    {
        name: 'Toto',
        owner: 'Dorothy'
    },
    {
        name: 'Lassie',
        owner: 'Alex',
        notes: "Owned by Timmy's brother after he died in the well"
    },
    {
        name: 'Lassie',
        owner: 'Timmy'
    },
    {
        name: 'Old Yeller',
        owner: 'Travis Coates'
    },
    {
        name: 'Balto',
        owner: 'Gunnar Kaasen'
    }
];

var readable = new ArrayStream(dogs);
readable.pipe(unix_sort(['name', 'owner']));
0.2.0

8 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago