{"record":{"id":"2604fefd9a11ac45","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-string-2604fe","errorCode":null,"errorMessage":"Argument is not a string.","messagePattern":"Argument is not a string\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/CheckSnakeCase.js","lineNumber":13,"sourceCode":"// CheckSnakeCase method checks the given string is in snake_case or not.\n\n// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)\n\n/**\n * checkSnakeCase method returns true if the string in snake_case, else return the false.\n * @param {String} varName the name of the variable to check.\n * @returns `Boolean` return true if the string is in snake_case, else return false.\n */\nconst checkSnakeCase = (varName) => {\n  // firstly, check that input is a string or not.\n  if (typeof varName !== 'string') {\n    throw new TypeError('Argument is not a string.')\n  }\n\n  const pat = /(.*?)_([a-zA-Z])*/\n  return pat.test(varName)\n}\n\nexport { checkSnakeCase }\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/CheckSnakeCase.js#L1-L21","documentation":"Pre-condition guard at the top of checkSnakeCase. The function tests a name against a snake_case-ish regex ((.*?)_([a-zA-Z])*) and first asserts the input is a string. Any non-string input is rejected with TypeError before regex.test() runs. Note the regex itself is permissive (it matches almost any string containing an underscore), but the guard is strictly about type.","triggerScenarios":"Calling checkSnakeCase(undefined), checkSnakeCase(null), checkSnakeCase(0), checkSnakeCase(Symbol('x')), or any value whose typeof !== 'string'.","commonSituations":"A field read from a config object that was not set; a value coming from URL search params that was parsed to a number; an env var that is undefined when the variable is missing from the environment.","solutions":["Guarantee a string before calling: String(value) only after confirming it is not null/undefined, or check typeof.","Provide a fallback default for the source variable.","Add a runtime type check at the boundary where untrusted data enters your module."],"exampleFix":"// before\ncheckSnakeCase(process.env.VAR_NAME)\n\n// after\nconst name = process.env.VAR_NAME\nif (typeof name === 'string') checkSnakeCase(name)","handlingStrategy":"type-guard","validationCode":"if (typeof varName !== 'string') {\n  throw new TypeError('varName must be a string')\n}\ncheckSnakeCase(varName)","typeGuard":"const isString = (v) => typeof v === 'string'","tryCatchPattern":"try {\n  checkSnakeCase(name)\n} catch (e) {\n  if (e instanceof TypeError) { /* type error */ } else throw e\n}","preventionTips":["Default env vars and config reads to ''.","Validate at the trust boundary, not deep inside call chains.","Use a shared isString helper across the module."],"tags":["string","validation","type-guard","naming-convention"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}