Web streams utils - v0.3.0
    Preparing search index...

    Function compact

    • Remove null and undefined values from a stream

      Type Parameters

      • T

      Returns TransformStream<T, NonNullable<T>>

      A TransformStream that filters out null and undefined values

      const readable = new ReadableStream({
      start(controller) {
      const items = [1, null, 2, undefined, 3]
      items.forEach(item => {
      controller.enqueue(item)
      })
      }
      })
      const stream = readable.pipeThrough(compact());
      // If readable emits [1, null, 2, undefined, 3], the result will be [1, 2, 3]