# getListDiff

## IMPORT

```typescript
import { getListDiff } from "@donedeal0/superdiff";
```

***

## FORMAT

### Input

```typescript
prevList: T[];
  nextList: T[];
  options?: {
    showOnly?: ("added" | "deleted" | "moved" | "updated" | "equal")[], // [] by default
    referenceKey?: string, // "" by default
    ignoreArrayOrder?: boolean, // false by default,
    considerMoveAsUpdate?: boolean // false by default
  }
```

* `prevList`: the original list.
* `nextList`: the new list.
* `options`
  * `showOnly` gives you the option to return only the values whose status you are interested in (e.g. `["added", "equal"]`).
  * `referenceKey` will consider an object to be `updated` rather than `added` or `deleted` if one of its keys remains stable, such as its `id`. This option has no effect on other datatypes.
  * `ignoreArrayOrder`: if set to `true`, `["hello", "world"]` and `["world", "hello"]` will be treated as `equal`, because the two arrays contain the same values, just in a different order.
  * `considerMoveAsUpdate`: if set to `true` a `moved` value will be considered as `updated`.

### Output

```typescript
type ListDiff = {
type ListDiff = {
  type: "list";
  status: "added" | "deleted" | "equal" | "moved" | "updated";
  diff: {
    value: unknown;
    index: number | null;
    previousIndex: number | null;
    status: "added" | "deleted" | "equal" | "moved" | "updated";
  }[];
};
```

***

## USAGE

### Input

```typescript
getListDiff(
- ["mbappe", "mendes", "verratti", "ruiz"],
+ ["mbappe", "messi", "ruiz"]
);
```

### Output

```diff
{
      type: "list",
+     status: "updated",
      diff: [
        {
          value: "mbappe",
          index: 0,
          previousIndex: 0,
          status: "equal",
        },
-       {
-         value: "mendes",
-         index: null,
-         previousIndex: 1,
-         status: "deleted",
-       },
-       {
-         value: "verratti",
-         index: null,
-         previousIndex: 2,
-         status: "deleted",
-       },
+       {
+         value: "messi",
+         index: 1,
+         previousIndex: null,
+         status: "added",
+       },
+       {
+         value: "ruiz",
+         index: 2,
+         previousIndex: 3,
+         status: "moved",
        },
      ],
    }
```
