# group-array-then-sort

> env.json is a take on the traditional .env file pattern with an addition to be able to set the default from the same file opposed to additional logic.

Latest version **1.0.1** (published 2017-11-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install group-array-then-sort
pnpm add group-array-then-sort
yarn add group-array-then-sort
bun add group-array-then-sort
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-11-01 |
| First published | 2017-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | John Carmichael |
| Maintainers | johncarmichael |
| Keywords | env, json, env.json |

## Links

- npm: https://www.npmjs.com/package/group-array-then-sort
- Repository: https://github.com/jdcrecur/group-array-then-sort
- Homepage: https://github.com/jdcrecur/env.json#readme
- Issues: https://github.com/jdcrecur/env.json/issues
- npm.io page: https://npm.io/package/group-array-then-sort

## Dependencies (1)

- [sort-by](https://npm.io/package/sort-by.md) ^1.2.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-11-01
- 1.0.0 — 2017-11-01

## README

# group-array-then-sort

```
npm i --save group-array-then-sort
```

## What is it

Group and array of objects by a given key, then sort the groups of array by another key either asc or desc.


## Example use:
Take this array of objects:
```
[{
  name: 'John',
  subject: 'English',
  score: 76,
  teacher: 'Mr Bob'
}, {
  name: 'John',
  subject: 'Science',
  score: 77,
  teacher: 'Mr Jim'
}, {
  name: 'John',
  subject: 'Maths',
  score: 56,
  teacher: 'Mr Ben'
}, {
  name: 'Janine',
  subject: 'Science',
  score: 62,
  teacher: 'Mr Jim'
}, {
  name: 'Janine',
  subject: 'Maths',
  score: 41,
  teacher: 'Mr Ben'
}]
```
You can then easily group the above by names into the following:
```
{ John: 
   [ { name: 'John', subject: 'Science', score: 77, teacher: 'Mr Jim' },
     { name: 'John', subject: 'Maths', score: 56, teacher: 'Mr Ben' },
     { name: 'John', subject: 'English', score: 76, teacher: 'Mr Bob' } 
   ],
  Janine: 
   [ { name: 'Janine', subject: 'Science', score: 62, teacher: 'Mr Jim' },
     { name: 'Janine', subject: 'Maths', score: 41, teacher: 'Mr Ben' } 
   ] 
 }

```

Using promises
```
const groupArrayThenSort = require('group-array-then-sort')
groupArrayThenSort(obj, 'name', 'subject', 'desc').then((sortedObj) => {
    console.log(sortedObj)
}).catch((e) => {
    console.error(e)
})
```

Using await
```
import groupArrayThenSort from 'group-array-then-sort'

// inside some async functino
let sortedObj
try{
   sortedObj = groupArrayThenSort(obj, 'name', 'subject', 'desc')
} catch (e) {
    console.error(e)
}    
```

See the tests in this repo for examples.

---
_Source: https://npm.io/package/group-array-then-sort · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
