# helper-methods-js

> A package that provides helper methods for common and not-so-common use cases

Latest version **1.0.2** (published 2023-04-29) · 0 weekly downloads

## Install

```sh
npm install helper-methods-js
pnpm add helper-methods-js
yarn add helper-methods-js
bun add helper-methods-js
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-04-29 |
| First published | 2023-01-14 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Maintainers | samhirtarif |
| Keywords | helper, helper methods, deepcopy, deep copy, dedupe, deduplication, remove duplicates, async, indexes, indexesOf, trim, trim delimeters, trim start, trim end |

## Links

- npm: https://www.npmjs.com/package/helper-methods-js
- Repository: https://github.com/samhirtarif/helper-methods-js
- Homepage: https://github.com/samhirtarif/helper-methods-js#readme
- Issues: https://github.com/samhirtarif/helper-methods-js/issues
- npm.io page: https://npm.io/package/helper-methods-js

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-04-29
- 1.0.0 — 2023-01-14

## README

# **Helper methods**
A package that provides helper methods for common and not-so-common use cases

## **Contributions are welcome!**

## Installation
```sh
npm install helper-methods-js
```

## Methods
- [**`deepcopy`**](#deepcopy)
- [**`dedupe`**](#dedupe)
- [**`indexesOf`**](#indexesOf)
- [**`isAsyncFunction`**](#isAsyncFunction)
- [**`trimDelimeters`**](#trimDelimeters)

<br />

---
<br />

### **`deepcopy`**

This method creates a deep copy of the provided object to the given depth. Beyond that depth, the object is shallow copied

| Parameter     | Description     | Default Value |
| :------------ |:---------------| :-------------|
| `obj`           | The object to be copied                | N/A             |
| `max_depth` (optional)     | Maximum depth to which the function would copy the object. Beyond this depth shallow copies would be created. A value of `0` implies that the entire object should be deep copied.    | `0`             |

<br />

#### Sample usage
```js
import { deepcopy } from 'helper-methods-js'

deepcopy({ name: 'bob' }, 0);
```
---
<br />

### **`dedupe`**

This method provides implementation to remove duplicates from an array.

| Parameter     | Description     | Default Value |
| :------------ |:---------------| :-------------|
| `array`           | The array that needs duplicates removed                | N/A             |
| `condition` (optional)    | A function that returns either `true` or `false`. This condition is executed for each array value and the values for which it returns `true` are removed. In case this condition is not provided, elements are removed on equality comparison.    | N/A             |

<br />

#### Sample usage
```js
import { dedupe } from 'helper-methods-js'

const cars = [
  { name: "audi", owner: "a" },
  { name: "bmw", owner: "x" },
  { name: "audi", owner: "b" },
  { name: "bmw", owner: "b" },
];

dedupe(cars, (e, i) => e.owner === i.owner)
```
---
<br />

### **`indexesOf`**

This method provides implementation to return indexes of all elements that match a specific condition

| Parameter     | Description     | Default Value |
| :------------ |:---------------| :-------------|
| `array`           | The array that needs duplicates removed                | N/A             |
| `condition`    | It can either be a value or a functions. In case of a function, the function should return `true` or `false`. This condition is executed for each array value and the values for which it returns `true` are added to the list of indexes returned. In case this condition is not provided, elements are removed on equality comparison.    | N/A             |

<br />

#### Sample usage
```js
import { indexesOf } from 'helper-methods-js'

const objs = [
  { age: 21, nationality: "a" },
  { age: 24, nationality: "a" },
  { age: 21, nationality: "b" },
  { age: 32, nationality: "c" },
  { age: 42, nationality: "b" },
  { age: 52, nationality: "c" },
  { age: 21, nationality: "a" },
]

const indexes = indexesOf(objs, (i: any) => i.nationality === "b")
```
---
<br />

### **`isAsyncFunction`**

This method returns whether a function is async or not.

| Parameter     | Description     | Default Value |
| :------------ |:---------------| :-------------|
| `fn`    | The function for which it needs to be determined whether it is async or not.    | N/A             |

<br />

#### Sample usage
```js
import { isAsyncFunction } from 'helper-methods-js'

const testFn = async () => {};
isAsyncFunction(testFn) // returns true

const testFnSync = () => {};
isAsyncFunction(testFnSync) // returns false
```
---
<br />

### **`trimDelimeters`**

This method takes a string and removes the provided delimeters from the start and end of the string.

| Parameter     | Description     | Default Value |
| :------------ |:---------------| :-------------|
| `str`           | The string to be trimed                | N/A             |
| `delimeters`    | A list of delimeters to be trimned from the start and/or end of the string provided.    | N/A             |
| `options` (optional)    | An object with values `trimStart` and `trimEnd` that represent if the string should only be trimmed from start and/or end respectively.     | `{ trimStart: true, trimEnd: true }`            |

<br />

#### Sample usage
```js
import { trimDelimeters } from 'helper-methods-js'

trimDelimeters("&&*ABC*(&", ["&", "*"]) // outputs "ABC*("
```

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