blob: e87b6341b7cbf298321c344accd977b3102c7a2e [file] [log] [blame]
// @flow
// @credits https://gist.github.com/rogozhnikoff/a43cfed27c41e4e68cdc
export function findInArray(array: Array<any> | TouchList, callback: Function): any {
for (let i = 0, length = array.length; i < length; i++) {
if (callback.apply(callback, [array[i], i, array])) return array[i];
}
}
export function isFunction(func: any): boolean %checks {
// $FlowIgnore[method-unbinding]
return typeof func === 'function' || Object.prototype.toString.call(func) === '[object Function]';
}
export function isNum(num: any): boolean %checks {
return typeof num === 'number' && !isNaN(num);
}
export function int(a: string): number {
return parseInt(a, 10);
}
export function dontSetMe(props: Object, propName: string, componentName: string): ?Error {
if (props[propName]) {
return new Error(`Invalid prop ${propName} passed to ${componentName} - do not set this, set it on the child.`);
}
}