mirror of https://github.com/lukechilds/ow.git
Sam Verschueren
7 years ago
committed by
Sindre Sorhus
3 changed files with 50 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||
|
import is from '@sindresorhus/is'; |
||||
|
import ow from '../..'; |
||||
|
import {Predicate} from '../predicates/predicate'; |
||||
|
|
||||
|
const ofTypeDeep = (input: any, predicate: Predicate): boolean => { |
||||
|
if (!is.plainObject(input)) { |
||||
|
ow(input, predicate); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
return Object.keys(input).every(key => ofTypeDeep(input[key], predicate)); |
||||
|
}; |
||||
|
|
||||
|
/** |
||||
|
* Test all the values in the object against a provided predicate. |
||||
|
* |
||||
|
* @hidden |
||||
|
* @param input Input object |
||||
|
* @param predicate Predicate to test every value in the input object against. |
||||
|
*/ |
||||
|
export default (input: any, predicate: Predicate): boolean | string => { |
||||
|
try { |
||||
|
return ofTypeDeep(input, predicate); |
||||
|
} catch (err) { |
||||
|
return err.message; |
||||
|
} |
||||
|
}; |
Loading…
Reference in new issue