# @dustfoundation/utils

> Shared Utils for Dust Foundation projects

Latest version **3.1.1** (published 2022-12-14) · 0 weekly downloads

## Install

```sh
npm install @dustfoundation/utils
pnpm add @dustfoundation/utils
yarn add @dustfoundation/utils
bun add @dustfoundation/utils
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2022-12-14 |
| First published | 2022-05-06 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | hibanka, maxim-levitskiy |

## Links

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

## Recent versions

- 3.1.1 (latest) — 2022-12-14
- 2.4.1 — 2022-07-05
- 2.4.0 — 2022-07-04
- 2.3.0 — 2022-06-23
- 2.2.0 — 2022-05-24
- 2.1.0 — 2022-05-10
- 2.0.0 — 2022-05-06
- 2.0.0-rc.2 — 2022-05-06
- 2.0.0-rc.1 — 2022-05-06

## README

# @dustfoundation/utils

![CI](https://github.com/DustFoundation/utils/actions/workflows/ci.yml/badge.svg)
[![NPM Version](https://badgen.net/npm/v/@dustfoundation/utils)](https://npmjs.com/package/@dustfoundation/utils)
[![Minimum Node.js Version](https://badgen.net/npm/node/@dustfoundation/utils)](https://npmjs.com/package/@dustfoundation/utils)

Shared **Utils** for Dust Foundation projects.

## Installation

```sh
npm install --save @dustfoundation/utils
```

## Features

### Util: Build Domain

Builds custom domain for `dust.foundation`. Acceptable stages: `dev`, `stage`, `prod`.

```ts
buildDomain('dev');
// => https://dev.dust.foundation
buildDomain('prod');
// => https://dust.foundation
buildDomain('dev', 'content');
// => https://content.dev.dust.foundation
buildDomain('dev', 'content', 'ws://');
// => ws://content.dev.dust.foundation
buildDomain('###');
// => throws Error
```

### Array: Chunk

Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements. If chunk size is 0, throws error.

```ts
chunk([1, 2, 3, 4, 5], 3);
// => [[1, 2, 3], [4, 5]]
```

### Array: Group By

Creates an object composed of keys generated by taking given key from each array element. The order of grouped values is determined by the order they occur in array. The corresponding value of each key is an array of elements responsible for generating the key.

```ts
groupBy([
  { symbol: 'BTC', price: 1 },
  { symbol: 'ETH', price: 2 },
  { symbol: 'ETH', price: 3 },
  { symbol: 'BTC', price: 4 },
  { bad: true },
], 'symbol');
// => { BTC: [1, 4], ETH: [2, 3] }
```

### Object: Omit

Creates an object composed of the own and inherited enumerable property paths of object that are not omitted.

```ts
omit({
  name: 'Bitcoin',
  symbol: 'BTC',
  price: 50000,
}, 'name', 'price');
// => { symbol: 'BTC' }
```

### Object: Replace Nullish

Creates an object with same properties but all `null` and `undefined` values are replaced by the given value. If `deep` enabled, works recursively (including arrays).

```ts
// deep: false (default)
replaceNullish({
  key: 'value',
  _null: null,
  _undefined: undefined,
}, 'any_custom_value');
// => { key: 'value', _null: 'any_custom_value', _undefined: 'any_custom_value' }

// deep: true
replaceNullish({
  key: 'value',
  nested: {
    _null: null,
    _undefined: undefined,
  },
}, 'any_custom_value', true);
// => { key: 'value', nested: { _null: 'any_custom_value', _undefined: 'any_custom_value' } }
```

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