https://github.com/clever/unix-sort
Sort large streams of JSON objects using the unix sort command.
https://github.com/clever/unix-sort
Last synced: 4 months ago
JSON representation
Sort large streams of JSON objects using the unix sort command.
- Host: GitHub
- URL: https://github.com/clever/unix-sort
- Owner: Clever
- License: apache-2.0
- Created: 2013-12-05T01:48:14.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2024-09-23T15:35:02.000Z (almost 2 years ago)
- Last Synced: 2025-06-24T21:46:23.173Z (about 1 year ago)
- Language: CoffeeScript
- Homepage:
- Size: 28.3 KB
- Stars: 12
- Watchers: 65
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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*
```javascript
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:
```javascript
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']));
```