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

lad-tech / toolbelt / 4483370358

pending completion
4483370358

push

github

GitHub
7 fix lib (#8)

106 of 107 branches covered (99.07%)

Branch coverage included in aggregate %.

133 of 133 relevant lines covered (100.0%)

10.99 hits per line

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

100.0
/src/logs/input-parser.ts
1
import { tryToStringifyJSON } from '../util/json';
3✔
2
import { isBoolean, isNumber, isString } from '../util/predicates';
3✔
3

4
export type SuccessParseResult = { success: boolean; value: string };
5
export type FailParseResult = { success: false };
6
export type ParseResult = SuccessParseResult | FailParseResult;
7

8
export interface InputParser {
9
  tryToParse(input: unknown): ParseResult;
10
}
11

12
export default class DefaultInputParser implements InputParser {
3✔
13
  public tryToParse(input: unknown): ParseResult {
14
    if (input instanceof Error) {
47✔
15
      return this.success(input.message);
21✔
16
    }
17

18
    if (isNumber(input) || isBoolean(input)) {
26✔
19
      return this.success(input.toString());
2✔
20
    }
21

22
    if (isString(input)) {
24✔
23
      return this.success(input);
21✔
24
    }
25

26
    const result = tryToStringifyJSON(input);
3✔
27

28
    if (result) {
3✔
29
      return this.success(result);
1✔
30
    }
31

32
    return this.fail();
2✔
33
  }
34

35
  private success(value: string): SuccessParseResult {
36
    return { success: true, value };
45✔
37
  }
38

39
  private fail(): FailParseResult {
40
    return { success: false };
2✔
41
  }
42
}
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