Skip to content

Instantly share code, notes, and snippets.

@wixo
Created November 13, 2015 20:21
Show Gist options
  • Save wixo/53265cfddc866ba6b180 to your computer and use it in GitHub Desktop.
Save wixo/53265cfddc866ba6b180 to your computer and use it in GitHub Desktop.
ContractorJS
var assert = require('assert');
var contractor = function ( options, contract ) {
var keys = Object.keys( contract );
if ( typeof options === 'object' ) {
keys.forEach( function ( key ) {
assert.equal( typeof options[key], contract[key] );
} );
} else {
throw new Error( 'options is not an object' );
}
};
var doSomething = function ( myAbstractObjAsArgument ) {
contractor( myAbstractObjAsArgument
, { response: 'object'
, fileName: 'string'
, language: 'string'
} );
console.log( 'ok' );
};
try {
doSomething( { response: { uno: 2 }, fileName: 'hola', language: 'ok' } );
} catch (e) {
console.error( 'error', e.message );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment