[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/TheAlgorithms/JavaScript/master/String/Lower.js [Back]  [Original]

/**
 * @function lower
 * @description Will convert the entire string to lowercase letters.
 * @param {String} str - The input string
 * @returns {String} Lowercase string
 * @example lower("HELLO") => hello
 * @example lower("He_llo") => he_llo
 */

const lower = (str) => {
  if (typeof str !== 'string') {
    throw new TypeError('Invalid Input Type')
  }

  return str.replace(/[A-Z]/g, (char) =>
    String.fromCharCode(char.charCodeAt() + 32)
  )
}

export default lower

Web Proxy Viewer  |  New URL  |  Original Page