index.js
/**
 * Generates a cryptographically secure random string to be used as a password
 * salt, using Node's built-in crypto.randomBytes() function.
 * @public
 * @param  {number} length The length of the salt to be generated.
 * Must be an integer within the range (`0` <= `length` <= `2^31-1`).
 * @return {Promise.<Buffer>} The salt as a Buffer.
 */
Generates a cryptographically secure random string to be used as a password
salt, using Node's built-in crypto.randomBytes() function.
@public
@param  {number} length The length of the salt to be generated.
Generates a cryptographically secure random string to be used as a password salt using Node ' s built - in crypto . randomBytes () function . @public @param { number } length The length of the salt to be generated .
function gensalt(length) {
  if (typeof length !== 'number' || !Number.isInteger(length)) {
    return Promise.reject(
      new TypeError("The 'length' parameter must be an integer")
    );
  }
  if (length < 0 || length > MAX_UINT31) {
    return Promise.reject(
      new TypeError(
        `The 'length' parameter must be in the range (0 <= length <= ${MAX_UINT31})`
      )
    );
  }
  return new Promise((resolve, reject) => {
    crypto.randomBytes(length, (err, salt) => {
      if (err) reject(err);
      else resolve(salt);
    });
  });
}
function gensalt ( length ) { if ( typeof length !== 'number' || ! Number . isInteger ( length ) ) { return Promise . reject ( new TypeError ( "The 'length' parameter must be an integer" ) ) ; } if ( length < 0 || length > MAX_UINT31 ) { return Promise . reject ( new TypeError ( ` ${ MAX_UINT31 } ` ) ) ; } return new Promise ( ( resolve , reject ) => { crypto . randomBytes ( length , ( err , salt ) => { if ( err ) reject ( err ) ; else resolve ( salt ) ; } ) ; } ) ; }
Generates a cryptographically secure random string to be used as a password
 salt, using Node's built-in crypto.randomBytes() function.
Generates a cryptographically secure random string to be used as a password salt using Node ' s built - in crypto . randomBytes () function .
// Salt length Validation /* istanbul ignore next */