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

C2FO / fast-csv / 13550863665

26 Feb 2025 06:30PM CUT coverage: 95.907%. Remained the same
13550863665

Pull #1101

github

web-flow
Merge 78434839f into 947bf442a
Pull Request #1101: chore(deps): update node.js to v22

325 of 353 branches covered (92.07%)

Branch coverage included in aggregate %.

753 of 771 relevant lines covered (97.67%)

2176197.34 hits per line

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

93.55
/packages/parse/src/parser/Scanner.ts
1
import { ParserOptions } from '../ParserOptions';
2
import { MaybeToken, Token } from './Token';
144✔
3

4
const ROW_DELIMITER = /((?:\r\n)|\n|\r)/;
144✔
5

6
export interface ScannerArgs {
7
    line: string;
8
    parserOptions: ParserOptions;
9
    hasMoreData: boolean;
10
    cursor?: number;
11
}
12

13
export class Scanner {
144✔
14
    public line: string;
15

16
    private readonly parserOptions: ParserOptions;
17

18
    public lineLength: number;
19

20
    public readonly hasMoreData: boolean;
21

22
    public cursor = 0;
3,540✔
23

24
    public constructor(args: ScannerArgs) {
25
        this.line = args.line;
3,540✔
26
        this.lineLength = this.line.length;
3,540✔
27
        this.parserOptions = args.parserOptions;
3,540✔
28
        this.hasMoreData = args.hasMoreData;
3,540✔
29
        this.cursor = args.cursor || 0;
3,540✔
30
    }
31

32
    public get hasMoreCharacters(): boolean {
33
        return this.lineLength > this.cursor;
10,575,048✔
34
    }
35

36
    public get nextNonSpaceToken(): MaybeToken {
37
        const { lineFromCursor } = this;
12,721,266✔
38
        const regex = this.parserOptions.NEXT_TOKEN_REGEXP;
12,721,266✔
39
        if (lineFromCursor.search(regex) === -1) {
12,721,266✔
40
            return null;
3,372✔
41
        }
42
        const match = regex.exec(lineFromCursor);
12,717,894✔
43
        if (match == null) {
12,717,894!
44
            return null;
×
45
        }
46
        const token = match[1];
12,717,894✔
47
        const startCursor = this.cursor + (match.index || 0);
12,717,894✔
48
        return new Token({
12,717,894✔
49
            token,
50
            startCursor,
51
            endCursor: startCursor + token.length - 1,
52
        });
53
    }
54

55
    public get nextCharacterToken(): MaybeToken {
56
        const { cursor, lineLength } = this;
93,409,602✔
57
        if (lineLength <= cursor) {
93,409,602✔
58
            return null;
2,958✔
59
        }
60
        return new Token({
93,406,644✔
61
            token: this.line[cursor],
62
            startCursor: cursor,
63
            endCursor: cursor,
64
        });
65
    }
66

67
    public get lineFromCursor(): string {
68
        return this.line.substr(this.cursor);
13,455,144✔
69
    }
70

71
    public advancePastLine(): Scanner | null {
72
        const match = ROW_DELIMITER.exec(this.lineFromCursor);
246✔
73
        if (!match) {
246✔
74
            if (this.hasMoreData) {
198✔
75
                return null;
18✔
76
            }
77
            this.cursor = this.lineLength;
180✔
78
            return this;
180✔
79
        }
80
        this.cursor += (match.index || 0) + match[0].length;
48!
81
        return this;
48✔
82
    }
83

84
    public advanceTo(cursor: number): Scanner {
85
        this.cursor = cursor;
282✔
86
        return this;
282✔
87
    }
88

89
    public advanceToToken(token: Token): Scanner {
90
        this.cursor = token.startCursor;
1,349,994✔
91
        return this;
1,349,994✔
92
    }
93

94
    public advancePastToken(token: Token): Scanner {
95
        this.cursor = token.endCursor + 1;
88,896,396✔
96
        return this;
88,896,396✔
97
    }
98

99
    public truncateToCursor(): Scanner {
100
        this.line = this.lineFromCursor;
732,984✔
101
        this.lineLength = this.line.length;
732,984✔
102
        this.cursor = 0;
732,984✔
103
        return this;
732,984✔
104
    }
105
}
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