# instant-utils

> Lightweight utility library to assist other `instant` packages.

Latest version **1.0.1** (published 2018-12-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install instant-utils
pnpm add instant-utils
yarn add instant-utils
bun add instant-utils
```

## 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.1 |
| Published | 2018-12-17 |
| First published | 2018-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Craig Myles |
| Maintainers | cjmyles |
| Keywords | javascript |

## Links

- npm: https://www.npmjs.com/package/instant-utils
- Repository: https://github.com/cjmyles/instant-utils
- Homepage: https://github.com/cjmyles/instant-utils#readme
- Issues: https://github.com/cjmyles/instant-utils/issues
- npm.io page: https://npm.io/package/instant-utils

## Recent versions

- 1.0.1 (latest) — 2018-12-17
- 1.0.0 — 2018-12-14
- 0.0.3 — 2018-10-30
- 0.0.2 — 2018-10-03
- 0.0.1 — 2018-08-29

## README

# Instant Utils

Lightweight utility library to assist other [`instant`](https://github.com/cjmyles/instant) packages.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
  - [asyncForEach](#asyncforeach)
  - [asyncMap](#asyncmap)
  - [pick](#pick)
  - [removeUndefineds](#removeundefineds)
- [Contributing](#contributing)
- [License](#license)

## Installation

You can install this package using npm:

```bash
$ npm install instant-utils
```

## Usage

Here is a quick example to get you started:

**ES Modules**

```javascript
import { pick } from 'instant-utils';

const country = { id: 1, name: 'Australia' };
const result = pick(country, ['name']);
console.log(result); // => { name: 'Australia' }
```

**CommonJS Modules**

```javascript
var utils = require('instant-utils');

var country = { id: 1, name: 'Australia' };
var result = utils.pick(country, ['name']);
console.log(result); // => { name: 'Australia' }
```

## API

### asyncForEach

Asyncronous For Each function, enabling multiple loop iterations to be wrapped in one completion promise.

#### Arguments

`arr (Array)`: The array to iterate over.\
`iteratee (Function)`: The function invoked per iteration.

#### Returns

`Array`

#### Example Usage

```js
async function getCountries() {
  const countries = ['scotland', 'australia'],
  ];
  return await asyncForEach(countries, country => {
    const response = await fetch(`/api/countries/${country}`);
    return await response.json();
  });
}
```

### asyncMap

Asyncronous Map function, enabling multiple map iterations to be wrapped in one completion promise.

#### Arguments

`arr (Array)`: The array to iterate over.\
`iteratee (Function)`: The function invoked per iteration.

#### Returns

`Array`

#### Example Usage

```js
async function mapCountries() {
  const countries = [
    { id: 'scotland', name: 'Scotland' },
    { id: 'australia', name: 'Australia' },
  ];
  return await asyncMap(countries, country => {
    return {
      ...country,
      visited: true,
    };
  });
}
```

### pick

Creates an object composed of the picked object properties.

#### Arguments

`obj (Object)`: The source object.\
`keys (Array)`: The property keys to pick.

#### Returns

`Object`

#### Example Usage

```js
const country = { id: 1, name: 'Australia' };
const result = pick(country, ['name']);
console.log(result); // => { name: 'Australia' }
```

### removeUndefineds

Creates an object composed of non-undefined-valued object properties.

#### Arguments

`obj (Object)`: The source object.

#### Returns

`Object`

#### Example Usage

```js
const country = { id: 1, name: 'Australia', unicorns: undefined };
const result = removeUndefineds(country);
console.log(result); // => { id: 1, name: 'Australia' }
```

## Contributing

We'd greatly appreciate any [contribution](CONTRIBUTING.md) you make.

## License

[MIT](LICENSE)

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