@tailored-apps/helpers

1.1.1 • Public • Published

@tailored-apps/helpers

js-standard-style

@tailored-apps/helpers contains some helper-functions and is part of the api-skeleton-2.

Installation and Updating

npm install @tailored-apps/helpers

Functions

registerExitListeners

Registers listeners that produce output on process termination

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.

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.

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

Usage

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: "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

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

Readme

Keywords

Package Sidebar

Install

npm i @tailored-apps/helpers

Weekly Downloads

28

Version

1.1.1

License

ISC

Unpacked Size

50.1 kB

Total Files

7

Last publish

Collaborators

  • dabls
  • tailoredapps