turbocommons-ts
Version:
General purpose library that implements frequently used and generic software development tasks
92 lines (91 loc) • 4.21 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 array operations
*/
export declare class ArrayUtils {
/**
* Tells if the given value is an array or not
*
* @param value A value to check
*
* @returns true if the given value is an array, false otherwise
*/
static isArray(value: any): boolean;
/**
* Check if two provided arrays are identical (have exactly the same elements and in the same order).
*
* @param array1 First array to compare
* @param array2 Second array to compare
*
* @returns true if arrays are exactly the same, false if not
*/
static isEqualTo(array1: any[], array2: any[]): boolean;
/**
* Check if the provided string is found inside the provided array structure.
* This method will recursively search inside all the provided array elements and test if the provided string is found.
* Search will be performed inside any array structures like arrays or other objects. Result will be positive even if
* any string on the array contains the searched text as a substring.
*
* @param array The array where the string will be looked for
* @param str The string that will be searched on the array
* @param caseSensitive True (default) to perform a case sensitive search, false otherwise
*
* @returns True if the string is found anywhere inside the provided array, false otherwise
*/
static isStringFound(array: any[], str: string, caseSensitive?: boolean): boolean;
/**
* Strictly check that the provided value is a non empty array or throw an exception
*
* @param value A value to check
* @param valueName The name of the value to be shown at the beginning of the exception message
* @param errorMessage The rest of the exception message
*
* @throws Error If the check fails
*
* @return void
*/
static forceNonEmptyArray(value: any, valueName?: string, errorMessage?: string): void;
/**
* Remove the specified item from an array
*
* @param array An array (it will not be modified by this method)
* @param element The element that must be removed from the given array
*
* @returns The provided array but without the specified element (if found). Note that originally received array is not modified by this method
*/
static removeElement(array: any[], element: any): any[];
/**
* remove all the duplicate values on the provided array
* Duplicate values with different data types won't be considered as equal ('1', 1 will not be removed)
*
* @param array An array with possible duplicate values
*
* @return The same provided array but without duplicate elements
*/
static removeDuplicateElements(array: any[]): any[];
/**
* Check if the given array contains duplicate values or not.
* Duplicate values with different data types won't be considered as equal ('1', 1 will return false)
*
* @param array An array containing some elements to test
*
* @return True if there are duplicate values, false otherwise
*/
static hasDuplicateElements(array: any[]): boolean;
/**
* Get all the duplicate values on the provided array
* Duplicate values with different data types won't be considered as equal ('1', 1 will return false)
*
* @param array An array containing some elements to test
*
* @return list with all the elements that are duplicated on the provided array
*/
static getDuplicateElements(array: any[]): any[];
}