zoukankan      html  css  js  c++  java
  • [Node.js] Introduction to apiCheck.js

    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('
    ------
    ');
    
    
    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"
    ]
  • 相关阅读:
    通知协议KVO的用法
    UIImageView用法
    默默的学习!
    多输入参数的方法
    一本书的摘录
    实例、局部、静态变量(java)
    分数相加的例题
    类的继承
    多线程
    单例
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4564106.html
Copyright © 2011-2022 走看看