How to use is2 - 10 common examples

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 / udp-discovery / index.js View on Github external
debug('addNew for \''+name+'\', but it already exists.');
        return false;
    }

    self.services[name] = {};
    self.services[name].name = name;
    self.services[name].interval = interval;
    self.services[name].data = userData;
    self.services[name].available = available;
    //self.services[name].announce = announce;
    // if local is true, the service is local to this process.
    self.services[name].local = announce;

    // if there is an rinfo, copy it and place it on the service
    // we don't need the size parameter, though.
    if (is.obj(rinfo) && is.nonEmptyStr(rinfo.address))
        self.services[name].addr = rinfo.address;

    // set the name property to be read-only - it would be confusing if it
    // changed as it is also the key.
    Object.defineProperty(self.services[name], 'name', {
        value: name,
        writable: false,
        enumerable: true,
        configurable: true
    });

    // since it's new - send an event
    var evName = available ? 'available' : 'unavailable';
    self.emit(evName, name, self.services[name], 'new');

    // update the lanst announcement time to now
github stdarg / udp-discovery / index.js View on Github external
Discovery.prototype.updateExisting = function(name, data, interval, available,
                                              rinfo) {
    // this is an existing entry
    var oldAvail = this.services[name].available;
    // update the lanst announcement time to now
    this.services[name].interval = interval;
    this.services[name].data = data;

    // if there is an rinfo, copy it and place it on the service
    // we don't need the size parameter, though.
    if (is.obj(rinfo) && is.str(rinfo.address) && !this.services[name].addr)
        this.services[name].addr = rinfo.address;

    // if the availability changed, send an event
    if (available !== oldAvail) {
        this.services[name].available = available;
        var evName = available ? 'available' : 'unavailable';
        this.emit(evName, name, this.services[name], 'availabilityChange');
    }

    return true;
};
github stdarg / config-js / index.js View on Github external
if (!isValid && typeof defaultValue === 'undefined' && !fromEnv) {
        debug('Var statuses ','!isValid',!isValid,'typeof defaultValue',
              typeof defaultValue, '!fromEnv',!fromEnv);
        throw new Error('No config value found for: '+propertyName);
    }

    // either return found value or default
    if (!fromEnv) {
        debug('Propery '+envPropName+' gotten from config file: ',(isValid ? currVal : defaultValue));
        return isValid ? currVal : defaultValue;
    } else {
        debug('Attempting to coercion checks.');
        if (is.num(currVal)) {
            debug('Coercing env '+envPropName+' to a numeric.');
            return Number(envStr);
        } else if (is.array(currVal)) {
            debug('Coercing env '+envPropName+' to an array.');
            if (/^\[(.)*\]$/.match(envStr)) {
                envStr = envStr.substr(1);  // remove '['
                envStr = envStr.substring(0, envStr.length-1);
                var elems = envStr.split(',');
                for (var i=0; i
github stdarg / config-js / index.js View on Github external
var isValid = ('undefined'!==typeof currVal && null!==currVal);

    // invalid value found and no default value, then we throw an error
    if (!isValid && typeof defaultValue === 'undefined' && !fromEnv) {
        debug('Var statuses ','!isValid',!isValid,'typeof defaultValue',
              typeof defaultValue, '!fromEnv',!fromEnv);
        throw new Error('No config value found for: '+propertyName);
    }

    // either return found value or default
    if (!fromEnv) {
        debug('Propery '+envPropName+' gotten from config file: ',(isValid ? currVal : defaultValue));
        return isValid ? currVal : defaultValue;
    } else {
        debug('Attempting to coercion checks.');
        if (is.num(currVal)) {
            debug('Coercing env '+envPropName+' to a numeric.');
            return Number(envStr);
        } else if (is.array(currVal)) {
            debug('Coercing env '+envPropName+' to an array.');
            if (/^\[(.)*\]$/.match(envStr)) {
                envStr = envStr.substr(1);  // remove '['
                envStr = envStr.substring(0, envStr.length-1);
                var elems = envStr.split(',');
                for (var i=0; i
github stdarg / config-js / index.js View on Github external
// if the path has '##' and process.env.NODE_ENV is a non-empty string,
    // replace '##' with the contents of process.env.NODE_ENV
    var pathToConfigFile = pathToConfigFileIn;
    var idx = pathToConfigFileIn.indexOf('##');
    if (idx > -1 && is.nonEmptyStr(process.env.NODE_ENV)) {
        pathToConfigFile = pathToConfigFileIn.substr(0, idx) +
            process.env.NODE_ENV + pathToConfigFileIn.substr(idx+2);
    }

    // complimentary to have arg checking
    if (!is.nonEmptyStr(pathToConfigFile))
        throw new Error('Bad path to config file: '+pathToConfigFile);
    if (!fs.existsSync(pathToConfigFile))
        throw new Error('Config file is missing: '+pathToConfigFile);
    if (is.defined(region))  assert.ok(is.nonEmptyStr(region));

    // english is the default
    if (is.undefined(region)) region = 'en';

    debug('## sub: pathToConfigFileIn: '+pathToConfigFileIn);
    this.pathToDefaults = path.join(path.dirname(pathToConfigFileIn),
                                    'defaults.js');
    this.pathToConfigFile = pathToConfigFile;
    debug('region: '+region);
    this.region = region;
    var self = this;
    debug('pathToDeafults: '+this.pathToDefaults);

    // set a watch for when the file changes, to reload the file.
    fs.watchFile(this.pathToConfigFile, {persistent: false}, function () {
        self.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
github strongloop / supercluster / lib / WorkerRunCommon.js View on Github external
var iterator = function(cmd, cb) {
    // default directorry is the cwd
    if (!is.nonEmptyStr(cmd.dir))  cmd.dir = dir;

    var output = ({stdout:'', stderr:''});
    if (!is.nonEmptyStr(cmd.cmd) || !is.array(cmd.args))
      return debug('Bad command '+inspect(cmd));

    exports.runCmd(cmd.cmd, cmd.args, cmd.dir, output,
    function(err, output, code) {
      if (err) {
        debug(inspect(err.message));
        return cb(err);
      }
      codes.push(code);
      outputs.push(output);
      cb(null);
    });
  };
github stdarg / udp-discovery / index.js View on Github external
Discovery.prototype.sendEventTo = function(dest, eventName, data) {
    if (!is.nonEmptyStr(dest) && !is.nonEmptyArray(dest) &&
        !is.function(dest)) {
        debug('Discovery.sendEventTo received bad dest parameter: '+
              inspect(dest));
        return false;
    }

    if (!is.nonEmptyStr(eventName)) {
        debug('Discovery.sendEventTo received bad name parameter: '+
              inspect(eventName));
        return false;
    }

    var i;
    // handle the case where dest is a service name
    if (is.nonEmptyStr(dest)) {
        this.sendEventToService(dest, eventName, data);
github strongloop / supercluster / lib / WorkerRunGithub.js View on Github external
exports.gitClone = function(task, targetDir, cb) {

  if (!is.obj(task) || !is.nonEmptyStr(task.user) || !is.nonEmptyStr(task.repo))
    return cb(new Error('Error bad task object: '+inspect(task)));

  if (!is.func(cb))
    return cb(new Error('Bad cb parameter: '+inspect(cb)));

  // assume, if the target directory is present, it was installed.
  // FIXME: This is kinda dumb.
  if (fs.existsSync(targetDir))
    return cb();

  debug('gitClone task: '+inspect(task));
  var url = 'https://github.com/' + task.user + '/' + task.repo;
  debug('gitClone url: '+url);
  exec(['git', 'clone', url], function(err, out, code) {
    if (err) {
      debug('runGithub git clone error: '+inspect(err));
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(); },

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