6.0.10
Here are some helper functions for objects and arays
(Array)
To flat
Array
:
Flatted
(Array)
Array to remove elements
Array
:
Flatted
(Array
= []
)
Array of items
object
:
Fist element if
// returns 1
const a = [1]
getFirstFromSingleElementArray(a);
(Array
= []
)
Array of items
object
:
Fist element if exists, or an empty object
// returns 1
const a = [1]
getFirstFromSingleElementArray(a);
// returns {}
const b = []
getFirstFromSingleElementArray(b);
getAnyFromArray returns the first element of array or null
(Array
= []
)
Input Array
object
:
the first item or null
Returns the last element of array (or object) or null
object
:
the first item or null
Verify if an value is empty or null
(any)
Input
boolean
:
true if value is empty or null, otherwise false
Logic negation of isEmptyOrNull
(any)
Input value
boolean
:
true if value is not empty or null, otherwise false
Checks if string is type of {String}
(string)
Input String
(any | boolean)
:
true if it's string type
Verify if string is not ''.
(string)
input string
boolean
:
true if is String Not Blank
Truncate an string after max characters and add ... characters at string's end.
string
:
truncated String
This function removes the field with name key of arr itens.
object
:
object with key omitted
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.
object
:
object
This function removes the duplicate itens of the field prop inside myArr array.
(Array)
The input array.
(string)
The field name wich functions will verify oneness, it's not allow to use deep fields.
Array
:
with duplicates removed.
Get the item at the path path of the òbj
(string)
The field key that will be get.
(any
= null
)
The input object
(null | any)
:
resolved object
Array
:
concatenated
This functions flats a array using the 'f' function to determine final items of the array.
any
:
xs flatten using f function.
(Array
= []
)
Array of items
object
:
Fist element if
// returns 1
const a = [1]
getFirstFromSingleElementArray(a);
Return the first element of Array pr {}
(Array
= []
)
Input Array
{}
:
First element
Verify if undefined or null
(any)
object or any to validade
boolean
:
Logic Value