Skip to content

Instantly share code, notes, and snippets.

@techieshark
Created September 25, 2023 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techieshark/782d59fe7ba21f78662e5b5112542242 to your computer and use it in GitHub Desktop.
Save techieshark/782d59fe7ba21f78662e5b5112542242 to your computer and use it in GitHub Desktop.
Is string s a non empty string?
/**
* Is `s` both 1) defined, 2) a string, and 3) not empty?
* Can also be used as a TS type predicate to remove `undefined` values.
*/
export function isNonEmptyString(s?: string): s is string {
return Boolean(
typeof s === 'string' &&
s.length > 0
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment