首页 > Windows开发 > 详细

[Node.js] Introduction to apiCheck.js

时间:2015-06-09 19:53:02      阅读:171      评论:0      收藏:0      [点我收藏+]

timeoutLog.js:

var apiCheckFactory = require(‘api-check‘);

var myCheck = apiCheckFactory();

module.exports = timeoutLog;

var api = [
  myCheck.number,
  myCheck.shape({
    name: myCheck.string
  }),
  myCheck.func.optional
];

function timeoutLog(time, person, callback) {
  myCheck.throw(api, arguments);

  setTimeout(function() {
    console.log(‘Time is up for ‘ + person.name + ‘!‘);
    callback && callback(person);
  }, time);
}

 

index.js:

// just giving me some space...
console.log(‘\n------\n‘);


var timeoutLog = require(‘./timeoutLog‘);

var person = {
  name: ‘Jane‘
};

timeoutLog(300, {name: ‘Joe‘}, function(thePerson) {
  console.log(
    ‘Person is the same? ‘ + (person === thePerson)
  );
});

 

Error message something like:

Error: apiCheck failed! `Argument 1` passed, `value` at `Argument 2` must be `String`

You passed:
[
  "wHY+jgNSE0HaoLsMgqkF4uGBX33bf6orJcLVGD0MdFx+tPoPnoJ9EreqOxuUixXoEOI2nGwJb8sXFAyrnXSjMpD98OVj0wg2menNJ65LzEtw3YYBsBZ4yzRtI6PD13zUy+R3S7WIhcWI30V+jZShvP5J2rm4=",
  true
]

With the types:
[
  "string",
  "boolean"
]

The API calls for:
[
  "String",
  "String"
]

 

[Node.js] Introduction to apiCheck.js

原文:http://www.cnblogs.com/Answer1215/p/4564106.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!