Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 11 additions & 53 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches: [ master, develop ]

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -33,18 +36,20 @@ jobs:
npm list mocha c8 @types/mocha --depth=0

- name: Run Node.js tests
run: npm test
run: npm run test:node

- name: Run tests with coverage
if: matrix.node-version == '22.x'
run: npm run test:cover
run: npm test

- name: Upload coverage artifacts
- name: Upload coverage to Codecov
if: matrix.node-version == '22.x'
uses: actions/upload-artifact@v4
uses: codecov/codecov-action@v4
with:
name: coverage-report
path: coverage/lcov-report/
file: ./coverage/lcov.info
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false

browser-test-chromium:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -120,50 +125,3 @@ jobs:

- name: Run WebKit browser tests
run: npm run test:browser:webkit

coverage-summary:
runs-on: ubuntu-latest
needs: [test, browser-test-chromium, browser-test-firefox, browser-test-webkit]
if: |
github.ref == 'refs/heads/master' &&
github.event_name == 'push' &&
needs.test.result == 'success' &&
needs.browser-test-chromium.result == 'success' &&
needs.browser-test-firefox.result == 'success' &&
needs.browser-test-webkit.result == 'success'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests with coverage
run: npm run test:cover

- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-report-final
path: coverage/lcov-report/

- name: Coverage badge data
run: |
COVERAGE_PERCENT=$(grep -oP 'lines\.*:\s*\K[\d.]+' coverage/lcov.info | tail -1)
echo "Coverage: ${COVERAGE_PERCENT}%"
echo "COVERAGE_PERCENT=${COVERAGE_PERCENT}" >> $GITHUB_ENV

- name: Deploy coverage to GitHub Pages
if: github.ref == 'refs/heads/master'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./coverage/lcov-report
destination_dir: coverage
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@

# Make sure to include the entire dist directory
!dist/**/*

*.map
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
[![npm version](https://img.shields.io/npm/v/web-streams-extensions.svg)](https://www.npmjs.com/package/web-streams-extensions)
[![npm beta](https://img.shields.io/npm/v/web-streams-extensions/beta.svg?label=npm%20beta)](https://www.npmjs.com/package/web-streams-extensions)
[![Build Status](https://github.com/MeirionHughes/web-streams-extensions/workflows/Test%20and%20Coverage/badge.svg)](https://github.com/MeirionHughes/web-streams-extensions/actions)
[![Coverage](https://img.shields.io/endpoint?url=https://meirionhughes.github.io/web-streams-extensions/coverage.json)](https://meirionhughes.github.io/web-streams-extensions/coverage/)
[![codecov](https://codecov.io/gh/MeirionHughes/web-streams-extensions/branch/master/graph/badge.svg)](https://codecov.io/gh/MeirionHughes/web-streams-extensions)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
[![Node.js](https://img.shields.io/badge/Node.js-18%2B-green.svg)](https://nodejs.org/)
[![ES2022](https://img.shields.io/badge/ECMAScript-ES2022-blueviolet.svg)](https://tc39.es/ecma262/)

A collection of predominantly Object-Mode helper methods for WebStreams, inspired by ReactiveExtensions.
Being built on-top of ReadableStream, we can have a reactive pipeline with **non-blocking back-pressure** built-in.
A collection helper methods for WebStreams, inspired by ReactiveExtensions.

## Contributing

Expand Down Expand Up @@ -39,6 +39,42 @@ const result = await toArray(stream);
console.log(result); // [4, 8, 12]
```

### Native Web Streams API

A few notes on using the native Web Streams primitives alongside this library:

- piping: The standard `.pipeTo()` and `.pipeThrough()` are available on `ReadableStream`. Use `pipe()` from this library when you want to compose operators in a functional style (it returns a `ReadableStream`).

- Async iteration: Readable streams are async-iterable. You can iterate values with `for await (const chunk of stream)` to consume values one-by-one.

Examples:

```ts
// Using native async iteration
for await (const v of of('a', 'b', 'c')) {
console.log(v);
}

// Use pipeTo when piping to a writable stream (native API)
await from(['a', 'b', 'c'])
.pipeTo(new WritableStream({
write(chunk) { /* ... */ }
}));

// Use pipeThrough if you want to use a native transform

of(1,2,3)
.pipeThrough(new TransformStream({
transform(value, controller){
controller.enqueue(value);
}
}))
.pipeTo(writable);

```

⚠️ReadableStreams are not recoverable. If you start and consume a stream, that instance cannot be reused.

## API Reference Quick Index

### Creation Functions
Expand Down Expand Up @@ -125,6 +161,8 @@ console.log(result); // [4, 8, 12]
- `BehaviourSubject<T>` - Subject that remembers last value
- `ReplaySubject<T>` - Subject that replays buffered values to new subscribers

## Native Stream API



## Creation
Expand Down
Loading