How to use the is2.nonEmptyObj 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 strongloop / supercluster / lib / Master.js View on Github external
Master.prototype.taskWorker = function(worker, task, args, cb) {
  var self = this;

  if (!is.func(task) && !is.obj(task))
    return asyncerr(new Error('Bad task object: '+inspect(task)),cb);

  if (!is.nonEmptyObj(worker))
    return asyncerr(new Error('Bad parameter for worker: '+
                              inspect(worker)), cb);

  if (!is.func(cb))
    debug('Master.taskAll received no callback function.');

  // args is an optional argument and may not be present
  if (is.func(args)) {
    cb = args;
  } else if (is.array(args)) {
    if (is.obj(task) && !task.args) {
      task.args = args;
      args = undefined;
    }
  }
github stdarg / udp-discovery / index.js View on Github external
Discovery.prototype.pause = function(name) {
    // we have to have a name that is string and not empty
    if (!is.nonEmptyStr(name)) {
        debug('stopAnouncement: bad name param: '+inspect(name));
        return false;
    }

    if (!is.nonEmptyObj(this.services)) {
        debug('stopAnnounce: There are no services to stop');
        return false;
    }

    // the service has to be already known to stop announcing
    if (!this.services[name]) {
        debug('Discovery.stopAnnounce error: no entry for \''+name+'\'');
        return false;
    }

    // if there is no task to do the announcing, quit
    if (!this.services[name].intervalId) {
        debug('Discovery.stopAnnounce error: not announcing \''+name+'\'');
        return false;
    }
github stdarg / udp-discovery / index.js View on Github external
Discovery.prototype.sendAnnounce = function(data) {
    if (!is.nonEmptyObj(data)) {
        debug('sendAnnounce has a bad param for data: '+inspect(data));
        return false;
    }

    var copy = objToJson.copyObj(data);
    delete copy.lastAnnTm;
    delete copy.intervalId;

    var str = objToJson.jsonStringify(copy);
    if (!str) {
        debug('objToJson.jsonStringify failed on serice data: '+inspect(data));
        return;
    }

    // send the stringified buffer over multicast
    var buf = new Buffer(str);
github stdarg / udp-discovery / index.js View on Github external
Discovery.prototype.handleAnnouncement = function(ann, rinfo) {
    // ensure the ann is an object that is not empty
    if (!is.nonEmptyObj(ann)) {
        debug('handleAnnouncement bad ann: '+inspect(ann));
        return false;
    }

    // also, the ann obj needs a name
    if (!ann.name) {
        debug('handleAnnouncement error: no name.');
        return false;
    }

    // The entry exists, update it
    if (this.services && this.services[ann.name]) {
        this.services[ann.name].lastAnnTm = Date.now();
        return this.updateExisting(ann.name, ann.data, ann.interval,
                                   ann.available,
                                  rinfo);
github strongloop / supercluster / lib / Worker.js View on Github external
Worker.prototype.runGithub = function(task, cb) {
  if (!is.nonEmptyObj(task))
    return asyncerr(new Error('No task received.'), cb);

  if (!is.str(task.user))
    return asyncerr(new Error('Task has no user: '+ inspect(task)), cb);

  if (!is.str(task.repo))
    return asyncerr(new Error('Task has no repo: '+ inspect(task)), cb);

  if (!is.str(task.dir))
    return asyncerr(new Error('Task has no dir: '+ inspect(task)), cb);

  if (!is.obj(task.cmds))
    return asyncerr(new Error('Task has no cmds: '+inspect(task)), cb);

  // get the dir and make the directory
  var dir = path.dirname(task.fileName);

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