turbocommons-ts
Version:
General purpose library that implements frequently used and generic software development tasks
90 lines (89 loc) • 4.48 kB
TypeScript
/**
* TurboCommons is a general purpose and cross-language library that implements frequently used and generic software development tasks.
*
* Website : -> https://turboframework.org/en/libs/turbocommons
* License : -> Licensed under the Apache License, Version 2.0. You may not use this file except in compliance with the License.
* License Url : -> http://www.apache.org/licenses/LICENSE-2.0
* CopyRight : -> Copyright 2015 Edertone Advanded Solutions (08211 Castellar del Vallès, Barcelona). http://www.edertone.com
*/
/**
* Utilities to perform common object operations
*
* @class
*/
export declare class ObjectUtils {
/**
* Tells if the given value is an object or not
*
* @param value A value to check
*
* @returns true if the given value is an object, false otherwise
*/
static isObject(value: any): boolean;
/**
* Get the list of literals for a given object. Notice that only 1rst depth keys are providen
*
* @param object A valid object
*
* @returns List of strings with the first level object key names in the same order as defined on the object instance
*/
static getKeys(object: any): string[];
/**
* Check if two provided objects are identical.
* Notice that properties order does not alter the comparison. So if two objects
* have the same properties with exactly the same values, but they appear in a different
* order on both objects, this method will consider them as equal.
*
* @param object1 First object to compare
* @param object2 Second object to compare
*
* @returns true if objects are exactly the same, false if not
*/
static isEqualTo(object1: any, object2: any): boolean;
/**
* Check if the provided string is found inside the provided object structure.
* This method will recursively search inside all the provided object properties and test if the provided string is found.
* Search will be performed inside any object structures like arrays or other objects. Result will be positive even if
* any string on the object contains the searched text as a substring.
*
* @param object The object where the string will be looked for
* @param str The string that will be searched on the object
* @param caseSensitive True (default) to perform a case sensitive search, false otherwise
*
* @returns True if the string is found anywhere inside the provided object, false otherwise
*/
static isStringFound(object: any, str: string, caseSensitive?: boolean): boolean;
/**
* Combine a source object into a destination one by applying a deep merge.
* All properties from the source will be replaced into the destination object, without altering the
* destination properties that are not found on source.
*
* @param destination The object that will be overriden with the source one. The given instance will be permanently modified.
* @param source An object to merge into the destination one. This instance will not be modified
*
* @returns The destination object instance after being modified by merging the source object into it
*/
static merge(destination: any, source: any): any;
/**
* Perform a deep copy of the given object.
*
* @param object Any language instance like numbers, strings, arrays, objects, etc.. that we want to duplicate.
*
* @returns An exact independent copy of the received object, without any shared reference.
*/
static clone(object: any): any;
/**
* Apply a given function to each value of the provided object (Recursively through all the object elements). It will also scan
* inside arrays and sub objects.
*
* NOTICE: Original object is not modified
*
* @param object Any language instance like numbers, strings, arrays, objects, etc.. that we want to process.
* @param callableFunction A function that takes a single argument and returns a value. It must always return a value, cause
* it will be assigned to the original object
*
* @returns An exact independent copy of the received object, without any shared reference, where each value has been processed
* by the provided callable function.
*/
static apply(object: any, callableFunction: (v: any) => any): any;
}