https://github.com/milly/ts-streams
Typescript modules that provides utilities for Streams API. Like RXJS.
https://github.com/milly/ts-streams
Last synced: 9 months ago
JSON representation
Typescript modules that provides utilities for Streams API. Like RXJS.
- Host: GitHub
- URL: https://github.com/milly/ts-streams
- Owner: Milly
- License: mit
- Created: 2024-05-17T09:37:37.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-07-04T01:07:24.000Z (11 months ago)
- Last Synced: 2025-09-06T21:26:26.810Z (9 months ago)
- Language: TypeScript
- Homepage: https://jsr.io/@milly/streams
- Size: 254 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# streams
[](LICENSE)
[](https://jsr.io/@milly/streams)
[](https://github.com/Milly/ts-streams/actions/workflows/test.yml)
[](https://codecov.io/gh/Milly/ts-streams)
TypeScript modules that provides utilities for
[Streams API](https://developer.mozilla.org/docs/Web/API/Streams_API).
## Example
```typescript
import { from } from "@milly/streams/readable/from";
import { fromMessage } from "@milly/streams/readable/from-message";
import { switchMap } from "@milly/streams/transform/switch-map";
import { take } from "@milly/streams/transform/take";
import { forEach } from "@milly/streams/writable/for-each";
import { postMessage } from "@milly/streams/writable/post-message";
import { assertEquals } from "@std/assert";
async function* gen() {
yield 1;
await Promise.resolve();
yield "foo";
await Promise.resolve();
yield true;
}
const { port1, port2 } = new MessageChannel();
from(gen())
.pipeThrough(switchMap((chunk) => [chunk, typeof chunk]))
.pipeTo(postMessage(port1))
.finally(() => port1.close());
const result: unknown[] = [];
await fromMessage(port2)
.pipeThrough(take(6))
.pipeTo(forEach((chunk) => {
result.push(chunk);
}))
.finally(() => port2.close());
assertEquals(result, [
1,
"number",
"foo",
"string",
true,
"boolean",
]);
```
## License
This library is licensed under the MIT License. See the [LICENSE](./LICENSE)
file for details.