Created
September 25, 2023 03:40
-
-
Save techieshark/782d59fe7ba21f78662e5b5112542242 to your computer and use it in GitHub Desktop.
Is string s a non empty string?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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