Support package for Kernel Framework
npm install @kernel-js/supportnpm install @kernel-js/support`
Helpers
$3
* env
* isArray
* isObject
* isEmpty
* isNotEmpty
* toBoolean
* removeEmpty
* mapEmptyToNull
Lodash
* camelCase
* capitalize
* find
* floor
* get
* has
* hasIn
* head
* keysIn
* last
* set
* snakeCase
* startCase
* map
* mapValues
* omitBy
* unset
$3
Gets the value of an environment variable.
env(key, [defaultValue])
__Arguments__
* key - the path to the property you want. You can use dot notation on nested objects
* defaultValue - the optional default value when the key was not found
`js
// Examples
env('NODE_ENV');
env('app.name');
env('app.name', 'My Default App Name');
`
---------------------------------------
$3
Return a boolean if the informed value is of Array type.
isArray(value)
__Arguments__
* value - any value
`js
// Example
isArray([]); // True
isArray({}); // False
isArray(''); // False
`
---------------------------------------
$3
Return a boolean if the informed value is of Object type.
isObject(value)
__Arguments__
* value - any value
`js
// Example
isObject({}); // True
isObject([]); // False
isObject(''); // False
`
---------------------------------------
$3
Check if the informed value is empty. This is a little different of lodash behaviour,
booleans are not considered empty and ' ' for example is considered empty.
isEmpty(value)
__Arguments__
* value - any value
`js
// Examples
isEmpty(true); // false
isEmpty(null); // true
isEmpty(undefined); // true
isEmpty(' '); // true
isEmpty({}); // true
isEmpty([]); // true
`
---------------------------------------
$3
Just the oposite of isEmpty.
isNotEmpty(value)
__Arguments__
* value - any value
`js
// Examples
isNotEmpty(true); // true
isNotEmpty(null); // false
isNotEmpty(undefined); // false
isNotEmpty(' '); // false
isNotEmpty({}); // false
isNotEmpty([]); // false
`
---------------------------------------
$3
Converts a give string or number into boolean or return null when cannot convert it.
toBoolean(value)
__Arguments__
* value - any value
`js
// Examples
toBoolean(1); // true
toBoolean('true'); // true
toBoolean('yes'); // true
toBoolean('on'); // true
toBoolean(0); // false
toBoolean('false'); // false
toBoolean('no'); // false
toBoolean('off'); // false
toBoolean('lorem ipsum'); // null
`
---------------------------------------
$3
Removes any empty property from object using isEmpty helper.
removeEmpty(value)
__Arguments__
* value - any object
`js
// Example
removeEmpty({"a": " ", "b": "b value", "c": null}); // {"b": "b value"}
`
---------------------------------------
$3
Converts any empty property of object to null using isEmpty helper.
mapEmptyToNull(value)
__Arguments__
* value - any object
`js
// Example
mapEmptyToNull({"a": " ", "b": "b value", "c": null, "d": {}}); // {"a": null, "b": "b value", "c": null, "d": null}
``