How to use the is2.obj function in is2

To help you get started, we’ve selected a few is2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stdarg / tcp-port-used / index.js View on Github external
function waitUntilUsed(port, retryTimeMs, timeOutMs) {

    // the first arument may be an object, if it is not, make an object
    var opts;
    if (is.obj(port)) {
        opts = port;
        opts.host = '127.0.0.1';
        opts.inUse = true;
    } else {
        opts = makeOptionsObj(port, '127.0.0.1', true, retryTimeMs, timeOutMs);
    }

    return waitUntilUsedOnHost(opts);
}
github stdarg / udp-discovery / index.js View on Github external
function Discovery(options) {
    var self = this;

    if (options && !is.obj(options))
        debug('Dicovery constructor bad options argument: '+inspect(options));

    // Create a dgram socket and bind it
    self.dgramType = (options && options.dgramType) ?
                      options.dgramType.toLowerCase() : DEFAULT_DGRAM_TYPE;
    self.reuseaddr = (options && options.reuseaddr) ? options.reuseaddr : DEFAULT_REUSE_ADDR;
    self.socket = dgram.createSocket({type: self.dgramType, reuseAddr: self.reuseaddr});
    self.port = (options && options.port) ? options.port : DEFAULT_UDP_PORT;
    self.bindAddr = (options && options.bindAddr) ? options.bindAddr :
                     undefined;
    self.socket.bind(self.port, self.bindAddr);

    // create an interval task to check for announcements that have timed out
    self.timeOutInt = (options && options.timeOutInt) ? options.timeOutInt :
                                        DEFAULT_TIMEOUT;
    self.timeOutId = setInterval(function() { self.handleTimeOut(); },
github strongloop / supercluster / lib / Worker.js View on Github external
self.RestApi.addRoute('post', '/addTask', function(req, res, taskInfo) {
    if (!is.obj(taskInfo) || !is.obj(taskInfo.master)) {
      debug('self.RestApi.addRoute received bad taskInfo:', taskInfo);
      return;
    }

    // send reply to client - we got the task - the rest of the work will be
    // done asynchronously from here. We'll tell the client how it went via
    // a REST call.
    res.json({success:true});

    // create easy to use return address
    var address = req.socket.address().address + ':' +
      taskInfo.master.restApiPort;

    // process the task on the next tick
    process.nextTick(function() {
      if (is.obj(taskInfo) && is.obj(taskInfo.master) &&
github stdarg / tcp-port-used / index.js View on Github external
function waitForStatus(port, host, inUse, retryTimeMs, timeOutMs) {

    var deferred = getDeferred();
    var timeoutId;
    var timedout = false;
    var retryId;

    // the first arument may be an object, if it is not, make an object
    var opts;
    if (is.obj(port)) {
        opts = port;
    } else {
        opts = makeOptionsObj(port, host, inUse, retryTimeMs, timeOutMs);
    }

    //debug('opts:'+util.inspect(opts);

    if (!is.bool(opts.inUse)) {
        deferred.reject(new Error('inUse must be a boolean'));
        return deferred.promise;
    }

    if (!is.positiveInt(opts.retryTimeMs)) {
        opts.retryTimeMs = RETRYTIME;
        debug('set retryTime to default '+RETRYTIME+'ms');
    }
github stdarg / tcp-port-used / index.js View on Github external
function waitUntilFreeOnHost(port, host, retryTimeMs, timeOutMs) {

    // the first arument may be an object, if it is not, make an object
    var opts;
    if (is.obj(port)) {
        opts = port;
        opts.inUse = false;
    } else {
        opts = makeOptionsObj(port, host, false, retryTimeMs, timeOutMs);
    }

    return waitForStatus(opts);
}
github strongloop / supercluster / lib / Worker.js View on Github external
process.nextTick(function() {
      if (is.obj(taskInfo) && is.obj(taskInfo.master) &&
          is.obj(taskInfo.task) && is.nonEmptyStr(taskInfo.task.type)) {
        self.emit('taskReceived', taskInfo.master, taskInfo.task);
        self.doTask(taskInfo, address);
      } else {
        debug('/addTask bad taskInfo:',taskInfo);
      }
    });
  });
github strongloop / supercluster / lib / Worker.js View on Github external
Worker.prototype.doTask = function(taskInfo, address) {

  debug('Worker.doTask taskInfo: '+inspect(taskInfo));
  var self = this;
  var cbFunc = function(err, result) {
    debug('cbFunc result: '+inspect(result));
    self.taskReply(err, taskInfo, address, result);
  };

  if (!is.obj(taskInfo) || !is.obj(taskInfo.task) ||
      !is.nonEmptyStr(taskInfo.task.type)) {
    debug('Bad task Info received in Worker.doTask: '+inspect(taskInfo));
    return;
  }

  switch(taskInfo.task.type) {
  case 'function':
    self.runFunc(taskInfo.task, cbFunc);
    break;
  case 'file':
    self.runFile(taskInfo.task, cbFunc);
    break;
  case 'github':
    self.runGithub(taskInfo.task, cbFunc);
    break;
  default:
github strongloop / supercluster / lib / Master.js View on Github external
process.nextTick(function() {
    if (is.func(task)) {
      self.sendFuncToWorker(worker, task, args, cb);
    } else if (is.obj(task)) {
      switch(task.type) {
      case 'github':
        self.sendGithubToWorker(worker, task, cb);
        break;
      case 'file':
        self.sendFileToWorker(worker, task, cb);
        break;
      default:
        debug('Unknown task.type in task: '+inspect(task));
        cb(new Error('Unknown task.type in task: '+inspect(task)));
        break;
      }
    }
  });
};

is2

A type checking library where each exported function returns either true or false and does not throw. Also added tests.

MIT
Latest version published 2 years ago

Package Health Score

68 / 100
Full package analysis