Function isStringAnd

  • Executes a type guard for the string type prior to testing a condition that requires an input of string type, returning true only if both the type check and condition pass.

    Remarks

    This is especially useful in pipelines where the TS type checker would not detect that a type guard had been applied using other alternatives.

    Example

    import * as G from "flurp/guard";
    import * as L from "flurp/logic";
    import * as S from "flurp/string";

    const goodStartW = G.isStringAnd(S.startsWith("w"));
    goodStartW("weasel"); // true
    goodStartW("a weasel"); // false
    goodStartW(/a weasel/); // false

    const badStartW = L.both(G.isString, S.startsWith("w"));
    badStartW(/a weasel/); // TS compiler will not recognize G.isString as a type guard.

    Type Parameters

    • T

    Parameters

    • condition: ((x: string) => boolean)
        • (x: string): boolean
        • Parameters

          • x: string

          Returns boolean

    Returns ((x: T) => boolean)

      • (x: T): boolean
      • Parameters

        • x: T

        Returns boolean