All files password.js

100% Statements 15/15
100% Branches 8/8
100% Functions 5/5
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 401x 8x     1x           7x     1x 7x     1x 6x 6x 26x   2x     1x 4x           1x              
const checkLength = function (password) {
  return password.length >= 8 && password.length <= 25
}
 
const checkAlphabet = function (password) {
  // const alphabet = 'abcdefghilklmnopqrstuvwxyz'
  // for (const ch of password) {
  //   if (alphabet.includes(ch.toLowerCase())) return true
  // }
  // return false
  return /[a-zA-Z]/.test(password)
}
 
const checkDigit = function (password) {
  return /[0-9]/.test(password)
}
 
const checkSymbol = function (password) {
  const symbol = '!"#$%&( )*+,-./:;<=>?@[]^_`{|}~'
  for (const ch of password) {
    if (symbol.includes(ch.toLowerCase())) return true
  }
  return false
}
 
const checkPassword = function (password) {
  return checkLength(password) &&
  checkAlphabet(password) &&
  checkDigit(password) &&
  checkSymbol(password)
}
 
module.exports = {
  checkLength,
  checkAlphabet,
  checkDigit,
  checkSymbol,
  checkPassword
}