# @tailored-apps/helpers

> A small library providing various utility functions used in tailored apps backends (propably not very useful for anyone else)

Latest version **1.1.1** (published 2018-07-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install @tailored-apps/helpers
pnpm add @tailored-apps/helpers
yarn add @tailored-apps/helpers
bun add @tailored-apps/helpers
```

## 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.1.1 |
| Published | 2018-07-09 |
| First published | 2017-11-29 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=7.6.0 |
| Dependencies | 0 |
| Unpacked size | 48.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Michael Smesnik |
| Maintainers | dabls, daerion, tailoredapps |
| Keywords | utility, tailored apps |

## Links

- npm: https://www.npmjs.com/package/@tailored-apps/helpers
- Repository: https://gitlab.tailored-apps.com/libraries/node/helpers
- npm.io page: https://npm.io/package/@tailored-apps/helpers

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2018-07-09
- 1.1.0 — 2017-11-29
- 1.0.0 — 2017-11-29

## README

# @tailored-apps/helpers
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

**@tailored-apps/helpers** contains some helper-functions and is part of the [api-skeleton-2](https://gitlab.tailored-apps.com/backend/api-skeleton-2).

## Installation and Updating
```js
npm install @tailored-apps/helpers
```

## Functions

### registerExitListeners
Registers listeners that produce output on process termination

```js
function registerExitListeners (logger, moduleName = 'module')
```

### getDuration
Returns the difference between two Date objects in seconds - will instantiate a new Date object if no finish parameter is provided.

```js
function getDuration (start, finish)
```

### replaceTokens

Replaces tokens in a string with values from the provided "replacements" object

All tokens will be replaced with the values of the corresponding property in the replacements object, if such a
property exists (i.e. is not undefined). Otherwise, token literals will be returned.

Returns a string with the tokens replaced.

```js
function replaceTokens (str, replacements, tokenStart = '{', tokenEnd = '}')
```

**Usage**
```js
replaceTokens('this {fancyProp} will be replaced, {poorMe} will not', { fancyProp: 'strange thing' })
```
input | value
-|-
str| this {fancyProp} will be replaced, {poorMe} will not
replacements| { fancyProp: 'strange thing' }
tokenStart | {
tokenEnd | }

**returns:** </br>
"this strange thing will be replaced, {poorMe} will not"

### requireNodeEnv

The simplest of utility functions - will throw an error if NODE_ENV is not set

```js
function requireNodeEnv (errorMessage = 'NODE_ENV environment variable is not set.')
```

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