Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/misc"

Index

Functions

getPath

  • getPath(obj: any, path: string): any
  • Get value given the Path as "path.to.nested" string

    Parameters

    • obj: any
    • path: string

    Returns any

getSortType

  • getSortType(arr: any[], field: string): string
  • Get the type of element that will be sorted as [object ${TYPE}]

    Examples:

    getSortType([{a: 1}], "a"); // [object Number]
    getSortType([{a: "b"}], "a"); // [object String]
    getSortType([{a: new Date()}], "a"); // [object Date]
    getSortType([{a: []}], "a"); // [object Array]
    getSortType([{a: {}}], "a"); // [object Object]
    

    Parameters

    • arr: any[]

      Array to check for type, will not send back a type if null or undefined

    • field: string

      field name to check against

    Returns string

isEmpty

  • isEmpty(obj: any): boolean
  • Checks current element if it empty

    Examples:

    isEmpty({}); // true
    isEmpty([]); // true
    isEmpty(""); // true
    isEmpty(null); // true
    isEmpty(undefined); // true
    

    Parameters

    • obj: any

    Returns boolean

merge

  • merge(left: any[], right: any[], sortField: string, sort: number, type: string): any[]
  • Parameters

    • left: any[]
    • right: any[]
    • sortField: string
    • sort: number
    • type: string

    Returns any[]

mergeSort

  • mergeSort(toSort: any[], sortField: string, sortParam: number, type: any): any
  • Sort array of documents using MergeSort

    Examples:

    let docs = [{n: 1}, {n: 6}, {n: 5}];
    let sort = {n: -1};
    let key = Object.keys(sort)[0]; // "n"
    let val = sort[key]; // -1
    let type = getSortType(docs, key); // "[object Number]"
    mergeSort(docs, key, val, type); // [{n: 6}, {n: 5}, {n: 1}]
    

    Parameters

    • toSort: any[]

      array of documents to sort

    • sortField: string

      field name as string from documents

    • sortParam: number

      numeric -1 for descending and 1 for ascending sort order

    • type: any

      one of the results of Object.prototype.toString.call(obj[field])

    Returns any

rmObjDups

  • rmObjDups(arr: any[], field: string): any[]
  • Remove duplicate objects from array comparing certain unique field.

    Example:

    let a = [{_id: 1, name: "ch"}, {_id: 1, name: "ch"}]
    rmDups(a, "_id"); // [{_id: 1, name: "ch"}]
    

    Parameters

    • arr: any[]
    • field: string

    Returns any[]

Generated using TypeDoc