Created
February 5, 2017 05:23
-
-
Save brianleroux/5054192ba3082ef6cc1b9265ed3b724a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require('@smallwins/validate/assert') | |
function add(params) { | |
assert(params, { | |
'a': Number, | |
'b': Number, | |
}) | |
return params.a + params.b | |
} | |
add({a:1, b:2}) | |
add({a:'1', b:2}) | |
/* logs: | |
TypeError: expected Number but received String "1" for params.a | |
at TypeError (native) | |
at /Users/brianleroux/Repo/33ed82ee20aa0f4b11d630a9d423b2df/node_modules/@smallwins/validate/assert.js:47:13 | |
at Array.forEach (native) | |
at assert (/Users/brianleroux/Repo/33ed82ee20aa0f4b11d630a9d423b2df/node_modules/@smallwins/validate/assert.js:36:23) | |
at add (/Users/brianleroux/Repo/33ed82ee20aa0f4b11d630a9d423b2df/smallwins-add.js:4:3) | |
at Object.<anonymous> (/Users/brianleroux/Repo/33ed82ee20aa0f4b11d630a9d423b2df/smallwins-add.js:13:1) | |
at Module._compile (module.js:409:26) | |
at Object.Module._extensions..js (module.js:416:10) | |
at Module.load (module.js:343:32) | |
at Function.Module._load (module.js:300:12) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment