Namespace: comparators

module:core.utils. comparators

A set of useful comparators compatible with _.sortBy().

The following naming convention is used: <dataType>Comparator<Arguments count: 1 or 2><Comparing direction: 'Asc' or 'Desc'>.

For example: `stringComparator2Asc` means that comparator function takes 2 string objects and compares it in ascending order.

Can be used as comparator in Backbone.Collection.

Members


<static> stringComparator1

Methods


<static> booleanComparator2Asc(a, b)

Parameters:
Name Type Description
a Boolean Argument A.
b Boolean Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> booleanComparator2Desc(a, b)

Parameters:
Name Type Description
a Boolean Argument A.
b Boolean Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> dateComparator2Asc(a, b)

Parameters:
Name Type Description
a Date | String | moment Argument A. Javascript Date, date string in ISO8691 or momentJS date.
b Date | String | moment Argument B. Javascript Date, date string in ISO8691 or momentJS date.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> dateComparator2Desc(a, b)

Parameters:
Name Type Description
a Date | String | moment Argument A. Javascript Date, date string in ISO8691 or momentJS date.
b Date | String | moment Argument B. Javascript Date, date string in ISO8691 or momentJS date.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> durationComparator2Asc(a, a)

Parameters:
Name Type Description
a String | Object Argument A. An ISO8601 duration string ('P1Y2M3DT4H5M6S'), a string separated by colons like '7.23:59:59.999' or MomentJS object like { seconds: 2, minutes: 2, hours: 2, days: 2, weeks: 2, months: 2, years: 2 }.
a String | Object Argument B. An ISO8601 duration string ('P1Y2M3DT4H5M6S'), a string separated by colons like '7.23:59:59.999' or MomentJS object like { seconds: 2, minutes: 2, hours: 2, days: 2, weeks: 2, months: 2, years: 2 }.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> durationComparator2Desc(a, a)

Parameters:
Name Type Description
a String | Object Argument A. An ISO8601 duration string ('P1Y2M3DT4H5M6S'), a string separated by colons like '7.23:59:59.999' or MomentJS object like { seconds: 2, minutes: 2, hours: 2, days: 2, weeks: 2, months: 2, years: 2 }.
a String | Object Argument B. An ISO8601 duration string ('P1Y2M3DT4H5M6S'), a string separated by colons like '7.23:59:59.999' or MomentJS object like { seconds: 2, minutes: 2, hours: 2, days: 2, weeks: 2, months: 2, years: 2 }.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> emptyComparator()

Empty comparator.
Returns:
Always 0 (means equals).
Type
Number

<static> getComparatorByDataType(dataType, sorting)

Method returns comparator function based on type name.
Parameters:
Name Type Description
dataType String Data type as in core.meta.objectPropertyTypes.
sorting String What sorting do we need? Options:
  • 'asc'
  • 'desc'
Returns:
Comparator function.
Type
function

<static> numberComparator2Asc(a, b)

Parameters:
Name Type Description
a Number Argument A.
b Number Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> numberComparator2Desc(a, b)

Parameters:
Name Type Description
a Number Argument A.
b Number Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> referenceComparator2Asc(a, b)

Method to compare objects by it's name property.
Parameters:
Name Type Description
a Object Argument A.
b Object Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> referenceComparator2Desc(a, b)

Method to compare objects by it's name property.
Parameters:
Name Type Description
a Object Argument A.
b Object Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> stringComparator2Asc(a, b)

Parameters:
Name Type Description
a String Argument A.
b String Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number

<static> stringComparator2Desc(a, b)

Parameters:
Name Type Description
a String Argument A.
b String Argument B.
Returns:
Result as follows:
  • -1 - if A < B.
  • 0 - if A == B.
  • 1 - if A > B.
Type
Number