JS API
The package exports three filtering functions — sync, async, and stream — plus the low-level RevertedCommitsFilter class they’re built on:
import { filterRevertedCommitsSync, filterRevertedCommits, filterRevertedCommitsStream, RevertedCommitsFilter} from 'conventional-commits-filter'See Introduction for a first example.
Functions
Section titled “Functions”| Function | Signature | Description |
|---|---|---|
filterRevertedCommitsSync | (commits: Iterable) => Generator<Commit> | Filter synchronously. |
filterRevertedCommits | (commits: Iterable | AsyncIterable) => AsyncGenerator<Commit> | Async-generator function for stream.pipeline. |
filterRevertedCommitsStream | () => Transform | A Node.js Transform stream. |
filterRevertedCommits is itself the transform step — pass it to pipeline directly. filterRevertedCommitsStream is called to create a stream:
import { filterRevertedCommits, filterRevertedCommitsStream } from 'conventional-commits-filter'import { pipeline } from 'node:stream/promises'
await pipeline(commits, filterRevertedCommits, collect)
commitsStream.pipe(filterRevertedCommitsStream())What counts as a revert
Section titled “What counts as a revert”A commit is treated as a revert when it has a truthy revert object — set by conventional-commits-parser from its revertPattern. The filter holds each revert and drops a later commit when every field of the revert’s revert object matches that commit (its raw form when present) — in practice the header and hash. When matched, both the revert and the reverted commit are removed.
RevertedCommitsFilter
Section titled “RevertedCommitsFilter”The stateful class behind the functions, for custom pipelines. Feed commits one at a time to process() — it yields the commits that survive so far — then call flush() at the end to emit any it was still holding:
import { RevertedCommitsFilter } from 'conventional-commits-filter'
const filter = new RevertedCommitsFilter()const kept = []
for (const commit of commits) { kept.push(...filter.process(commit))}
kept.push(...filter.flush())| Method | Description |
|---|---|
process(commit) | Generator that yields the currently-surviving commits after taking commit into account. |
flush() | Generator that yields any commits still held once the input is exhausted. |