• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

streetsidesoftware / cspell / 8745810937

18 Apr 2024 11:05PM UTC coverage: 93.481% (+0.02%) from 93.46%
8745810937

Pull #5502

github

web-flow
Merge 53f2b8079 into c515cc91c
Pull Request #5502: chore: Add lint rules

6439 of 7332 branches covered (87.82%)

126 of 144 new or added lines in 68 files covered. (87.5%)

3 existing lines in 3 files now uncovered.

13192 of 14112 relevant lines covered (93.48%)

23103.11 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/packages/hunspell-reader/src/iterableToStream.ts
1
import * as stream from 'node:stream';
2

3
// cspell:words streamable
4

5
export type Streamable = string | Buffer;
6

7
export type IterableLike<T> = Iterable<T> | IterableIterator<T>;
8

9
/**
10
 * Transform an iterable into a node readable stream.
11
 */
12
export function iterableToStream<T extends Streamable>(
13
    src: IterableLike<T>,
14
    options?: stream.ReadableOptions,
15
): stream.Readable {
NEW
16
    return new ReadableObservableStream(src, options ?? { encoding: 'utf8' });
×
17
}
18

19
class ReadableObservableStream<T> extends stream.Readable {
20
    private iter: Iterator<T> | undefined;
21
    private done = false;
×
22

23
    constructor(
24
        private _source: IterableLike<T>,
×
25
        options: stream.ReadableOptions,
26
    ) {
27
        super(options);
×
28
    }
29

30
    _read() {
31
        if (!this.iter) {
×
32
            this.iter = this._source[Symbol.iterator]();
×
33
        }
34
        if (this.done) {
×
35
            // See: https://nodejs.org/api/stream.html#readablepushchunk-encoding
36
            // Pushing null means the stream is done.
37
            // eslint-disable-next-line unicorn/no-null
38
            this.push(null);
×
39
            return;
×
40
        }
41

42
        let r = this.iter.next();
×
43
        while (!r.done && this.push(r.value)) {
×
44
            r = this.iter.next();
×
45
        }
46
        if (r.done) {
×
47
            this.done = true;
×
48
            // since it is possible for r.value to have something meaningful, we must check.
49
            if (r.value !== null && r.value !== undefined) {
×
50
                this.push(r.value);
×
51
            }
52
            // See: https://nodejs.org/api/stream.html#readablepushchunk-encoding
53
            // Pushing null means the stream is done.
54
            // eslint-disable-next-line unicorn/no-null
UNCOV
55
            this.push(null);
×
56
        }
57
    }
58
}
59

60
export default iterableToStream;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc