{"record":{"id":"f94dcf009fd45703","repo":"TheAlgorithms/JavaScript","slug":"invalid-input-type-f94dcf","errorCode":null,"errorMessage":"Invalid Input Type","messagePattern":"Invalid Input Type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/Lower.js","lineNumber":12,"sourceCode":"/**\n * @function lower\n * @description Will convert the entire string to lowercase letters.\n * @param {String} str - The input string\n * @returns {String} Lowercase string\n * @example lower(\"HELLO\") => hello\n * @example lower(\"He_llo\") => he_llo\n */\n\nconst lower = (str) => {\n  if (typeof str !== 'string') {\n    throw new TypeError('Invalid Input Type')\n  }\n\n  return str.replace(/[A-Z]/g, (char) =>\n    String.fromCharCode(char.charCodeAt() + 32)\n  )\n}\n\nexport default lower\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/Lower.js#L1-L21","documentation":"Guard in lower. The function lowercases a string by replacing [A-Z] with charCode+32 equivalents and requires the input to be a string, throwing TypeError otherwise. This protects .replace() from non-string values.","triggerScenarios":"Calling lower(undefined), lower(null), lower(42), lower(['A']). Any input where typeof !== 'string'.","commonSituations":"Optional field omitted; value coerced to a number earlier; array passed instead of a string. Note: for production use String.prototype.toLowerCase() is more robust (handles Unicode), so calling this custom lower is itself a choice to flag.","solutions":["Pass a string; default missing values to ''.","Validate typeof at the call site.","Consider the native str.toLowerCase() for full Unicode coverage."],"exampleFix":"// before\nlower(maybeStr)\n\n// after\nlower(typeof maybeStr === 'string' ? maybeStr : '')","handlingStrategy":"type-guard","validationCode":"if (typeof str !== 'string') {\n  throw new TypeError('str must be a string')\n}\nlower(str)","typeGuard":"const isString = (v) => typeof v === 'string'","tryCatchPattern":"try {\n  lower(input)\n} catch (e) {\n  if (e instanceof TypeError && /Invalid Input Type/i.test(e.message)) { /* not a string */ } else throw e\n}","preventionTips":["Default optional fields to ''.","For Unicode correctness prefer native str.toLowerCase().","Validate typeof at the boundary."],"tags":["string","validation","type-guard","lowercase","unicode-caveat"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}