> For the complete documentation index, see [llms.txt](https://kernel-js.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kernel-js.gitbook.io/docs/support/untitled.md).

# @kernel-js/support

[![Build Status](https://travis-ci.org/kernel-js/support.svg?branch=master)](https://travis-ci.org/kernel-js/support) [![Coverage Status](https://coveralls.io/repos/github/kernel-js/support/badge.svg?branch=master)](https://coveralls.io/github/kernel-js/support?branch=master) <br>

> Util functions and classes

* Expose some [Lodash](https://www.npmjs.com/package/lodash) functions
* Exports additional helpers

## Install

`npm install @kernel-js/support`

## Lodash

* camelCase
* capitalize
* find
* floor
* get
* has
* hasIn
* head
* keysIn
* last
* set
* snakeCase
* startCase
* map
* mapValues
* omitBy
* unset

## Helpers

* env
* isArray
* isObject
* isEmpty
* isNotEmpty
* toBoolean
* removeEmpty
* mapEmptyToNull

### env

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

```javascript
// Examples
env('NODE_ENV');
env('app.name');
env('app.name', 'My Default App Name');
```

### isArray

Return a boolean if the informed value is of Array type.

```
isArray(value)
```

#### **Arguments**

* `value` - any value

```javascript
// Example
isArray([]); // True
isArray({}); // False
isArray(''); // False
```

### isObject

Return a boolean if the informed value is of Object type.

```
isObject(value)
```

#### **Arguments**

* `value` - any value

```javascript
// Example
isObject({}); // True
isObject([]); // False
isObject(''); // False
```

### isEmpty

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

```javascript
// Examples
isEmpty(true); // false
isEmpty(null); // true
isEmpty(undefined); // true
isEmpty(' '); // true
isEmpty({}); // true
isEmpty([]); // true
```

### isNotEmpty

Just the oposite of isEmpty.

```
isNotEmpty(value)
```

#### **Arguments**

* `value` - any value

```javascript
// Examples
isNotEmpty(true); // true
isNotEmpty(null); // false
isNotEmpty(undefined); // false
isNotEmpty(' '); // false
isNotEmpty({}); // false
isNotEmpty([]); // false
```

### toBoolean

Converts a give string or number into boolean or return null when cannot convert it.

```
toBoolean(value)
```

**Arguments**

* `value` - any value

```javascript
// 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
```

### removeEmpty

Removes any empty property from object using isEmpty helper.

```
removeEmpty(value)
```

**Arguments**

* `value` - any object

```javascript
// Example
removeEmpty({"a": " ", "b": "b value", "c": null}); // {"b": "b value"}
```

### mapEmptyToNull

Converts any empty property of object to null using isEmpty helper.

```
mapEmptyToNull(value)
```

**Arguments**

* `value` - any object

```javascript
// Example
mapEmptyToNull({"a": " ", "b": "b value", "c": null, "d": {}}); // {"a": null, "b": "b value", "c": null, "d": null}
```
