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

visgl / loaders.gl / 20352515932

18 Dec 2025 09:56PM UTC coverage: 35.115% (-28.4%) from 63.485%
20352515932

push

github

web-flow
feat(loader-utils): Export is-type helpers (#3258)

1188 of 1998 branches covered (59.46%)

Branch coverage included in aggregate %.

147 of 211 new or added lines in 13 files covered. (69.67%)

30011 existing lines in 424 files now uncovered.

37457 of 108056 relevant lines covered (34.66%)

0.79 hits per line

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

40.35
/modules/json/src/lib/json-parser/streaming-json-parser.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
import {default as JSONParser} from './json-parser';
1✔
6
import JSONPath from '../jsonpath/jsonpath';
1✔
7

1✔
8
/**
1✔
9
 * The `StreamingJSONParser` looks for the first array in the JSON structure.
1✔
10
 * and emits an array of chunks
1✔
11
 */
1✔
12
export default class StreamingJSONParser extends JSONParser {
1✔
13
  private jsonPaths: JSONPath[];
1!
UNCOV
14
  private streamingJsonPath: JSONPath | null = null;
×
UNCOV
15
  private streamingArray: any[] | null = null;
×
UNCOV
16
  private topLevelObject: object | null = null;
×
17

1✔
18
  constructor(options: {[key: string]: any} = {}) {
1✔
UNCOV
19
    super({
×
UNCOV
20
      onopenarray: () => {
×
UNCOV
21
        if (!this.streamingArray) {
×
UNCOV
22
          if (this._matchJSONPath()) {
×
UNCOV
23
            // @ts-ignore
×
UNCOV
24
            this.streamingJsonPath = this.getJsonPath().clone();
×
UNCOV
25
            this.streamingArray = [];
×
UNCOV
26
            this._openArray(this.streamingArray as []);
×
UNCOV
27
            return;
×
UNCOV
28
          }
×
UNCOV
29
        }
×
UNCOV
30

×
UNCOV
31
        this._openArray();
×
UNCOV
32
      },
×
UNCOV
33

×
UNCOV
34
      // Redefine onopenarray to inject value for top-level object
×
UNCOV
35
      onopenobject: (name) => {
×
UNCOV
36
        if (!this.topLevelObject) {
×
UNCOV
37
          this.topLevelObject = {};
×
UNCOV
38
          this._openObject(this.topLevelObject);
×
UNCOV
39
        } else {
×
UNCOV
40
          this._openObject({});
×
UNCOV
41
        }
×
UNCOV
42
        if (typeof name !== 'undefined') {
×
UNCOV
43
          this.parser.emit('onkey', name);
×
UNCOV
44
        }
×
UNCOV
45
      }
×
UNCOV
46
    });
×
UNCOV
47
    const jsonpaths = options.jsonpaths || [];
×
UNCOV
48
    this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));
×
UNCOV
49
  }
×
50

1✔
51
  /**
1✔
52
   * write REDEFINITION
1✔
53
   * - super.write() chunk to parser
1✔
54
   * - get the contents (so far) of "topmost-level" array as batch of rows
1✔
55
   * - clear top-level array
1✔
56
   * - return the batch of rows\
1✔
57
   */
1✔
58
  write(chunk) {
1✔
UNCOV
59
    super.write(chunk);
×
UNCOV
60
    let array: any[] = [];
×
UNCOV
61
    if (this.streamingArray) {
×
UNCOV
62
      array = [...this.streamingArray];
×
UNCOV
63
      this.streamingArray.length = 0;
×
UNCOV
64
    }
×
UNCOV
65
    return array;
×
UNCOV
66
  }
×
67

1✔
68
  /**
1✔
69
   * Returns a partially formed result object
1✔
70
   * Useful for returning the "wrapper" object when array is not top level
1✔
71
   * e.g. GeoJSON
1✔
72
   */
1✔
73
  getPartialResult() {
1✔
UNCOV
74
    return this.topLevelObject;
×
UNCOV
75
  }
×
76

1✔
77
  getStreamingJsonPath() {
1✔
78
    return this.streamingJsonPath;
×
79
  }
×
80

1✔
81
  getStreamingJsonPathAsString() {
1✔
UNCOV
82
    return this.streamingJsonPath && this.streamingJsonPath.toString();
×
UNCOV
83
  }
×
84

1✔
85
  getJsonPath() {
1✔
UNCOV
86
    return this.jsonpath;
×
UNCOV
87
  }
×
88

1✔
89
  // PRIVATE METHODS
1✔
90

1✔
91
  /**
1✔
92
   * Checks is this.getJsonPath matches the jsonpaths provided in options
1✔
93
   */
1✔
94
  _matchJSONPath() {
1✔
UNCOV
95
    const currentPath = this.getJsonPath();
×
UNCOV
96
    // console.debug(`Testing JSONPath`, currentPath);
×
UNCOV
97

×
UNCOV
98
    // Backwards compatibility, match any array
×
UNCOV
99
    // TODO implement using wildcard once that is supported
×
UNCOV
100
    if (this.jsonPaths.length === 0) {
×
UNCOV
101
      return true;
×
UNCOV
102
    }
×
UNCOV
103

×
UNCOV
104
    for (const jsonPath of this.jsonPaths) {
×
UNCOV
105
      if (jsonPath.equals(currentPath)) {
×
UNCOV
106
        return true;
×
UNCOV
107
      }
×
UNCOV
108
    }
×
UNCOV
109

×
UNCOV
110
    return false;
×
UNCOV
111
  }
×
112
}
1✔
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