-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathshims.js
26 lines (22 loc) · 914 Bytes
/
shims.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// @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.`);
}
}