Module Helpers

Environment Helpers

Helper types and functions.

Use cases

Table of Contents
  1. mutable()
  2. filterNil()
  3. asError()
  4. asString()
  5. delayedPromise()
  6. ifDefined()

mutable()

mutable(Object.freeze({ a: 0 })); // {a:0}
mutable('a'); // 'a'

filterNil()

// observable = -null-undefined-0-1-2-
observable.pipe(filterNil()).subscribe(); // -----0-1-2-

asError()

const error = new Error('a');
asError(error); // new Error('a')
asError('a'); // new Error('a')

asString()

asString({ a: 0 }); // '{"a":0}'
asString({ a: () => ({ a: 0 }) }); // '{"a":"() => ({ a: 0 })"}'
asString([0, 'a', null, true]); // '[0,"a",null,true]'
asString([{ a: 0 }]); // '[{"a":0}]'

delayedPromise()

delayedPromise('a', 10); // Promise resolves 'a' after 10ms

ifDefined()

Executes an assertion if the value is not nil. If the value is nil returns true.

ifDefined(value?.id, typeof value?.id === 'string');

Index

Type Aliases

Functions

Generated using TypeDoc