General

grupojaque-ngx-commonsGlobals"lib/helpers/general.helper"

General Helper

This module implements functions that we've used (and even implemented) repeatedly in the same project. Most of the functions in here are assumed to be requiered at least once in common front-end projects.

Index

Data Handling Functions

Other Functions

Data Handling Functions

getObjectPath

getObjectPath(obj: any, path: string): any

Defined in lib/helpers/general.helper.ts:115

Return the value that an object holds in a given path

When the path doesn't exist in any of the anidated keys, it'll return undefined.

// returns `'a'`
getObjectPath(
{shallow: '', deep: {one: 1, two: 2, deeper: { a: 'a'}}},
"deep.deeper.a");
// returns `undefined`
getObjectPath(
{shallow: '', deep: {one: 1, two: 2, deeper: { a: 'a'}}},
"myprop");

Parameters:

NameTypeDescription
objanyAn object
pathstringPath to access, example "pagination.limit"

Returns: any


objectHasPath

objectHasPath(obj: any, path: string): boolean

Defined in lib/helpers/general.helper.ts:38

Check if a deep property path is defined in an object

The path is received as a string separated with dots, as you'd otherwise try to access those properties: prop.prop2.prop3.

If any property in the path is undefined, the function will return false.

// returns true, `deep.deeper.a` is defined
objectHasPath(
{shallow: '', deep: {one: 1, two: 2, deeper: { a: 'a'}}},
"deep.deeper.a")
// returns false, `deep.deeper.deepest` is undefined
objectHasPath(
{shallow: '', deep: {one: 1, two: 2, deeper: { a: 'a'}}},
"deep.deeper.deepest.a")

Parameters:

NameTypeDescription
objanyObject to find the propety path
pathstringDot-separated string representing the property path to check

Returns: boolean

Whether all the properties in the path are defined or not


objectHasPaths

objectHasPaths(obj: any, paths: string[]): boolean

Defined in lib/helpers/general.helper.ts:85

Check if an object contains all of many deep property paths

Each path is received as a string separated with commas, as you'd otherwise try to access those properties: prop.prop2.prop3.

If any of the paths in the paths array is undefined, the function will return false.

// returns true | All paths are defined
hasPropertyPaths(
{shallow: '', deep: {one: 1, two: 2, deeper: { a: 'a'}}},
["shallow", "deep.one", "deep.deeper.a"])
// returns false | `deep.deeper.deepest` is undefined
hasPropertyPaths(
{shallow: '', deep: {one: 1, two: 2, deeper: { a: 'a'}}},
["shallow", "deep.one", "deep.deeper.deepest.a"])

Parameters:

NameTypeDescription
objanyObject to find the propety paths
pathsstring[]Each string represents the path to check

Returns: boolean

Whether each path in the list is defined or not


Other Functions

findValueInObjectArray

findValueInObjectArray(array: any[], path: string, value: string | boolean | number): any

Defined in lib/helpers/general.helper.ts:168

Returns the first element that matches a shallow comparison

For every object in the array, it'll try to fetch the property value for the received path and shallow-compare it to the value to match.

// returns `{a: 30, b: 40}`
findValueInObjectArray([{a: 10}, {b: 20}, {a: 30, b: 40}], "a", 30)
// returns `undefined`
findValueInObjectArray({}, "a", 30)

Parameters:

NameTypeDescription
arrayany[]Array of objects to look in
pathstringProperty path of the value to compare
valuestring | boolean | numberValue that matches the searched object

Returns: any


getArrayOfAnEnum

getArrayOfAnEnum<T>(obj: T): Array‹object›

Defined in lib/helpers/general.helper.ts:131

Type parameters:

T

Parameters:

NameTypeDescription
objTis an enum

Returns: Array‹object›

object array