open-index/open-npm huggingface dataset:
npm package: @dustfoundation/utils
Description: Shared Utils for Dust Foundation projects
Latest version: 3.1.1

# @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' } }
```