# OrderBy

[Github](https://github.com/aykutkardas/Json-Function) repository for your stars.

## Usage

#### Install

```bash
$ npm install json-function
```

#### Import

```javascript
import { orderBy } from 'json-function';
```

#### Usage

Example Data

```javascript
const data = [
  {
    id: 1,
    userId: 1,
    title: "quis ut nam facilis et officia qui"
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum"
  },
  {
    id: 3,
    userId: 2,
    title: "delectus aut autem"
  }
];
```

**DESC Syntax**

```javascript
orderBy(data, "id", "DESC");
```

Output

```javascript
[
  {
    id: 3,
    userId: 2,
    title: "delectus aut autem"
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum"
  },
  {
    id: 1,
    userId: 1,
    title: "quis ut nam facilis et officia qui"
  }
];
```

**ASC Syntax**

```javascript
orderBy(data, "title", "ASC");
// or
orderBy(data, "title");
```

Output

```javascript
[
  {
    id: 3,
    userId: 2,
    title: "delectus aut autem"
  },
  {
    id: 2,
    userId: 1,
    title: "lorem ipsum"
  },
  {
    id: 1,
    userId: 1,
    title: "quis ut nam facilis et officia qui"
  }
];
```

{% hint style="warning" %}
It is currently only sorting with string and number values. Soon the date ranking support will come.
{% endhint %}

**Sort Deep**

Example Data

```javascript
const data = [
  {
    id: 1,
    userId: 1,
    address: {
      city: "New York"
    }
  },
  {
    id: 2,
    userId: 1,
    address: {
      city: "Detroit"
    }
  },
  {
    id: 3,
    userId: 2,
    address: {
      city: "Dallas"
    }
  }
];
```

```javascript
orderBy(data, "address.city", "ASC", { deep: true });
```
