Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

turbo-stream

jacob-ebey6.4mMIT3.1.0TypeScript support: included

A streaming data transport format that aims to support built-in features such as Promises, Dates, RegExps, Maps, Sets and more.

devalue, turbo, stream, enhanced, json

readme

Turbo Stream
turbo-stream's badge

A streaming data transport format that aims to support built-in features such as Promises, Dates, RegExps, Maps, Sets and more.

Decode runtime size: turbo-stream's badge

Installation

npm install turbo-stream

Usage

import { decode, encode } from "turbo-stream";

const encodedStream = encode(Promise.resolve(42));
const decoded = await decode(encodedStream);
console.log(decoded); // 42

Benchmarks

Run them yourself with pnpm bench

• realistic payload
------------------------------------------- -------------------------------
JSON                           2.80 µs/iter   2.71 µs █▆                   
                        (2.59 µs … 5.61 µs)   5.55 µs ██                   
                    (  2.91 kb …   2.91 kb)   2.91 kb ██▁▂▁▁▁▁▁▂▁▁▁▁▁▁▁▁▁▁▂
turbo encode                  16.71 µs/iter  16.47 µs  █                   
                      (16.04 µs … 19.47 µs)  18.38 µs ███                  
                    (  2.80 kb …   2.81 kb)   2.80 kb ██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█
turbo full                    35.30 µs/iter  36.33 µs  █                   
                     (31.38 µs … 202.79 µs)  52.50 µs  █▃  ▄               
                    (  2.47 kb … 454.32 kb) 104.44 kb ▂██▃▅█▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁

                             ┌                                            ┐
                             ┬  ╷
                        JSON │──┤
                             ┴  ╵
                                         ┌┬╷
                turbo encode             ││┤
                                         └┴╵
                                                       ╷┌─┬┐              ╷
                  turbo full                           ├┤ │├──────────────┤
                                                       ╵└─┴┘              ╵
                             └                                            ┘
                             2.59 µs           27.55 µs            52.50 µs

summary
  turbo encode
   5.97x slower than JSON
   2.11x faster than turbo full

Legacy

Shout out to Rich Harris and his https://github.com/rich-harris/devalue project. Devalue has heavily influenced this project and portions of the original code was directly lifted from it. I highly recommend checking it out if you need something more cusomizable or without streaming support. This new version has been re-written from the ground up and no longer resembles devalue.

changelog

Changelog

3.1.0 (2025-02-07)

Features

  • allow for custom error redaction (#68) (e128d83)

3.0.1 (2025-02-05)

Bug Fixes

3.0.0 (2025-02-04)

⚠ BREAKING CHANGES

  • new encoding format (#59)

Features

2.4.1 (2024-09-11)

Bug Fixes

  • address memory leak caused by too many event listeners on AbortSignal (#49) (628504e)

2.4.0 (2024-08-17)

Features

  • add postPlugins for encode to handle any values that can not be handled natively or by other plugins (#47) (5fc83c8)

2.3.0 (2024-08-12)

Features

2.2.3 (2024-08-11)

Bug Fixes

  • push one value at a time to avoid stack overflows (#43) (88c51a7)

2.2.2 (2024-08-10)

Bug Fixes

  • support "infinitely" large payloads (#41) (8b602a3)

2.2.1 (2024-08-09)

Bug Fixes

  • encoding of previously-used values (#38) (84520be)

2.2.0 (2024-06-04)

Features

  • allow plugins to custom encode functions (#34) (6bd197a)

2.1.0 (2024-05-30)

Features

  • support pre resolved / rejected promises (#32) (3f15f99)

Bug Fixes

2.0.1 (2024-04-29)

Bug Fixes

  • subsequent null and undefined encoding failure (#24) (47adfe1)

2.0.0 (2024-03-06)

⚠ BREAKING CHANGES

  • add abort signal (#21)

Features

1.2.1 (2024-02-15)

Bug Fixes

1.2.0 (2023-11-01)

Features

1.1.1 (2023-11-01)

Bug Fixes

1.1.0 (2023-10-27)

Features

1.0.4 (2023-10-27)

Bug Fixes

  • add support for URL encoding and decoding (#10) (acf9ae1)

1.0.3 (2023-10-26)

Bug Fixes

1.0.2 (2023-10-26)

Bug Fixes

  • add sideEffects: false to pkg json (#6) (ad7b842)

1.0.1 (2023-10-26)

Features

  • add release pipeline to the repository (db40f74)
  • encode errors and promise rejections (fa120e9)
  • minify things (1db51bf)
  • support null prototype objects (27b3ece)

Bug Fixes

  • add repository to package.json (#4) (9ae3518)

Miscellaneous Chores

1.0.0 (2023-10-26)

Welcome to turbo-stream, a streaming data transport format that aims to support built-in features such as Promises, Dates, RegExps, Maps, Sets and more.

Shout out to Rich Harris and his https://github.com/rich-harris/devalue project. Devalue has heavily influenced this project and portions of the code have been directly lifted from it. I highly recommend checking it out if you need something more cusomizable or without streaming support.

Features

  • initial release