diff --git a/lib/is.js b/lib/is.js index fdb41e8..ea55a2d 100644 --- a/lib/is.js +++ b/lib/is.js @@ -631,6 +631,51 @@ } ) + + // + // __is.conforms( object , schema , [strict=false] )__ + // + + util.addPredicate( 'conforms' , function isConforms( object , schema , strict ) { + + var key + var keys + var index + var length + + if ( is.not.object( object ) ) { + throw new TypeError( 'expected `object` to be an object, got "' + getTag( object ) + '"' ) + } + + if ( is.not.object( schema ) ) { + throw new TypeError( 'expected `schema` to be an object, got "' + getTag( schema ) + '"' ) + } + + keys = ownKeys( schema ) + length = keys.length + + if ( strict && length !== ownKeys( object ).length ) { + return false + } + + for ( index = 0 ; index < length ; index += 1 ) { + + key = keys[ index ] + + if ( typeof schema[ key ] !== 'function' ) { + continue + } + + if ( !schema[ key ]( object[ key ] , key , object ) ) { + return false + } + + } + + return true + + } ) + } )