Function safeParseToArray

  • Parses a multi-line string with one JSON object per line to an array of the specified type. Objects not passing the type guard are silently filtered out of the result set.

    Type Parameters

    • T

      The type of the returned objects.

    Parameters

    • guard: ((o) => o is T)

      The type predicate to validate each deserialized object.

        • (o): o is T
        • Parameters

          • o: unknown

          Returns o is T

    • text: string

      The JSON strings to parse.

    Returns T[]

    An array containing the desrialized objects passing the type guard function.