# @orderandchaos/sorted

> Sort an array of objects by it&#x27;s keys

Latest version **1.0.9** (published 2020-09-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @orderandchaos/sorted
pnpm add @orderandchaos/sorted
yarn add @orderandchaos/sorted
bun add @orderandchaos/sorted
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.9 |
| Published | 2020-09-09 |
| First published | 2020-09-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 10.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | sarcoma |
| Maintainers | sarcoma |

## Links

- npm: https://www.npmjs.com/package/@orderandchaos/sorted
- Repository: https://github.com/sarcoma/sort-array-by-object-key
- Homepage: https://github.com/sarcoma/sort-array-by-object-key#readme
- Issues: https://github.com/sarcoma/sort-array-by-object-key/issues
- npm.io page: https://npm.io/package/@orderandchaos/sorted

## Recent versions

- 1.0.9 (latest) — 2020-09-09
- 1.0.7 — 2020-09-09
- 1.0.6 — 2020-09-08
- 1.0.5 — 2020-09-08
- 1.0.3 — 2020-09-08
- 1.0.1 — 2020-09-08
- 1.0.0 — 2020-09-08

## README

# @orderandchaos/sorted

> Sort an array of objects by it&#x27;s keys

[![NPM](https://img.shields.io/npm/v/@orderandchaos/sorted.svg)](https://www.npmjs.com/package/@orderandchaos/sorted) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save @orderandchaos/sorted
```

## Usage

```tsx
import sortOnColumn, { ISortColumns, makeSortColumns } from '@orderandchaos/sorted';

interface IObj {
    name: string,
    value: number,
    misc: any
}

const arr: IObj[] = [
    {name: 'a', value: 3, misc: null},
    {name: 'b', value: 2, misc: undefined},
    {name: 'c', value: 1, misc: 0},
    {name: 'd', value: 0, misc: ''},
]


const sortColumns: ISortColumns = makeSortColumns<IObj>(arr);

// Sort on 'name'
const sortedByNameAsc = arr.sort(sortOnColumn<IObj>('name', sortColumns.name));
console.log('Name Asc', sortedByNameAsc);

sortColumns.name = !sortColumns.name;

const sortedByNameDesc = arr.sort(sortOnColumn<IObj>('name', sortColumns.name));
console.log('Name Desc', sortedByNameDesc);

// Sort on 'value'
const sortedByValueAsc = arr.sort(sortOnColumn<IObj>('value', sortColumns.value));
console.log('Value Asc', sortedByValueAsc);

sortColumns.value = !sortColumns.value;

const sortedByValueDesc = arr.sort(sortOnColumn<IObj>('value', sortColumns.value));
console.log('Value Desc', sortedByValueDesc);
```

## License

MIT © [sarcoma](https://github.com/sarcoma)

---
_Source: https://npm.io/package/@orderandchaos/sorted · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
