码迷,mamicode.com
首页 > Windows程序 > 详细

[Node.js] Introduction to apiCheck.js

时间:2015-06-09 19:54:18      阅读:122      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!