# swifty-array-helpers

> A set of convenience methods that extends Array's capabilities, inspired by Swift

Latest version **1.0.6** (published 2021-11-10) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install swifty-array-helpers
pnpm add swifty-array-helpers
yarn add swifty-array-helpers
bun add swifty-array-helpers
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2021-11-10 |
| First published | 2021-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Henrik Panhans |
| Maintainers | henrik-dmg |
| Keywords | array, prototype, extension |

## Links

- npm: https://www.npmjs.com/package/swifty-array-helpers
- Repository: https://github.com/henrik-dmg/swifty-array-helpers
- Homepage: https://github.com/henrik-dmg/swifty-array-helpers#readme
- Issues: https://github.com/henrik-dmg/swifty-array-helpers/issues
- npm.io page: https://npm.io/package/swifty-array-helpers

## Dependencies (1)

- [typescript](https://npm.io/package/typescript.md) ^4.3.2

## Recent versions

- 1.0.6 (latest) — 2021-11-10
- 1.0.4 — 2021-06-04
- 1.0.3 — 2021-06-01
- 1.0.2 — 2021-06-01
- 1.0.1 — 2021-06-01
- 1.0.0 — 2021-05-27

## README

# Array Helpers for JavaScript

![npm](https://img.shields.io/npm/v/swifty-array-helpers?logo=npm)
![npm](https://img.shields.io/npm/dm/swifty-array-helpers?logo=npm)

## What is this?

A collection of functions for the `Array.prototype` inspired by the methods that are available in Swift

## Usage

### Import

You need to import the methods first. Example:

```js
// ES6 module
import 'swifty-array-helper/firstWhere'

// node.js
require('swifty-array-helper/firstWhere')
```

### firstIndex

Finds the index of the first element matching the predicate.
Example:

```js
const array = [5, 3, 7, 12]
const index = array.firstIndex(x -> x <= 4) // 1
```

### firstWhere

Finds the first element matching the predicate (similar to `firstIndex`).
Example:

```js
const array = [5, 3, 7, 12]
const firstElementMatchingPredicate = array.firstWhere(x -> x <= 4) // 3
```

### filteredWhere

Filters the array based on the passed predicate
Example:

```js
const array = [5, 3, 7, 12]
const filteredArray = array.filteredWhere(x -> x <= 6) // [5, 3]
```

### compactMap

Maps all values, filtering `null` or `undefined` values out
Example:

```js
const array = [
  { name: 'Henrik' },
  { name: 'Henrik', lastName: 'Panhans' },
  { name: 'Henrik' },
  { name: 'Henrik' }
]
const lastNames = array.compactMap(value -> value.lastName) // ["Panhans"]
```

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