# Namespace: comparators

## 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.

Source:
  - utils/utilsApi.js, line 40

### Methods

#### <static> booleanComparator2Asc(a, b) → {Number}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | Boolean | Argument A.
  `b` | Boolean | Argument B.

  Source:
    - utils/comparators.js, line 272

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> booleanComparator2Desc(a, b) → {Number}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | Boolean | Argument A.
  `b` | Boolean | Argument B.

  Source:
    - utils/comparators.js, line 284

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> dateComparator2Asc(a, b) → {Number}

  ##### 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.

  Source:
    - utils/comparators.js, line 196

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> dateComparator2Desc(a, b) → {Number}

  ##### 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.

  Source:
    - utils/comparators.js, line 208

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> durationComparator2Asc(a, a) → {Number}

  ##### 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 }`.

  Source:
    - utils/comparators.js, line 246

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> durationComparator2Desc(a, a) → {Number}

  ##### 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 }`.

  Source:
    - utils/comparators.js, line 260

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> emptyComparator() → {Number}

  Empty comparator.

  Source:
    - utils/comparators.js, line 182

  ##### Returns:

  Always 0 (means equals).

  Type
    Number

#### <static> getComparatorByDataType(dataType, sorting) → {function}

  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'`

  Source:
    - utils/comparators.js, line 318

  ##### Returns:

  Comparator function.

  Type
    function

#### <static> numberComparator2Asc(a, b) → {Number}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | Number | Argument A.
  `b` | Number | Argument B.

  Source:
    - utils/comparators.js, line 220

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> numberComparator2Desc(a, b) → {Number}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | Number | Argument A.
  `b` | Number | Argument B.

  Source:
    - utils/comparators.js, line 232

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> referenceComparator2Asc(a, b) → {Number}

  Method to compare objects by it's `name` property.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | Object | Argument A.
  `b` | Object | Argument B.

  Source:
    - utils/comparators.js, line 297

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> referenceComparator2Desc(a, b) → {Number}

  Method to compare objects by it's `name` property.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | Object | Argument A.
  `b` | Object | Argument B.

  Source:
    - utils/comparators.js, line 310

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> stringComparator1(a) → {String}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | String | Argument A.

  Source:
    - utils/comparators.js, line 150

  ##### Returns:

  An object to compare with simple operators (><=).

  Type
    String

#### <static> stringComparator2Asc(a, b) → {Number}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | String | Argument A.
  `b` | String | Argument B.

  Source:
    - utils/comparators.js, line 164

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number

#### <static> stringComparator2Desc(a, b) → {Number}

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `a` | String | Argument A.
  `b` | String | Argument B.

  Source:
    - utils/comparators.js, line 176

  ##### Returns:

  Result as follows:

  - `-1` - if A < B.
  - `0` - if A == B.
  - `1` - if A > B.
  Type
    Number