{"id":"f3b0a3efbdb231b8","repo":"sindresorhus/is","slug":"expected-value-which-is-non-empty-string-and-not","errorCode":null,"errorMessage":"Expected value which is `non-empty string and not whitespace`, received value of type `${is(value)}`.","messagePattern":"Expected value which is `non-empty string and not whitespace`, received value of type `(.+?)`\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/index.ts","lineNumber":1773,"sourceCode":"\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty object', value));\n\t}\n}\n\nexport function assertNonEmptySet<T = unknown>(value: unknown, message?: string): asserts value is Set<T> {\n\tif (!isNonEmptySet(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty set', value));\n\t}\n}\n\nexport function assertNonEmptyString(value: unknown, message?: string): asserts value is string {\n\tif (!isNonEmptyString(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty string', value));\n\t}\n}\n\nexport function assertNonEmptyStringAndNotWhitespace(value: unknown, message?: string): asserts value is string {\n\tif (!isNonEmptyStringAndNotWhitespace(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-empty string and not whitespace', value));\n\t}\n}\n\nexport function assertNonNegativeInteger(value: unknown, message?: string): asserts value is number {\n\tif (!isNonNegativeInteger(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-negative integer', value));\n\t}\n}\n\nexport function assertNonNegativeNumber(value: unknown, message?: string): asserts value is number {\n\tif (!isNonNegativeNumber(value)) {\n\t\tthrow new TypeError(message ?? typeErrorMessage('non-negative number', value));\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-restricted-types\nexport function assertNull(value: unknown, message?: string): asserts value is null {\n\tif (!isNull(value)) {","sourceCodeStart":1755,"sourceCodeEnd":1791,"githubUrl":"https://github.com/sindresorhus/is/blob/7821031c66cdeb7256a0feb2d506535f9e84fcaf/source/index.ts#L1755-L1791","documentation":"Thrown by `assertNonEmptyStringAndNotWhitespace()` (source/index.ts:1771) when the value is not a string containing at least one non-whitespace character. It is the stricter sibling of `assertNonEmptyString`: `''`, `'   '`, `'\\t\\n'`, and all non-strings fail.","triggerScenarios":"Calling `assert.nonEmptyStringAndNotWhitespace(value)` with a whitespace-only string (user typed spaces in a form, a padded CSV/env value), the empty string, or a non-string value.","commonSituations":"Untrimmed user input from forms or CLI prompts; config values accidentally saved as blank lines or spaces; copy-pasted secrets/tokens that captured only whitespace.","solutions":["Trim input at the boundary (`value.trim()`) and validate the trimmed result — then use the trimmed value downstream.","Verify the config/env source actually contains a real value, not padding or a blank line.","If blank input is a legal 'skip' signal, branch on `is.nonEmptyStringAndNotWhitespace(value)` instead of asserting."],"exampleFix":"// before\nassert.nonEmptyStringAndNotWhitespace(userInput); // throws on '   '\n// after\nconst name = userInput.trim();\nassert.nonEmptyStringAndNotWhitespace(name);\nsave(name);","handlingStrategy":"type-guard","validationCode":"if (typeof value === 'string' && value.trim().length > 0) {\n  assert.nonEmptyStringAndNotWhitespace(value);\n}","typeGuard":"function isNonEmptyStringAndNotWhitespace(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  assert.nonEmptyStringAndNotWhitespace(title);\n} catch (error) {\n  if (error instanceof TypeError) {\n    // title is empty or whitespace-only (e.g. '   ') — reject or re-prompt for input\n  }\n  throw error;\n}","preventionTips":["Trim user input at the boundary (value.trim()) before validating or storing it","Test with whitespace-only inputs ('  ', '\\t', '\\n') — they pass nonEmptyString but fail this stricter assert","Prefer this assert over nonEmptyString for human-entered fields like names and titles"],"tags":["assertion","type-check","string","validation","input-sanitization"],"analyzedSha":"7821031c66cdeb7256a0feb2d506535f9e84fcaf","analyzedAt":"2026-07-31T18:34:06.268Z","schemaVersion":2}