BackgroundModule mahalo/utils/key-path

This module contains utility functions to deal with pathsinside of objects.

Index

Functions

keyPath

  • keyPath(obj: Object, path: string, val?: any): any
  • Finds a value along a given path or sets a value in the given pathwhen called with a third argument.

    A key path is a chain of keys to follow inside of an object. They aresepareted by a dot. If your key actually contains a dot you canescape it with the ^ symbol. If you need an actual ^ symbolin a key you can use ^^. You get the idea.

    alias

    { keyPath } from mahalo

    Parameters
    • obj: Object
    • path: string
    • Optional val: any
    Returns any

toKeyPath

  • toKeyPath(keys: string[] | string): string
  • Transforms either an array of keys or a single key intoa valid path with escaped dots.

    Parameters
    • keys: string[] | string
    Returns string

toKeys

  • toKeys(str: string): Array<string>
  • Parses a path string into an array of keysfor the given path.

    Example
    toKeys('user.name'); // ['user', 'name']toKeys('user^.name'); // ['user.name']toKeys('user^^.name'); // ['user^', 'name']
    Parameters
    • str: string
    Returns Array<string>