Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Lang Functions

  • isEqual(value: any, other: any): boolean
  • Performs a deep comparison between two values to determine if they are equivalent.

    Note: This method supports comparing arrays, array buffers, booleans, date objects, error objects, maps, numbers, Object objects, regexes, sets, strings, symbols, and typed arrays. Object objects are compared by their own, not inherited, enumerable properties. Functions and DOM nodes are not supported.

    example

    var object = { 'user': 'fred' }; var other = { 'user': 'fred' };

    _.isEqual(object, other); // => true

    object === other; // => false

    Parameters

    • value: any

      The value to compare.

    • other: any

      The other value to compare.

    Returns boolean

    Returns true if the values are equivalent, else false.

Other Functions

  • cloneDeep<T>(value: T): T
  • This method is like _.clone except that it recursively clones value.

    Type Parameters

    • T

    Parameters

    • value: T

      The value to recursively clone.

    Returns T

    Returns the deep cloned value.

  • debounce(func: GenericFunction, delay?: number): ((...args: GenericArguments) => void)
  • This method is used to forcefully delay a function and cancel all intermediate redundant calls made within the span of delay. Returns a method that will debounce by expected delay when called.

    example
    export function Input() {
    const [ query, setQuery ] = useState('');
    const [ result, setResult ] = useState([]);

    const searchQuery = async (val) => {
    const resp = await searchApi(val);
    setResult(resp.data);
    }

    const debouncedSearchQuery = debounce(searchQuery, 500);

    const onQueryInput = (event) => {
    setQuery(event.target.value);
    debouncedSearchQuery();
    }

    return (
    <input
    {...props}
    onChange={onQueryInput}
    />
    )
    }

    // This will result in searchQuery method to be delayed by 500ms.
    // If the user continues to input query within span of 500ms. Then all redundant calls will cancelled.

    // Without debounce => 'abcde' => 5 calls individually for a, ab, abc, abcd, abcde
    // With debounce => 'abcde' => 1 call for abcde

    Parameters

    • func: GenericFunction

      Method that needs to be debounced

    • delay: number = 200

      Amount of delay in miliseconds

    Returns ((...args: GenericArguments) => void)

      • (...args: GenericArguments): void
      • Parameters

        • Rest ...args: GenericArguments

        Returns void

  • downloadFile(downloadConfig: { downloadMethod: string; file: null | File; fileExtension: string; fileName: string; fileUrl: null | string; type: string }): void
  • This function can download a file on user's machine either directly by a url or a blob object.

    remarks

    Please ensure you are passing the appropriate downloadMethod type -

    'url' method expects the fileUrl argument

    'blob' expects the file argument


    downloadConfig properties

    • file => BlobObject or null. Required if downloadMethod is 'blob'
    • type => MIME-TYPE of the file. 'application/pdf', 'application/gzip', 'image/png'
    • fileName => Expected name of the downloaded file
    • downloadMethod => 'blob' or 'url'
    • fileExtension => Expected extension of the downloaded file
    • fileUrl => downloadable file's url. Required if downloadMethod is 'url'
    example
    downloadFile({
    file: fileBlobObject,
    type: 'application/pdf',
    fileName: 'MyFile',
    fileExtension: 'pdf',
    downloadMethod: 'blob',
    fileUrl: null
    }) // *Downloads file of type PDF on the client's machine named MyFile.pdf*

    Parameters

    • downloadConfig: { downloadMethod: string; file: null | File; fileExtension: string; fileName: string; fileUrl: null | string; type: string }
      • downloadMethod: string
      • file: null | File
      • fileExtension: string
      • fileName: string
      • fileUrl: null | string
      • type: string

    Returns void

  • getData(obj: any, path: string, def?: unknown): any
  • getFilledArray(arraySize: number, value: string | number): any[]
  • This method returns an array of given size filled with provided value

    example
    getFilledArray(4,'hello') // ['hello', 'hello', 'hello', 'hello']
    

    Parameters

    • arraySize: number

      Size of the array i.e number of elements in the array

    • value: string | number

      Value that you want to fill in the array

    Returns any[]

  • getIndexByMatchingObjectValue<MatchValueType>(searchArr: MultiLevelObject[], matchKey: string, matchValue: MatchValueType): number
  • This method searches for an object inside an array of objects based on the object key and expected value then returns its index. Returns -1 if key not found.

    remarks

    Please ensure not to send chained keys as matchKey.
    'key' | 'name' => Correct
    'key.name[0]' | 'address.pincode' => Incorrect
    example
    const dummy = [ { rollNo: 1 }, { rollNo: 2 }, { rollNo: 3 }, { rollNo: 4 } ];

    getIndexByMatchingObjectValue<number>(dummy, 'rollNo', 4); // 3
    getIndexByMatchingObjectValue<number>(dummy, 'rollNo', 3); // 2
    getIndexByMatchingObjectValue<number>(dummy, 'rollNo', 6); // -1

    getIndexByMatchingObjectValue<number>(dummy, 'address', 6); // -1
    getIndexByMatchingObjectValue<number>(dummy, 'address.pincode', 6); // -1

    Type Parameters

    • MatchValueType

    Parameters

    • searchArr: MultiLevelObject[]

      Array of objects to search within

    • matchKey: string

      Key of the object to be matched

    • matchValue: MatchValueType

      Expected value to be matched

    Returns number

  • getObjectEntries(obj: any): any[][]
  • This method is used to parse an object into entries. Works exactly like Object.entries. Object.entries is still not fully supported so consider this a polyfill for the same.

    { key1: value1, key2: value2 } => [ [ key1, value1 ], [ key2, value2 ] ]

    example
    const dummy1 = { key1: value1, key2: value2, key3: value3 };
    const dummy2 = { key1: 'value1', key2: 'value2', key3: [ 1, 2, 3 ], key4: { a: 1, b: 2 } }

    getObjectEntries(dummy1) // [ [ key1, value1 ], [ key2, value2 ], [ key3, value3 ] ];
    getObjectEntries(dummy2) // [ [ key1, value1 ], [ key2, value2 ], [ key3 , [ 1, 2, 3 ] ],[ key4,{ a:1, b:2 } ] ];

    Parameters

    • obj: any

      Object to be parsed into entries.

    Returns any[][]

  • getPathVariableFromUrlIndex(url: string, indexFromLast?: number): undefined | string
  • This method returns the path from the url. By default it returns the last path i.e last slash part from the URL. If you want you can get any path from URL by passing index from last value param

    example
    getPathVariableFromUrlIndex('https://groww.in/mutual-funds/user/explore')       //explore
    getPathVariableFromUrlIndex('https://groww.in/mutual-funds/user/explore', 2) //mutual-funds

    Parameters

    • url: string

      The url that is entered

    • indexFromLast: number = 0

      The index from last slash in the URL. By default it is the last index.

    Returns undefined | string

  • getSelectedTabIndex(tabs: TabsData[], selectedTabName: string): number
  • This method returns the index of the selected tab

    remarks

    Please ensure that tab object has searchId key to facilitate matching process

    example
    getSelectedTabIndex(tabsArrayOfObject,'mutual-funds') // 1
    

    Parameters

    • tabs: TabsData[]

      Array of tabs object

    • selectedTabName: string

      Selected tab name

    Returns number

  • isEmpty(data: any): boolean
  • This method can be used to check if the variable is empty or not. Returns true if it is empty else false.

    example
    if(isEmpty(userData)) {
    return;
    }

    Parameters

    • data: any

      Any variable that you want to check if it is empty or not

    Returns boolean

  • omit(object: null | MultiLevelObject, props: string[]): MultiLevelObject | null
  • Returns new object with copied all properties without the ones specified.

    example

    omit({ name: 'Jack', age: 69, title: 'Mr' }, ['age', 'title']); // { name: 'Jack' }

    Parameters

    • object: null | MultiLevelObject

      source object

    • props: string[]

      properties to omit

    Returns MultiLevelObject | null

    • new object without given properties
  • remove<T>(array: T[], predicate: ((elem: T, index: number, list: T[]) => boolean)): T[]
  • Removes values from array using function as predicate. Returns removed values.

    example
    const arr = [ 1, 2, 3, 4, 5, 6 ];

    const freshArr = remove(arr, (elem) => {
    return !!(elem % 2)
    })

    // Predicate returned true for every odd value and false for every even value.
    // For the ones predicate returned true, were deleted from the array. Removed values were returned.

    // arr = [ 2, 4, 6 ];
    // freshArr = [ 1, 3, 5 ];

    Type Parameters

    • T

    Parameters

    • array: T[]
    • predicate: ((elem: T, index: number, list: T[]) => boolean)
        • (elem: T, index: number, list: T[]): boolean
        • Parameters

          • elem: T
          • index: number
          • list: T[]

          Returns boolean

    Returns T[]

  • sortObjectByValue(obj: SingleLevelObject, isDescending?: boolean): SingleLevelObject
  • This method sorts an Object with key value pairs on the basis of the values. (Check examples for better understanding)

    remarks

    Object should be of a single level. Avoid nested objects or arrays. In case of error, method returns the original object.

    example
    const list = { yellow: 1, blue: 10, red: 5, green: 6, pink: 8 };
    const listWrong = { yellow: 1, blue: [ 'I', 'am', 'blue' ], red: 5, green: { i: 'i', am: 'am', green: 'green' }, pink: 8 };

    sortObjectByValue(list, true); // { blue: 10, pink: 8, green: 6, red: 5, yellow: 1 }
    sortObjectByValue(list); // { yellow: 1, red: 5, green: 6, pink: 8, blue: 10 }

    sortObjectByValue(listWrong);
    // console => Error in sorting object, original object returned : ErrorObject
    // { yellow: 1, blue: [ 'I', 'am', 'blue' ], red: 5, green: { i: 'i', am: 'am', green: 'green' }, pink: 8 }

    Parameters

    • obj: SingleLevelObject

      Object with key value pairs with single level hierarchy. (Read remarks)

    • Optional isDescending: boolean

      Sort in descending order or not. Defaults to false. Optional argument.

    Returns SingleLevelObject

  • uniqBy(arr: GenericFunction, iteratee: GenericFunction): any[]
  • This method is like uniq except that it accepts iteratee which is invoked for each element in array to generate the criterion by which uniqueness is computed. The order of result values is determined by the order they occur in the array. The iteratee is invoked with one argument: (value).

    example
    const arr = [ 12, undefined, { id: 1, name: 'bob' }, null,  { id: 1, name: 'bill' }, null, undefined ];

    uniqBy(arr, 'name'); // [ { id: 1, name: 'bob' }, { id: 1, name: 'bill' }]

    Parameters

    • arr: GenericFunction

      The array to inspect

    • iteratee: GenericFunction

      The iteratee invoked per element.

    Returns any[]

Generated using TypeDoc