Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
added is.conforms, without docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mov37 committed Jun 6, 2016
1 parent e2de554 commit 4bc12e3
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions lib/is.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

} )

} )


Expand Down

0 comments on commit 4bc12e3

Please sign in to comment.