Options
All
  • Public
  • Public/Protected
  • All
Menu

@cat5th/key-serializer

Index

Type aliases

Functions

Type aliases

PublicKey

PublicKey: Exclude<PropertyKey, symbol>

means a iterable object key, includes string and number, but symbol

Functions

get

  • get(target: object, keys: string | PublicKey[] | null): any
  • deepin target, and get value or keys from target

    Parameters

    • target: object
    • keys: string | PublicKey[] | null

      it is only a alias of query(obj, keys).value

      
      const obj = { a: { b: [1, 2] } }
      query(obj, 'a.b[0]') // => 1
      

    Returns any

parse

  • parse a string to PublicKey array

     parse('a[0].b[2]') // => ['a', 0, 'b', 2]

    Parameters

    • str: string

      the string you wanna parse

    Returns PublicKey[]

query

  • query(target: any, keys?: string | PublicKey[] | null, createdTarget?: boolean): object | object | object
  • query the result from target by keys

    Parameters

    • target: any
    • Optional keys: string | PublicKey[] | null
    • Default value createdTarget: boolean = false

      if it's true, this funciton will create object or array when necessary

      const obj = { a: { b: [1, 2] } }
      query(obj, 'a.b[0]') // => { target: [1, 2], key: 0, value: 1 }

      or with createTarget param

      const obj = { }
      query(obj, 'a.b[0]', true) => { target: [], key: 0, value: undefined }

    Returns object | object | object

set

  • set(target: object, keys: string | PublicKey[] | null, value: any): void
  • deepin target, and set value of keys from target

    Parameters

    • target: object
    • keys: string | PublicKey[] | null
    • value: any
      
      const obj = { a: { b: [1, 2] } }
      query(obj, 'a.b[0]', 3)
      obj.a.b[0] === 3 // => true
      

    Returns void

stringify

  • stringify PublicKey array to string

    stringify(['a', 0, 'b', 2]) // => 'a[0].b[2]'
    
    **notice**: number key will be converted to ```'[xxx]'```, and string key will be converted to ```.xxx

    `

    Parameters

    • arr: PublicKey[]

      the key arr you wanna stringify

    Returns string

Generated using TypeDoc