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

juanjoDiaz / streamparser-json / 8943701405

03 May 2024 07:05PM UTC coverage: 98.296% (-0.1%) from 98.433%
8943701405

push

github

juanjoDiaz
chore: bump version number

441 of 452 branches covered (97.57%)

Branch coverage included in aggregate %.

828 of 839 relevant lines covered (98.69%)

61755391.58 hits per line

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

58.33
/packages/node/src/tokenparser.ts
1
import {
84✔
2
  Transform,
3
  type TransformOptions,
4
  type TransformCallback,
5
} from "stream";
6
import { TokenParser, type TokenParserOptions } from "@streamparser/json";
84✔
7

8
export default class TokenParserTransform extends Transform {
84✔
9
  private tokenParser: TokenParser;
10

11
  constructor(
12
    opts: TokenParserOptions = {},
×
13
    transformOpts: Omit<
4✔
14
      TransformOptions,
15
      "readableObjectMode" | "writableObjectMode"
16
    > = {},
17
  ) {
18
    super({
12✔
19
      ...transformOpts,
20
      writableObjectMode: true,
21
      readableObjectMode: true,
22
    });
23
    this.tokenParser = new TokenParser(opts);
12✔
24

25
    this.tokenParser.onValue = (parsedTokenInfo) => this.push(parsedTokenInfo);
12✔
26
    this.tokenParser.onError = (err) => {
12✔
27
      throw err;
12✔
28
    };
29
    this.tokenParser.onEnd = () => {
12✔
30
      if (!this.writableEnded) this.end();
×
31
    };
32
  }
33

34
  /**
35
   * Main function that send data to the parser to be processed.
36
   *
37
   * @param {Buffer} chunk Incoming data
38
   * @param {String} encoding Encoding of the incoming data. Defaults to 'utf8'
39
   * @param {Function} done Called when the proceesing of the supplied chunk is done
40
   */
41
  override _transform(
42
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
    chunk: any,
44
    encoding: BufferEncoding,
45
    done: TransformCallback,
46
  ): void {
47
    try {
24✔
48
      this.tokenParser.write(chunk);
24✔
49
      done();
12✔
50
    } catch (err: unknown) {
51
      done(err as Error);
12✔
52
    }
53
  }
54

55
  override _final(callback: (error?: Error | null) => void): void {
56
    try {
×
57
      if (!this.tokenParser.isEnded) this.tokenParser.end();
×
58
      callback();
×
59
    } catch (err: unknown) {
60
      callback(err as Error);
×
61
    }
62
  }
63
}
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

© 2026 Coveralls, Inc