Module: rgjs/val

RGJS6 Value module.

Methods


<static> fallback(val, fallback)

Return value if set or return default.

Parameters:
Name Type Description
val anything

A value

fallback anything

The fallback value, returned if 'val' is undefined or null

Returns:

The value or fallback value

Type
anything
Example
const o = {a: 0, b: '', c: null};
rgjs.val.fallback(o, 'fallback') // {a: 0, b: '', c: {}, d: []}
rgjs.val.fallback(o.a, 'fallback') // 0
rgjs.val.fallback(o.b, 'fallback') // ''
rgjs.val.fallback(o.c, 'fallback') // 'fallback'
rgjs.val.fallback(o.d, 'fallback') // 'fallback'

<static> isEmpty(val)

Check if a value is unset, false, undefined, null or empty.
Note: may not work with ES6 symbols: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Symbol

Parameters:
Name Type Description
val anything

A value

Returns:

True if empty, false if not.

Type
boolean
Example
const o = {a: 0, b: '', c: {}, d: []};
rgjs.val.isEmpty(o) // false
rgjs.val.isEmpty(o.a) // false
rgjs.val.isEmpty(o.b) // true
rgjs.val.isEmpty(o.c) // true
rgjs.val.isEmpty(o.d) // true

<static> isSet(val)

Check if a value is set (not undefined and not null).

Parameters:
Name Type Description
val anything

A value

Returns:

True if set, false if not.

Type
boolean
Example
const o = {a: 1, b: false, c: null};
rgjs.val.isSet(o.a) // true
rgjs.val.isSet(o.b) // true
rgjs.val.isSet(o.c) // false

<static> isSetNotFalse(val)

Check if a value is set (not undefined and not null) and not false.

Parameters:
Name Type Description
val anything

A value

Returns:

True if set, false if not.

Type
boolean
Example
const o = {a: 1, b: false, c: null};
rgjs.val.isSetNotFalse(o.a) // true
rgjs.val.isSetNotFalse(o.b) // false
rgjs.val.isSetNotFalse(o.c) // false

<static> isTruthy(val)

Check if a value is (logically) truthy.
Not truthy: false, undefined, null, empty, '0', 'false', [], {}, NaN.

Parameters:
Name Type Description
val anything

A value

Returns:

True if truthy, false if not.

Type
boolean
Example
const o = {a: 0, b: '', c: {}, d: []};
rgjs.val.isTruthy(o) // true
rgjs.val.isTruthy(o.a) // false
rgjs.val.isTruthy(o.b) // false
rgjs.val.isTruthy(o.c) // false
rgjs.val.isTruthy(o.d) // false

<static> isUndefined(val)

Check if a value is undefined.

Parameters:
Name Type Description
val anything

A value

Returns:

True if set, false if not.

Type
boolean
Example
const o = {a: 1, b: false, c: null};
rgjs.val.isUndefined(o.a) // false
rgjs.val.isUndefined(o.b) // false
rgjs.val.isUndefined(o.c) // false
rgjs.val.isUndefined(o.d) // true