Example #1
0
function isAttributableSecretShare(x) {
    return x && 
        _.isString(x.uuid) && 
        _.isString(x.content) && 
        _.isString(x.name) && 
        _.isString(x.secretUuid) && 
        _.isString(x.secretName) && 
        _.isInteger(x.secretNumberOfShares) && 
        _.isInteger(x.secretThreshold);
}
Example #2
0
const getBetIndex = function (homeScore, awayScore) {
    if(_.isInteger(homeScore) && _.isInteger(awayScore)) {
        if(homeScore === awayScore) {
            return 0;
        } else {
            return homeScore > awayScore ? 1 : 2;
        }
    }

    return null;
};
Example #3
0
  one: function(x, y) {
    x = _.isInteger(x) ? x : 0
    y = _.isInteger(y) ? y : x

    return {
      x: x,
      y: y,
      data: _.map(_.range(x), function (num) {
        return _.range(y)
      })
    }
  },
  function(id, name, capacity, timeslotData) {
    if ((_.isInteger(id)) && (_.gt(id, 0))) {
      this._id = id;
    } else {
      throw new Errors.TypeError("ID must be a positive integer");
    }

    if ((_.isString(name)) && !(_.isEmpty(name))) {
      this.name = name;
    } else {
      throw new Errors.TypeError("A non-blank name must be provided");
    }
    if ((_.isInteger(capacity)) && (_.gt(capacity, 0))) {
      this.capacity = capacity;
    } else {
      throw new Errors.TypeError("Capacity must be a positive integer");
    }

    this.studentList = new Set(null, function(a, b) {
      return a.name === b.name;
    }, function(object) {
      return object.name;
    });

    this.timeslots = new SortedSet(null, function(a, b) {
      return a.value == b.value;
    }, function(a, b) {
      if (a.value > b.value) {
        return 1;
      } else if (a.value == b.value) {
        return 0;
      } else {
        return -1;
      }
    });

    var ucThis = this; // Hold on to 'this' reference for callback function
    if (!_.isUndefined(timeslotData)) {
      if (timeslotData instanceof Array) {
        _.forEach(timeslotData, function(ts) {
          ucThis.addTimeslot(ts);
        });
      } else if (_.values(Timeslots).indexOf(timeslotData) >= 0) {
        this.addTimeslot(timeslotData);
      } else {
        throw new Errors.TypeError("Timeslots passed in must be a single instance or an array of Timeslot objects");
      }
    }
  },
Example #5
0
/**
 * Given an input the function will return an number.
 *
 * @param {object} input - The input to be converted.
 *
 * @returns {number} - The converted result.
 */
export default function toInteger(input) {
    if (isInteger(input)) {
        return input;
    }

    return parseInt(input, 10);
}
var defaultParserSizeLimit = 4096000; // 4MB (same as DataPower's default)
/**
 * Return the payload parser size limit in bytes.
 * If user doesn't configure the size, default value, 4MB, will be returned.
 *
 */
function getParserSizeLimit() {
  var projectInfo = project.inspectPath(process.env.CONFIG_DIR || process.cwd());

  var config = apicConfig.loadConfig({
    projectDir: projectInfo.basePath,
    shouldParseUris: false });

  var sizeLimit;

  [ apicConfig.PROJECT_STORE, apicConfig.USER_STORE ].some(function(location) {
    var obj = config.get('parserSizeLimit', location);
    if (obj.parserSizeLimit && _.isInteger(parseInt(obj.parserSizeLimit, 10))) {
      sizeLimit = obj.parserSizeLimit;
      logger.debug('set parserSizeLimit to %d bytes', sizeLimit);
      return true;
    }
  });

  if (!_.isInteger(sizeLimit)) {
    sizeLimit = defaultParserSizeLimit;
    logger.debug('set parserSizeLimit to default %d bytes', sizeLimit);
  }

  return sizeLimit;
}
Example #7
0
const setPort = (port) => {
  if (!_.isInteger(port) || port < 1 || port > MAX_PORT_NUMBER) {
    throw new Error('port must be integer from 1-65535');
  }

  currentConfig.port = port;
};
p._writeTarget = function*(target) {
	this._debug('_writeTarget');
	if (_.isUndefined(target)) {
		return;
	}
	if (_.isNull(target)) {
		yield* this._write(this._BUF_NULL);
		return;
	}
	if (_.isArray(target)) {
		yield* this._writeArray(target);
		return;
	}
	if (_.isObject(target)) {
		yield* this._writeObject(target);
		return;
	}
	if (_.isString(target)) {
		yield* this._writeString(target);
		return;
	}
	if (_.isNumber(target)) {
		if (_.isInteger(target)) {
			yield* this._writeNumber(target, this._integerCache);
			return;
		}
		yield* this._writeNumber(target, this._numberCache);
		return;
	}
	if (_.isBoolean(target)) {
		yield* this._write(target ? this._BUF_TRUE : this._BUF_FALSE);
		return;
	}
	throw new Error('Unsupported type');
};
Example #9
0
['debug-port', 't', 'tab', 'tap-limit'].forEach(function (option) {
    if (!_.isInteger(args[option])) {
        if (option.length > 1)
            option = '-'+ option;
        exitWithUserError("-"+ option +" must take an integer value");
    }
});
Example #10
0
app.get(path.join(base, '/work-experience/:id'), function(req, res){
    var query = {};
    query._id = parseInt(req.params.id);
    if (! _.isInteger(query._id)) {
        var repErr = {
            "status": "error",
            "detail": "id can only be integer"
        };
        res.send(JSON.stringify(repErr));
    }

    data.retrieveAll('profession', query)
    .then(function(doc){
        var repJSON = JSON.stringify(doc);
        res.send(repJSON);
    })
    .catch(function(err){
        console.log('Error happened, ', err);
        var repErr = {
            result: "error",
            detail: err
        };
        res.send(JSON.stringify(repErr));
    });
});
Example #11
0
  async function build_entry_ids(env) {
    let prev = false, next = false, start = null;

    if (env.params.$query) {
      let query = env.params.$query;

      prev = typeof query.prev !== 'undefined';
      next = typeof query.next !== 'undefined';

      // get hid by id
      if (query.from && _.isInteger(+query.from)) {
        let entry = await N.models.blogs.BlogEntry.findOne()
                              .where('hid').equals(+query.from)
                              .where('st').in(env.data.blog_entries_visible_statuses)
                              .select('_id')
                              .lean(true);

        if (entry) start = entry._id;
      }
    }

    let limit_direction = prev || next;

    env.data.select_start  = start;
    env.data.select_before = (!limit_direction || prev) ? env.data.entries_per_page : 0;
    env.data.select_after  = (!limit_direction || next) ? env.data.entries_per_page : 0;

    return build_entry_ids_by_range(env);
  }
Example #12
0
 return _.find(this.columns, function (column) {
   if (_.isInteger(nameOrId)) {
     return column.id === nameOrId;
   } else {
     return column.name === nameOrId;
   }
 });
Example #13
0
    this.serverless.service.getAllFunctions().forEach((functionName) => {
      const functionObject = this.serverless.service.getFunction(functionName);
      const logGroupLogicalId = this.provider.naming
        .getLogGroupLogicalId(functionName);
      const newLogGroup = {
        [logGroupLogicalId]: {
          Type: 'AWS::Logs::LogGroup',
          Properties: {
            LogGroupName: this.provider.naming.getLogGroupName(functionObject.name),
          },
        },
      };

      if (_.has(this.serverless.service.provider, 'logRetentionInDays')) {
        if (_.isInteger(this.serverless.service.provider.logRetentionInDays) &&
          this.serverless.service.provider.logRetentionInDays > 0) {
          newLogGroup[logGroupLogicalId].Properties.RetentionInDays
            = this.serverless.service.provider.logRetentionInDays;
        } else {
          const errorMessage = 'logRetentionInDays should be an integer over 0';
          throw new this.serverless.classes.Error(errorMessage);
        }
      }

      _.merge(this.serverless.service.provider.compiledCloudFormationTemplate.Resources,
        newLogGroup);
    });
module.exports = function() {
  var maxParallel = parseInt(process.env.MAX_CONCURRENCY);
  var serverPort = parseInt(process.env.SERVER_PORT);
  var codeMaatOptions = process.env.CODEMAAT_OPTS;

  //Temporary code to warn about deprecation of MAX_CONCURRENCY
  if (_.isInteger(maxParallel)) {
    deprecationWarning('The usage of the env variable ' + ansi.bold('MAX_CONCURRENCY') + ' is deprecated and will be removed in future versions.\nSet the env variable ' + ansi.bold('SERIAL_PROCESSING') +' to control concurrency.');
  }

  var getMaxConcurrency = function() {
    if (!_.isUndefined(process.env.SERIAL_PROCESSING)) return 1;
    if (_.isInteger(maxParallel)) return maxParallel;
  };

  this.getConfiguration = function() {
    return {
      maxConcurrency: getMaxConcurrency(),
      debugMode: !_.isUndefined(process.env.COMMAND_DEBUG),
      logEnabled: _.isUndefined(process.env.LOG_DISABLED),
      serverPort: _.isInteger(serverPort) ? serverPort : undefined,
      codeMaat: { options: _.isString(codeMaatOptions) ? utils.arrays.arrayPairsToObject(codeMaatOptions.split(' ')) : {} }
    };
  };
};
Example #15
0
function getSchemaType(v) {
	if (v === null || v === undefined) return 'null';
	var t = typeof v;
	if (v instanceof Array) return 'array';
	if (_.isInteger(v) && t !== 'string') return 'integer';
	return t;
}
 [ apicConfig.PROJECT_STORE, apicConfig.USER_STORE ].some(function(location) {
   var obj = config.get('parserSizeLimit', location);
   if (obj.parserSizeLimit && _.isInteger(parseInt(obj.parserSizeLimit, 10))) {
     sizeLimit = obj.parserSizeLimit;
     logger.debug('set parserSizeLimit to %d bytes', sizeLimit);
     return true;
   }
 });
Example #17
0
			_.each( e.indexBy, ( v, k ) => {
				if( !_.isInteger( k ) && !e[ k ] ) {
					e[ k ] = v;
					indices.push( v );
				} else {
					indices.push( v );
				}
			} );
Example #18
0
  make: function(source, dimension) {
    // create the matrix
    var mat = {}
    // if dimension is an integer, the matrix is square
    if (_.isFunction(source)
        && _.isInteger(dimension) && dimension >= 0) {
          dimension = { x:dimension, y:dimension }
    }

    // source can be a 2-var predicate function or a line based matrix
    if (_.isFunction(source)
        && dimension
        && _.isInteger(dimension.x) && dimension.x >= 0
        && _.isInteger(dimension.y) && dimension.y >= 0) {
          // creating the matrix
          mat.x = dimension.x
          mat.y = dimension.y
          mat.data = []
          // populate
          for (var i = 0; i < mat.x; i++) {
            mat.data.push([])
            for (var j = 0; j < mat.y; j++) {
              if (source(i, j)) {
                mat.data[i].push(j)
              }
            }
          }
    } else if (_.isArray(source) && source[0] && _.isArray(source[0])) {
      // creating the matrix
      mat.x = source.length
      mat.y = source[0].length
      mat.data = []
      // populate
      for (var i = 0; i < mat.x; i++) {
        mat.data.push([])
        for (var j = 0; j < mat.y; j++) {
          if (source[i][j]) {
            mat.data[i].push(j)
          }
        }
      }
    }
    // return the matrix
    return mat
  },
Example #19
0
/**
 * Returns whether the original image size is greater than minimumImageDimensions values.
 *
 * @param  {Object}  state Global state tree
 * @param   {Integer} minimumWidth the minimum width of the image
 * @param   {Integer} minimumHeight the minimum height of the image
 * @returns {Boolean} whether dimensions of the image meet the minimum dimension requirements
 */
export default function getImageEditorIsGreaterThanMinimumDimensions(
	state,
	minimumWidth = MinimumImageDimensions.WIDTH,
	minimumHeight = MinimumImageDimensions.HEIGHT ) {
	const originalAspectRatio = getImageEditorOriginalAspectRatio( state );

	if ( originalAspectRatio ) {
		const { width, height } = originalAspectRatio;

		if ( isInteger( width ) &&
			isInteger( height ) &&
			width > minimumWidth &&
			height > minimumHeight ) {
			return true;
		}
	}
	return false;
}
 this.getConfiguration = function() {
   return {
     maxConcurrency: getMaxConcurrency(),
     debugMode: !_.isUndefined(process.env.COMMAND_DEBUG),
     logEnabled: _.isUndefined(process.env.LOG_DISABLED),
     serverPort: _.isInteger(serverPort) ? serverPort : undefined,
     codeMaat: { options: _.isString(codeMaatOptions) ? utils.arrays.arrayPairsToObject(codeMaatOptions.split(' ')) : {} }
   };
 };
Example #21
0
const replicationGraph = (nSrs, redundancy, w, h) => {
  const nGroups = nSrs / redundancy

  if (!isInteger(nGroups)) {
    return null
  }

  return graph(nGroups, redundancy, w, h, redundancy - 1)
}
Example #22
0
MockedResponse.prototype.status = function(statusCode) {
  this.statusCode = parseInt(statusCode, 10);
  
  if(!_.isInteger(this.statusCode)){
    this.statusCode = DEFAULT_STATUS_CODE;
  }

  return this;
};
Example #23
0
 setClaimTimeout: function (timeout) {
   
   if (_.isInteger(_.toNumber(timeout))) {
     localClaimsExpiry = _.toNumber(timeout);
     console.log("localClaims expiry has been successfully set to", timeout, "ms");
   } else {
     console.log("timeout needs to be an integer");
   }
 }
Example #24
0
  /**
   * Gets the parent of the node at the specified position.
   *
   * @private
   * @param  {number} position The index of the node to get the parent of.
   * @return {Node}   The parent of the node at the specified position.
   */
  getParent(position) {
    if (isUndefined(position) || !isInteger(position)) throw new Error(green('You need to use a position with the getParent() function!'))

    if (position > 0) {
      let parentPosition = Math.floor((position - 1) / 2)
      return this.heap[parentPosition]
    }
    return null
  }
Example #25
0
function generateNameForIndex(index) {
    if (!_.isInteger(index) || index < 0) {
        throw new Error("The parameter 'index' must be a non-negative integer. ");
    }
    if (index >= nato.length) {
        throw new Error("Unsupported");
    }
    return nato[index];
}
Example #26
0
function generateNames(n) {
    if (!_.isInteger(n) || n < 0) {
        throw new Error("The parameter 'n' must be a non-negative integer. ");
    }
    if (n >= nato.length) {
        throw new Error("Unsupported");
    }
    return nato.slice(n);
}
Example #27
0
var encodeToken = function (sub, secret, expiry) {
  expiry = (_.isInteger(expiry)) ? expiry : 14;
  var payload =  {
    exp: moment().add(expiry, 'days').unix(),
    iat: moment().unix(),
    sub: sub,
  };
  return jwt.encode(payload, secret);
};
Example #28
0
export function getIntervalBetweenDates (fromDate, toDate, intervals = ['year', 'month', 'day']) {
  for (let i = 0; i < intervals.length; i++) {
    const interval = intervals[i]
    const count = moment(toDate).diff(moment(fromDate), interval, i < intervals.length - 1)
    if (_.isInteger(count)) {
      return { interval, count }
    }
  }
  throw new Error(`could not calculate interval between dates ${fromDate} ${toDate}`)
}
Example #29
0
 async getXcodeVersion() {
   const raw = await exec.execWithRetriesAndLogs(`xcodebuild -version`, undefined, undefined, 1);
   const stdout = _.get(raw, 'stdout', 'undefined');
   const match = /^Xcode (\S+)\.*\S*\s*/.exec(stdout);
   const majorVersion = parseInt(_.get(match, '[1]'));
   if (!_.isInteger(majorVersion) || majorVersion < 1) {
     throw new Error(`Can't read Xcode version, got: '${stdout}'`);
   }
   return majorVersion;
 }
Example #30
0
  start(timeout){

    //this.intervalFn.call(this);

    timeout = _.isInteger(timeout) ? timeout : 600000;

    console.log('Job::start');
    console.log('STARTING JOB ---- ', timeout);
    this.interval = setInterval(this.intervalFn, timeout);
  }