# @benderthecrime/pick

> Returns a partial copy of an object containing only the keys specified.

Latest version **1.0.0** (published 2020-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @benderthecrime/pick
pnpm add @benderthecrime/pick
yarn add @benderthecrime/pick
bun add @benderthecrime/pick
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-05-31 |
| First published | 2020-05-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Joe Groseclose |
| Maintainers | benderthecrime |
| Keywords | pick, object, copy, partial, keys |

## Links

- npm: https://www.npmjs.com/package/@benderthecrime/pick
- npm.io page: https://npm.io/package/@benderthecrime/pick

## Dependencies (1)

- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^2.1.0

## Recent versions

- 1.0.0 (latest) — 2020-05-31

## README

# @benderthecrime/pick

Returns a partial copy of an object containing only the keys specified.

---

⚠️**NOTE: This package is great for my limited use cases and there are probably better options for your production apps.**

---

## Installation

```sh
npm i @benderthecrime/pick
```

## Usage

Require the module in your Node.js service:

```js
const pick = require('@benderthecrime/pick')
const {pick, pickAll} = require('@benderthecrime/pick')
```

Use `pick` when you want to skip missing keys in the returned Object:

```js
const pick = require('@benderthecrime/pick')

const user = {firstName: 'Jane', lastName: 'Doe', password: 'supersecret7'}
const responseFields = pick(['email', 'firstName', 'lastName'], user) // {firstName: 'Jane', lastName: 'Doe'}
```

Alternatively, `pick` can return a partially applied function:

```js
const app = require('express')()
const pick = require('@benderthecrime/pick')

const pickUserResponseFields = pick(['firstName', 'lastName'])

app.get('/user/self', (_, res) => {
  const user = {firstName: 'Jane', lastName: 'Doe', password: 'supersecret7'}
  res.send(pickUserResponseFields(user))
})
```

Use `pickAll` when you want to include missing keys in the returned Object:

```js
const {pickAll} = require('@benderthecrime/pick')

const user = {firstName: 'Jane', lastName: 'Doe', password: 'supersecret7'}
const responseFields = pickAll(['email', 'firstName', 'lastName'], user) // {email: undefined, firstName: 'Jane', lastName: 'Doe'}
```

Similarly to `pick`, `pickAll` can also return a partial:

```js
const app = require('express')()
const {pickAll} = require('@benderthecrime/pick')

const pickUserResponseFields = pickAll(['firstName', 'lastName'])

app.get('/user/self', (_, res) => {
  const user = {firstName: 'Jane', lastName: 'Doe', password: 'supersecret7'}
  res.send(pickUserResponseFields(user))
})
```

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