sort-component

0.1.0 • Public • Published

Sort

Sort array utility

Installation

$ npm install sort
$ component install learnboost/sort

Features

  • sort array of single elements, arrays and objects
  • similar syntax to mongodb sorting (for array of objects)
  • support force var type (numeric, alpha, date, etc)
  • extensible adding more converting functions

API

sort([e-0, e-1, ... e-n])

var sort = require('sort');
sort(['4', '11', '4.32', '1']); // ['1', '11', '4', '4.32']

sort([e-0, e-1, ... e-n], 'sorting')

var sort = require('sort');
 
// force direction `DESC` and type `numeric`
sort(['4', '11', '4.32', '1'], '-1 numeric'); // ['11', '4.23', '4', '1']

sort([Arr-0, Arr-1, ... Arr-n], {sorting})

var sort = require('sort');
 
// Array of Arrays
var persons = [
  ["diego", "banana"],
  ["jorge", "lemon"]
];
 
// multiple sorting
sort(persons, { 1: -1, 0: 1 });

sort(Obj-0, Obj-1, ... Obj-n], {sorting})

var sort = require('sort');
 
// Array of Objects
var persons = [
  { first: "diego", last: "banana" },
  { first: "jorge", last: "lemon" }
];
 
// multiple sorting - similar to mongodb
sort(persons, { last: -1, first: '1 alpha' });

Supported types

  • alpha
  • numeric
  • date

Extensibility

sort#add(name, fn)

Allow add custom function to convert the values

var sort = require('sort');
 
sort.add('roman', require('deromanize-component'));
sort(['X', 'V', 'IX', 'XIV'], '-1 roman'); // ['XIV', 'X', 'IX', 'V']

Tests

Download testing dependecies

npm install

Run tests

make test

License

(The MIT License) Copyright(c) 2012 Damian Suarez <rdsuarez@gmail.com>

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.

Readme

Keywords

none

Package Sidebar

Install

npm i sort-component

Weekly Downloads

6

Version

0.1.0

License

none

Last publish

Collaborators

  • retrofox