{"record":{"id":"7897410086bfb9ac","repo":"TheAlgorithms/JavaScript","slug":"argument-is-not-a-string-789741","errorCode":null,"errorMessage":"Argument is not a string.","messagePattern":"Argument is not a string\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"String/CheckKebabCase.js","lineNumber":13,"sourceCode":"// CheckKebabCase method checks the given string is in kebab-case or not.\n\n// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)\n\n/**\n * CheckKebabCase method returns true if the string in kebab-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 kebab-case, else return false.\n */\nconst CheckKebabCase = (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 = /(\\w+)-(\\w)([\\w-]*)/\n  return pat.test(varName) && !varName.includes('_')\n}\n\nexport { CheckKebabCase }\n","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/TheAlgorithms/JavaScript/blob/5c39e87a9a31f279c60f830ad74a845e4788a517/String/CheckKebabCase.js#L1-L21","documentation":"Thrown as a TypeError by CheckKebabCase() when varName is not a string. The function tests varName against a regex and calls varName.includes('_'), both requiring a string. Kebab-case means lowercase words joined by hyphens (e.g. 'my-var-name').","triggerScenarios":"Calling CheckKebabCase(null), CheckKebabCase(undefined), CheckKebabCase(123), or CheckKebabCase(['my-var']).","commonSituations":"Config key validation where keys can be numbers; missing fields in parsed YAML/JSON; values from a generic map typed as unknown.","solutions":["Coerce: CheckKebabCase(String(name)).","Type-guard before calling.","Ensure the upstream always produces strings."],"exampleFix":"// before\nCheckKebabCase(key)\n\n// after\nCheckKebabCase(String(key ?? ''))","handlingStrategy":"type-guard","validationCode":"function safeCheckKebabCase(name) {\n  if (typeof name !== 'string') {\n    throw new TypeError('Expected a string')\n  }\n  return CheckKebabCase(name)\n}","typeGuard":"function isString(v) {\n  return typeof v === 'string'\n}","tryCatchPattern":"try {\n  CheckKebabCase(name)\n} catch (e) {\n  if (e instanceof TypeError && e.message === 'Argument is not a string.') {\n    return false\n  }\n  throw e\n}","preventionTips":["Coerce keys/names with String() before calling.","Default missing config keys to empty string.","Validate types where identifiers enter the system."],"tags":["type-check","string","naming-convention","input-validation"],"backgroundTag":null,"analyzedSha":"5c39e87a9a31f279c60f830ad74a845e4788a517","analyzedAt":"2026-08-13T04:54:54.474Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}