How to use the is.int function in is

To help you get started, we’ve selected a few is 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 pgirard / blind / index.js View on Github external
throw new TypeError(hashRoundsMessage);
  }

  if (!is.int(this.hashRounds) || this.hashRounds < 1) {
    throw new RangeError(hashRoundsRangeMessage);
  }

  // set and check maxDataLength

  this.maxDataLength = options.maxDataLength || maxDataLengthDefault;

  if (!is.number(this.maxDataLength)) {
    throw new TypeError(maxDataLengthMessage);
  }

  if (!is.int(this.maxDataLength) || this.maxDataLength < 1) {
    throw new RangeError(maxDataLengthRangeMessage);
  }

  // set and check maxRandomLength

  this.maxRandomLength = options.maxRandomLength || maxRandomLengthDefault;

  if (!is.number(this.maxRandomLength)) {
    throw new TypeError(maxRandomLengthMessage);
  }

  if (!is.int(this.maxRandomLength) || this.maxRandomLength < minRandomLength + 1) {
    throw new RangeError(maxRandomLengthRangeMessage);
  }

  // set and check randomLength
github pgirard / blind / index.js View on Github external
throw new TypeError(maxRandomLengthMessage);
  }

  if (!is.int(this.maxRandomLength) || this.maxRandomLength < minRandomLength + 1) {
    throw new RangeError(maxRandomLengthRangeMessage);
  }

  // set and check randomLength

  this.randomLength = options.randomLength || randomLengthDefault;

  if (!is.number(this.randomLength)) {
    throw new TypeError(randomLengthMessage);
  }

  if (!is.int(this.randomLength) || !is.within(this.randomLength, minRandomLength, this.maxRandomLength)) {
    throw new RangeError('Property \'randomLength\' must be an integer between ' + minRandomLength + ' and ' + this.maxRandomLength);
  }

  // set skipChecks

  this.skipChecks = options.skipChecks || skipChecksDefault;
}
github pgirard / blind / index.js View on Github external
throw new TypeError(maxDataLengthMessage);
  }

  if (!is.int(this.maxDataLength) || this.maxDataLength < 1) {
    throw new RangeError(maxDataLengthRangeMessage);
  }

  // set and check maxRandomLength

  this.maxRandomLength = options.maxRandomLength || maxRandomLengthDefault;

  if (!is.number(this.maxRandomLength)) {
    throw new TypeError(maxRandomLengthMessage);
  }

  if (!is.int(this.maxRandomLength) || this.maxRandomLength < minRandomLength + 1) {
    throw new RangeError(maxRandomLengthRangeMessage);
  }

  // set and check randomLength

  this.randomLength = options.randomLength || randomLengthDefault;

  if (!is.number(this.randomLength)) {
    throw new TypeError(randomLengthMessage);
  }

  if (!is.int(this.randomLength) || !is.within(this.randomLength, minRandomLength, this.maxRandomLength)) {
    throw new RangeError('Property \'randomLength\' must be an integer between ' + minRandomLength + ' and ' + this.maxRandomLength);
  }

  // set skipChecks
github pgirard / blind / index.js View on Github external
this.hashAlgorithm = options.hashAlgorithm || hashAlgorithmDefault;

  if (validHashAlgorithms.indexOf(this.hashAlgorithm) < 0) {
    throw new RangeError(hashAlgorithmMessage);
  }

  // set and check hashRounds

  this.hashRounds = options.hashRounds || hashRoundsDefault;

  if (!is.number(this.hashRounds)) {
    throw new TypeError(hashRoundsMessage);
  }

  if (!is.int(this.hashRounds) || this.hashRounds < 1) {
    throw new RangeError(hashRoundsRangeMessage);
  }

  // set and check maxDataLength

  this.maxDataLength = options.maxDataLength || maxDataLengthDefault;

  if (!is.number(this.maxDataLength)) {
    throw new TypeError(maxDataLengthMessage);
  }

  if (!is.int(this.maxDataLength) || this.maxDataLength < 1) {
    throw new RangeError(maxDataLengthRangeMessage);
  }

  // set and check maxRandomLength
github pgirard / blind / index.js View on Github external
Blind.prototype.random = function (length) {

  // check properties and arguments

  if (!this.skipChecks) {
    if (validBinaryEncodings.indexOf(this.binaryEncoding) < 0) {
      throw new RangeError(binaryEncodingMessage);
    }

    if (!is.number(this.maxRandomLength)) {
      throw new TypeError(maxRandomLengthMessage);
    }

    if (!is.int(this.maxRandomLength) || this.maxRandomLength < minRandomLength + 1) {
      throw new RangeError(maxRandomLengthRangeMessage);
    }

    if (length === undefined) {
      if (!is.number(this.randomLength)) {
        throw new TypeError(randomLengthMessage);
      }

      if (!is.int(this.randomLength) || !is.within(this.randomLength, minRandomLength, this.maxRandomLength)) {
        throw new RangeError('Property \'randomLength\' must be an integer between ' + minRandomLength + ' and ' + this.maxRandomLength);
      }
    }
    else {
      if (!is.number(length)) {
        throw new TypeError('Argument \'length\' must be a number');
      }
github pgirard / blind / index.js View on Github external
if (length === undefined) {
      if (!is.number(this.randomLength)) {
        throw new TypeError(randomLengthMessage);
      }

      if (!is.int(this.randomLength) || !is.within(this.randomLength, minRandomLength, this.maxRandomLength)) {
        throw new RangeError('Property \'randomLength\' must be an integer between ' + minRandomLength + ' and ' + this.maxRandomLength);
      }
    }
    else {
      if (!is.number(length)) {
        throw new TypeError('Argument \'length\' must be a number');
      }

      if (!is.int(length) || !is.within(length, minRandomLength, this.maxRandomLength)) {
        throw new RangeError('Argument \'length\' must be an integer between ' + minRandomLength + ' and ' + this.maxRandomLength);
      }
    }
  }

  // generate the random value

  return crypto.randomBytes(length || this.randomLength).toString(this.binaryEncoding);
};
github pgirard / blind / index.js View on Github external
// check properties and arguments

  if (!this.skipChecks) {
    if (validBinaryEncodings.indexOf(this.binaryEncoding) < 0) {
      throw new RangeError(binaryEncodingMessage);
    }

    if (validHashAlgorithms.indexOf(this.hashAlgorithm) < 0) {
      throw new RangeError(hashAlgorithmMessage);
    }

    if (!is.number(this.hashRounds)) {
      throw new TypeError(hashRoundsMessage);
    }

    if (!is.int(this.hashRounds) || this.hashRounds < 1) {
      throw new RangeError(hashRoundsRangeMessage);
    }

    if (!is.number(this.maxDataLength)) {
      throw new TypeError(maxDataLengthMessage);
    }

    if (!is.int(this.maxDataLength) || this.maxDataLength < 1) {
      throw new RangeError(maxDataLengthRangeMessage);
    }

    if (!is.string(data) || !is.within(data.length, 1, this.maxDataLength)) {
      throw new TypeError('Argument \'data\' must be a string between 1 and ' + this.maxDataLength + ' characters long');
    }

    if (salt !== undefined && salt !== null) {
github pgirard / blind / index.js View on Github external
}

    if (!is.number(this.maxRandomLength)) {
      throw new TypeError(maxRandomLengthMessage);
    }

    if (!is.int(this.maxRandomLength) || this.maxRandomLength < minRandomLength + 1) {
      throw new RangeError(maxRandomLengthRangeMessage);
    }

    if (length === undefined) {
      if (!is.number(this.randomLength)) {
        throw new TypeError(randomLengthMessage);
      }

      if (!is.int(this.randomLength) || !is.within(this.randomLength, minRandomLength, this.maxRandomLength)) {
        throw new RangeError('Property \'randomLength\' must be an integer between ' + minRandomLength + ' and ' + this.maxRandomLength);
      }
    }
    else {
      if (!is.number(length)) {
        throw new TypeError('Argument \'length\' must be a number');
      }

      if (!is.int(length) || !is.within(length, minRandomLength, this.maxRandomLength)) {
        throw new RangeError('Argument \'length\' must be an integer between ' + minRandomLength + ' and ' + this.maxRandomLength);
      }
    }
  }

  // generate the random value
github pgirard / blind / index.js View on Github external
throw new RangeError(hashAlgorithmMessage);
    }

    if (!is.number(this.hashRounds)) {
      throw new TypeError(hashRoundsMessage);
    }

    if (!is.int(this.hashRounds) || this.hashRounds < 1) {
      throw new RangeError(hashRoundsRangeMessage);
    }

    if (!is.number(this.maxDataLength)) {
      throw new TypeError(maxDataLengthMessage);
    }

    if (!is.int(this.maxDataLength) || this.maxDataLength < 1) {
      throw new RangeError(maxDataLengthRangeMessage);
    }

    if (!is.string(data) || !is.within(data.length, 1, this.maxDataLength)) {
      throw new TypeError('Argument \'data\' must be a string between 1 and ' + this.maxDataLength + ' characters long');
    }

    if (salt !== undefined && salt !== null) {
      if (!is.string(salt) || !salt.length) {
        throw new TypeError('Argument \'salt\' must be a string with one or more characters');
      }

      if (!is[this.binaryEncoding](salt)) {
        throw new TypeError('Argument \'salt\' must be a ' + this.binaryEncoding + ' encoded binary value');
      }
    }