@tailored-apps/helpers
v1.1.1
Published
A small library providing various utility functions used in tailored apps backends (propably not very useful for anyone else)
Downloads
96
Readme
@tailored-apps/helpers
@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.')