TheAlgorithms/JavaScript · error · TypeError
Argument is not a string.
Error message
Argument is not a string.
What it means
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').
Source
Thrown at String/CheckKebabCase.js:13
// CheckKebabCase method checks the given string is in kebab-case or not.
// Problem Source & Explanation: https://en.wikipedia.org/wiki/Naming_convention_(programming)
/**
* CheckKebabCase method returns true if the string in kebab-case, else return the false.
* @param {String} varName the name of the variable to check.
* @returns `Boolean` return true if the string is in kebab-case, else return false.
*/
const CheckKebabCase = (varName) => {
// firstly, check that input is a string or not.
if (typeof varName !== 'string') {
throw new TypeError('Argument is not a string.')
}
const pat = /(\w+)-(\w)([\w-]*)/
return pat.test(varName) && !varName.includes('_')
}
export { CheckKebabCase }
View on GitHub (pinned to 5c39e87a9a)
Solutions
- Coerce: CheckKebabCase(String(name)).
- Type-guard before calling.
- Ensure the upstream always produces strings.
Example fix
// before CheckKebabCase(key) // after CheckKebabCase(String(key ?? ''))
Defensive patterns
Strategy: type-guard
Validate before calling
function safeCheckKebabCase(name) {
if (typeof name !== 'string') {
throw new TypeError('Expected a string')
}
return CheckKebabCase(name)
} Type guard
function isString(v) {
return typeof v === 'string'
} Try / catch
try {
CheckKebabCase(name)
} catch (e) {
if (e instanceof TypeError && e.message === 'Argument is not a string.') {
return false
}
throw e
} Prevention
- Coerce keys/names with String() before calling.
- Default missing config keys to empty string.
- Validate types where identifiers enter the system.
When it happens
Trigger: Calling CheckKebabCase(null), CheckKebabCase(undefined), CheckKebabCase(123), or CheckKebabCase(['my-var']).
Common situations: Config key validation where keys can be numbers; missing fields in parsed YAML/JSON; values from a generic map typed as unknown.
Related errors
- Argument is not a string.
- Argument is not a string.
- Invalid Input
- Argument should be string
- Both arguments should be strings.
AI-assisted analysis of TheAlgorithms/JavaScript@5c39e87a9a (2026-08-13).
Data as JSON: /api/errors/7897410086bfb9ac.
Report an issue: GitHub.