index.js
function sort(property) {
  // sort by multiple properties
  function multisort(properties) {
    return function multiCompare(a, b) {
      var i = 0;
      var result = 0;
      var numberOfProperties = properties.length;
      while(result === 0 && i < numberOfProperties) {
        result = sort(properties[i])(a, b);
        i++;
      }
      return result;
    };
  }

  if (_.isArray(property)) return multisort(property);
  debug('sorting by %s', property || '');
  var sortOrder = 1;
  // property may be preparsed object
  if (_.isObject(property)) {
    var propertyKey = _.keys(property)[0];
    sortOrder = property[propertyKey];
    property = propertyKey;
  }
  else if (property[0] === '-') {
    sortOrder = -1;
    property = property.substr(1);
  }
  function compare(a, b) {
    var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
    return result * sortOrder;
  }
  return compare;
}
function sort(property) {
  // sort by multiple properties
  function multisort(properties) {
    return function multiCompare(a, b) {
      var i = 0;
      var result = 0;
      var numberOfProperties = properties.length;
      while(result === 0 && i < numberOfProperties) {
        result = sort(properties[i])(a, b);
        i++;
      }
      return result;
    };
  }

  if (_.isArray(property)) return multisort(property);
  debug('sorting by %s', property || '');
  var sortOrder = 1;
  // property may be preparsed object
  if (_.isObject(property)) {
    var propertyKey = _.keys(property)[0];
    sortOrder = property[propertyKey];
    property = propertyKey;
  }
  else if (property[0] === '-') {
    sortOrder = -1;
    property = property.substr(1);
  }
  function compare(a, b) {
    var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
    return result * sortOrder;
  }
  return compare;
}
function sort ( property ) { // sort by multiple properties function multisort ( properties ) { return function multiCompare ( a , b ) { var i = 0 ; var result = 0 ; var numberOfProperties = properties . length ; while ( result === 0 && i < numberOfProperties ) { result = sort ( properties [ i ] ) ( a , b ) ; i ++ ; } return result ; } ; } if ( _ . isArray ( property ) ) return multisort ( property ) ; debug ( 'sorting by %s' , property || '' ) ; var sortOrder = 1 ; // property may be preparsed object if ( _ . isObject ( property ) ) { var propertyKey = _ . keys ( property ) [ 0 ] ; sortOrder = property [ propertyKey ] ; property = propertyKey ; } else if ( property [ 0 ] === '-' ) { sortOrder = - 1 ; property = property . substr ( 1 ) ; } function compare ( a , b ) { var result = ( a [ property ] < b [ property ] ) ? - 1 : ( a [ property ] > b [ property ] ) ? 1 : 0 ; return result * sortOrder ; } return compare ; }
in-memory sort, just for mocking db functionality
in - memory sort just for mocking db functionality