/** * Filter function but instead of returning the element, the function returns the * indexes of each element. * * @param array The array on which the filter function is going to run. * @param predicate The function to apply to each element. The function is called with * the element, the index, and the whole array. * @return An array of indexes */ export function filterIndexes(array: any[], predicate: (elt: any, idx: number, array: any[]) => boolean): number[] { const indexes: number[] = []; array.forEach((elt: any, idx: number) => { if (predicate(elt, idx, array)) { indexes.push(idx); } }); return indexes; } /** * Trim the value if the value is of type string * @param value The value to be trimmed (or not) * @return The trimmed value */ export function smartTrim(value: any): any { if (typeof value === 'string') { return value.trim(); } return value; }