# compact-map

> maps and compacts at the same time.

Latest version **0.3.1** (published 2016-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install compact-map
pnpm add compact-map
yarn add compact-map
bun add compact-map
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2016-04-14 |
| First published | 2016-04-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | George Bonner |
| Maintainers | georgebonnr |
| Keywords | node, react, es2015, eslint |

## Links

- npm: https://www.npmjs.com/package/compact-map
- Repository: https://github.com/georgebonnr/compact-map
- Homepage: https://github.com/georgebonnr/compact-map#readme
- Issues: https://github.com/georgebonnr/compact-map/issues
- npm.io page: https://npm.io/package/compact-map

## Dependencies (1)

- [null-like](https://npm.io/package/null-like.md) ^0.1.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2016-04-14
- 0.3.0 — 2016-04-14
- 0.2.0 — 2016-04-13
- 0.1.0 — 2016-04-13

## README

maps and compacts at the same time.

By default compactMap filters out `null` and `undefined` but perserves falsy values.

Example 1:
```
compactMap(
    [{foo: 0}, {foo: 'truthy'}, {foo: null}, {foo: undefined}],
    (value, index, coll) => value.foo
)
```
returns:
```
[0, 'truthy']
```

Note that the compacting logic operates on the the return value from the mapping callback, not the original value in the source collection.

Example 2:
````
compactMap(
    [undefined, null, false],
    (value, index, coll) => value + ' mapped'
)
```
returns:
```
['undefined mapped', 'null mapped', 'false mapped']
```


To remove falsy values as well, pass in the options object: `{strict: true}`.

Example:
```
compactMap(
    [{foo: 0}, {foo: 'truthy'}, {foo: null}, {foo: undefined}],
    (value, index, coll) => value.foo,
    { strict: true }
)
```
returns:
`['truthy']`

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