build/rekord.js
function createComparator(comparator, nullsFirst)
{
  if ( isFunction( comparator ) )
  {
    return comparator;
  }
  else if ( isString( comparator ) )
  {
    if ( comparator in Comparators )
    {
      return Comparators[ comparator ];
    }

    if ( comparator.charAt(0) === '-' )
    {
      var parsed = createComparator( comparator.substring( 1 ), !nullsFirst );

      return function compareObjectsReversed(a, b)
      {
        return -parsed( a, b );
      };
    }
    else if ( isFormatInput( comparator ) )
    {
      var formatter = createFormatter( comparator );

      return function compareFormatted(a, b)
      {
        var af = formatter( a );
        var bf = formatter( b );

        return af.localeCompare( bf );
      };
    }
    else if ( isParseInput( comparator ) )
    {
      var parser = createParser( comparator );

      return function compareExpression(a, b)
      {
        var ap = parser( a );
        var bp = parser( b );

        return compare( ap, bp, nullsFirst );
      };
    }
    else
    {
      return function compareObjects(a, b)
      {
        var av = isValue( a ) ? a[ comparator ] : a;
        var bv = isValue( b ) ? b[ comparator ] : b;

        return compare( av, bv, nullsFirst );
      };
    }
  }
  else if ( isArray( comparator ) )
  {
    var parsedChain = [];

    for (var i = 0; i < comparator.length; i++)
    {
      parsedChain[ i ] = createComparator( comparator[ i ], nullsFirst );
    }

    return function compareObjectsCascade(a, b)
    {
      var d = 0;

      for (var i = 0; i < parsedChain.length && d === 0; i++)
      {
        d = parsedChain[ i ]( a, b );
      }

      return d;
    };
  }

  return null;
}
function createComparator(comparator, nullsFirst)
{
  if ( isFunction( comparator ) )
  {
    return comparator;
  }
  else if ( isString( comparator ) )
  {
    if ( comparator in Comparators )
    {
      return Comparators[ comparator ];
    }

    if ( comparator.charAt(0) === '-' )
    {
      var parsed = createComparator( comparator.substring( 1 ), !nullsFirst );

      return function compareObjectsReversed(a, b)
      {
        return -parsed( a, b );
      };
    }
    else if ( isFormatInput( comparator ) )
    {
      var formatter = createFormatter( comparator );

      return function compareFormatted(a, b)
      {
        var af = formatter( a );
        var bf = formatter( b );

        return af.localeCompare( bf );
      };
    }
    else if ( isParseInput( comparator ) )
    {
      var parser = createParser( comparator );

      return function compareExpression(a, b)
      {
        var ap = parser( a );
        var bp = parser( b );

        return compare( ap, bp, nullsFirst );
      };
    }
    else
    {
      return function compareObjects(a, b)
      {
        var av = isValue( a ) ? a[ comparator ] : a;
        var bv = isValue( b ) ? b[ comparator ] : b;

        return compare( av, bv, nullsFirst );
      };
    }
  }
  else if ( isArray( comparator ) )
  {
    var parsedChain = [];

    for (var i = 0; i < comparator.length; i++)
    {
      parsedChain[ i ] = createComparator( comparator[ i ], nullsFirst );
    }

    return function compareObjectsCascade(a, b)
    {
      var d = 0;

      for (var i = 0; i < parsedChain.length && d === 0; i++)
      {
        d = parsedChain[ i ]( a, b );
      }

      return d;
    };
  }

  return null;
}
function createComparator ( comparator , nullsFirst ) { if ( isFunction ( comparator ) ) { return comparator ; } else if ( isString ( comparator ) ) { if ( comparator in Comparators ) { return Comparators [ comparator ] ; } if ( comparator . charAt ( 0 ) === '-' ) { var parsed = createComparator ( comparator . substring ( 1 ) , ! nullsFirst ) ; return function compareObjectsReversed ( a , b ) { return - parsed ( a , b ) ; } ; } else if ( isFormatInput ( comparator ) ) { var formatter = createFormatter ( comparator ) ; return function compareFormatted ( a , b ) { var af = formatter ( a ) ; var bf = formatter ( b ) ; return af . localeCompare ( bf ) ; } ; } else if ( isParseInput ( comparator ) ) { var parser = createParser ( comparator ) ; return function compareExpression ( a , b ) { var ap = parser ( a ) ; var bp = parser ( b ) ; return compare ( ap , bp , nullsFirst ) ; } ; } else { return function compareObjects ( a , b ) { var av = isValue ( a ) ? a [ comparator ] : a ; var bv = isValue ( b ) ? b [ comparator ] : b ; return compare ( av , bv , nullsFirst ) ; } ; } } else if ( isArray ( comparator ) ) { var parsedChain = [ ] ; for ( var i = 0 ; i < comparator . length ; i ++ ) { parsedChain [ i ] = createComparator ( comparator [ i ] , nullsFirst ) ; } return function compareObjectsCascade ( a , b ) { var d = 0 ; for ( var i = 0 ; i < parsedChain . length && d === 0 ; i ++ ) { d = parsedChain [ i ] ( a , b ) ; } return d ; } ; } return null ; }
Creates a function which compares two values.

@memberof Rekord
@param {comparatorInput} comparator
The input which creates a comparison function.
@param {Boolean} [nullsFirst=false] -
True if null values should be sorted first.
@return {comparisonCallback}
Creates a function which compares two values .