Options
All
  • Public
  • Public/Protected
  • All
Menu

This class provides some static methods which might be helpful when working with objects.

Hierarchy

  • ObjectUtil

Index

Constructors

Methods

Constructors

constructor

Methods

Static getPathByKeyValue

  • getPathByKeyValue(obj: any, key: string, value: string | number | boolean, currentPath?: string): string
  • Returns the dot delimited path of a given object by the given key-value pair. Example:

    const obj = {
      level: 'first',
      nested: {
        level: 'second'
      }
    };
    const key = 'level';
    const value = 'second';
    
    ObjectUtil.getPathByKeyValue(obj, key, value); // 'nested.level'
    

    Note: It will return the first available match!

    Parameters

    • obj: any

      The object to obtain the path from.

    • key: string

      The key to look for.

    • value: string | number | boolean

      The value to look for.

    • currentPath: string = ''

    Returns string

Static getValue

  • getValue(queryKey: string, queryObject: any): any
  • Method may be used to return a value of a given input object by a provided query key. The query key can be used in two ways:

    • Single-value: Find the first matching key in the provided object (Use with caution as the object/array order may not be as expected and/or deterministic!).
    • Backslash ("/") separated value: Find the last (!) matching key in the provided object.

    Parameters

    • queryKey: string

      The key to be searched.

    • queryObject: any

      The object to be searched on

    Returns any

    The target value or undefined if the given couldn't be found, or an object if a path was passed, from which we only could find a part, but not the most specific one. TODO Harmonize return values

Generated using TypeDoc