Objects

Here are some helper functions for objects and arays

Objects
Static Members
objects
flatten
Parameters
arrayOfArrays (Array) To flat
Returns
Array: Flatted
cleanArray
Parameters
a (Array) Array to remove elements
Returns
Array: Flatted

getFirstFromSingleElementArray

src/object/index.js
getFirstFromSingleElementArray
Parameters
array (Array = []) Array of items
Returns
object: Fist element if
Example
// returns 1
const a = [1]
getFirstFromSingleElementArray(a);

getFirstFromSingleElementArrayNotNull

src/object/index.js
getFirstFromSingleElementArrayNotNull
Parameters
array (Array = []) Array of items
Returns
object: Fist element if exists, or an empty object
Example
// returns 1
const a = [1]
getFirstFromSingleElementArray(a);

// returns {}
const b = []
getFirstFromSingleElementArray(b);

getAnyFromArray

src/object/index.js

getAnyFromArray returns the first element of array or null

getAnyFromArray
Parameters
array (Array = []) Input Array
Returns
object: the first item or null

getLastFromArrayOrObject

src/object/index.js

Returns the last element of array (or object) or null

getLastFromArrayOrObject
Parameters
array ((Array | object) = []) Input Array or object
Returns
object: the first item or null

isEmptyOrNull

src/object/index.js

Verify if an value is empty or null

isEmptyOrNull
Parameters
value (any) Input
Returns
boolean: true if value is empty or null, otherwise false

isNotEmptyOrNull

src/object/index.js

Logic negation of isEmptyOrNull

isNotEmptyOrNull
Parameters
value (any) Input value
Returns
boolean: true if value is not empty or null, otherwise false

verifyIfString

src/object/index.js

Checks if string is type of {String}

verifyIfString
Parameters
value (string) Input String
Returns
(any | boolean): true if it's string type

isStringNotBlank

src/object/index.js

Verify if string is not ''.

isStringNotBlank
Parameters
value (string) input string
Returns
boolean: true if is String Not Blank

truncateString

src/object/index.js

Truncate an string after max characters and add ... characters at string's end.

truncateString
Parameters
string (string) The input string.
max (number = 30) Max number o characters to truncate.
Returns
string: truncated String

omitDeepArrayWalk

src/object/index.js

This function removes the field with name key of arr itens.

omitDeepArrayWalk
Parameters
arr ((object | Array)) The input object.
key (string) The field key that will be removed.
Returns
object: object with key omitted
Example
import { omitDeepArrayWalk } from '@tecsinapse/es-utils/core/object'
const omitDeepArrayWalkTest = [
     {id:1, vector: 1},
     {id:2, vector: 2},
     {id:3, vector: 3},
];

console.log("omitDeepArrayWalk: " + omitDeepArrayWalk(omitDeepArrayWalkTest, 'vector').map(c=>c.id));

This function removes the field with name key inside the obj object.

omitDeep
Parameters
obj (object) The input object.
key (string) The field key that will be removed.
Returns
object: object

removeDuplicates

src/object/index.js

This function removes the duplicate itens of the field prop inside myArr array.

removeDuplicates
Parameters
myArr (Array) The input array.
prop (string) The field name wich functions will verify oneness, it's not allow to use deep fields.
Returns
Array: with duplicates removed.

Get the item at the path path of the òbj

resolveObj
Parameters
path (string) The field key that will be get.
obj (any = null) The input object
Returns
(null | any): resolved object
concat
Parameters
x (Array) first Array
y (Array) second Array
Returns
Array: concatenated

This functions flats a array using the 'f' function to determine final items of the array.

flatMap
Parameters
f (Function) The flat function
xs (Array) The input array
Returns
any: xs flatten using f function.

getFirstElementOfArray

src/object/index.js
getFirstElementOfArray
Parameters
array (Array = []) Array of items
Returns
object: Fist element if
Example
// returns 1
const a = [1]
getFirstFromSingleElementArray(a);

getFirstElementOfArray

src/object/index.js

Return the first element of Array pr {}

getFirstElementOfArray
Parameters
array (Array = []) Input Array
Returns
{}: First element

isNotUndefOrNull

src/object/index.js

Verify if undefined or null

isNotUndefOrNull
Parameters
value (any) object or any to validade
Returns
boolean: Logic Value