# @trenskow/group

> A small JavaScript function for grouping items in an array.

Latest version **0.1.7** (published 2026-10-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @trenskow/group
pnpm add @trenskow/group
yarn add @trenskow/group
bun add @trenskow/group
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.7 |
| Published | 2026-10-05 |
| First published | 2020-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kristian Trenskow |
| Maintainers | trenskow |
| Keywords | array, group |

## Links

- npm: https://www.npmjs.com/package/@trenskow/group
- Repository: https://github.com/trenskow/group
- Homepage: https://github.com/trenskow/group#readme
- Issues: https://github.com/trenskow/group/issues
- npm.io page: https://npm.io/package/@trenskow/group

## Recent versions

- 0.1.7 (latest) — 2026-10-05
- 0.1.6 — 2026-09-21
- 0.1.5 — 2026-09-18
- 0.1.4 — 2026-09-16
- 0.1.3 — 2026-09-16
- 0.1.2 — 2026-09-16
- 0.1.1 — 2026-08-03
- 0.1.0 — 2026-07-27
- 0.0.58 — 2026-07-27
- 0.0.57 — 2026-07-13
- 0.0.56 — 2026-07-02
- 0.0.55 — 2026-06-25
- 0.0.54 — 2026-06-08
- 0.0.53 — 2026-05-28
- 0.0.52 — 2026-05-19
- … 50 more at https://npm.io/package/@trenskow/group/versions

## README

group
----

A small JavaScript function for grouping items in an array.

# Installation

````bash
npm install --save @trenskow/group
````

````javascript
const group = require('@trenskow/group');
````

# Usage

````javascript
const grouped = group(/* array */, /* tester */);
````

| Parameter | Description |
|:----------|:------------|
| array     | The array that needs to be grouped.
| tester    | A function that is used to test the arrays items. *

> Test function takes in two items as parameters and should return `true` if they are in the same group.

## Example

````javascript
const animals = [{
	name: 'dog',
	type: 'mammal'
}, {
	name: 'goldfish',
	type: 'fish'
}, {
	name: 'crocodile',
	type: 'reptile'
}, {
	name: 'cat',
	type: 'mammal'
}, {
	name: 'guppy',
	type: 'fish'
}, {
	name: 'turtle',
	type: 'reptile'
}];

const animalsByType = group(animals, (item1, item2) => {
	return item1.type === item2.type;
});

/*
	Result:

	[
		[{
			name: 'dog',
			type: 'mammal'
		}, {
			name: 'cat',
			type: 'mammal'
		}],

		[{
			name: 'goldfish',
			type: 'fish'
		}, {
			name: 'guppy',
			type: 'fish'
		}],

		[{
			name: 'crocodile',
			type: 'reptile'
		}, {
			name: 'turtle',
			type: 'reptile'
		}]
	]

*/

````

# License

MIT (see LICENSE).

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