Skip to content

Instantly share code, notes, and snippets.

@techieshark
Created September 25, 2023 03:40
Show Gist options
  • Save techieshark/782d59fe7ba21f78662e5b5112542242 to your computer and use it in GitHub Desktop.
Save techieshark/782d59fe7ba21f78662e5b5112542242 to your computer and use it in GitHub Desktop.

Revisions

  1. techieshark created this gist Sep 25, 2023.
    11 changes: 11 additions & 0 deletions is-non-empty-string.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@

    /**
    * 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
    );
    }