• 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

59.2
/modules/tiles/src/utils/managed-array.ts
1
// This file is derived from the Cesium code base under Apache 2 license
1✔
2
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
1✔
3

1✔
4
import {assert} from '@loaders.gl/loader-utils';
1✔
5

1✔
6
/**
1✔
7
 * A wrapper around arrays so that the internal length of the array can be manually managed.
1✔
8
 *
1✔
9
 * @alias ManagedArray
1✔
10
 * @constructor
1✔
11
 * @private
1✔
12
 *
1✔
13
 * @param {Number} [length=0] The initial length of the array.
1✔
14
 */
1✔
15
export class ManagedArray {
1✔
16
  _map = new Map();
1!
UNCOV
17
  _array: any[];
×
UNCOV
18
  _length: number;
×
19

1✔
20
  constructor(length = 0) {
1✔
UNCOV
21
    this._array = new Array(length);
×
UNCOV
22
    this._length = length;
×
UNCOV
23
  }
×
24

1✔
25
  /**
1✔
26
   * Gets or sets the length of the array.
1✔
27
   * If the set length is greater than the length of the internal array, the internal array is resized.
1✔
28
   *
1✔
29
   * @memberof ManagedArray.prototype
1✔
30
   * @type Number
1✔
31
   */
1✔
32
  get length() {
1✔
UNCOV
33
    return this._length;
×
UNCOV
34
  }
×
35

1✔
36
  set length(length) {
1✔
UNCOV
37
    this._length = length;
×
UNCOV
38
    if (length > this._array.length) {
×
UNCOV
39
      this._array.length = length;
×
UNCOV
40
    }
×
UNCOV
41
  }
×
42

1✔
43
  /**
1✔
44
   * Gets the internal array.
1✔
45
   *
1✔
46
   * @memberof ManagedArray.prototype
1✔
47
   * @type Array
1✔
48
   * @readonly
1✔
49
   */
1✔
50
  get values() {
1✔
51
    return this._array;
×
52
  }
×
53

1✔
54
  /**
1✔
55
   * Gets the element at an index.
1✔
56
   *
1✔
57
   * @param {Number} index The index to get.
1✔
58
   */
1✔
59
  get(index) {
1✔
60
    assert(index < this._array.length);
×
61
    return this._array[index];
×
62
  }
×
63

1✔
64
  /**
1✔
65
   * Sets the element at an index. Resizes the array if index is greater than the length of the array.
1✔
66
   *
1✔
67
   * @param {Number} index The index to set.
1✔
68
   * @param {*} element The element to set at index.
1✔
69
   */
1✔
70
  set(index, element) {
1✔
71
    assert(index >= 0);
×
72

×
73
    if (index >= this.length) {
×
74
      this.length = index + 1;
×
75
    }
×
76

×
77
    if (this._map.has(this._array[index])) {
×
78
      this._map.delete(this._array[index]);
×
79
    }
×
80

×
81
    this._array[index] = element;
×
82
    this._map.set(element, index);
×
83
  }
×
84

1✔
85
  delete(element) {
1✔
86
    const index = this._map.get(element);
×
87
    if (index >= 0) {
×
88
      this._array.splice(index, 1);
×
89
      this._map.delete(element);
×
90
      this.length--;
×
91
    }
×
92
  }
×
93

1✔
94
  /**
1✔
95
   * Returns the last element in the array without modifying the array.
1✔
96
   *
1✔
97
   * @returns {*} The last element in the array.
1✔
98
   */
1✔
99
  peek() {
1✔
100
    return this._array[this._length - 1];
×
101
  }
×
102

1✔
103
  /**
1✔
104
   * Push an element into the array.
1✔
105
   *
1✔
106
   * @param {*} element The element to push.
1✔
107
   */
1✔
108
  push(element) {
1✔
UNCOV
109
    if (!this._map.has(element)) {
×
UNCOV
110
      const index = this.length++;
×
UNCOV
111
      this._array[index] = element;
×
UNCOV
112
      this._map.set(element, index);
×
UNCOV
113
    }
×
UNCOV
114
  }
×
115

1✔
116
  /**
1✔
117
   * Pop an element from the array.
1✔
118
   *
1✔
119
   * @returns {*} The last element in the array.
1✔
120
   */
1✔
121
  pop() {
1✔
UNCOV
122
    const element = this._array[--this.length];
×
UNCOV
123
    this._map.delete(element);
×
UNCOV
124
    return element;
×
UNCOV
125
  }
×
126

1✔
127
  /**
1✔
128
   * Resize the internal array if length > _array.length.
1✔
129
   *
1✔
130
   * @param {Number} length The length.
1✔
131
   */
1✔
132
  reserve(length) {
1✔
133
    assert(length >= 0);
×
134

×
135
    if (length > this._array.length) {
×
136
      this._array.length = length;
×
137
    }
×
138
  }
×
139

1✔
140
  /**
1✔
141
   * Resize the array.
1✔
142
   *
1✔
143
   * @param {Number} length The length.
1✔
144
   */
1✔
145
  resize(length) {
1✔
146
    assert(length >= 0);
×
147

×
148
    this.length = length;
×
149
  }
×
150

1✔
151
  /**
1✔
152
   * Trim the internal array to the specified length. Defaults to the current length.
1✔
153
   *
1✔
154
   * @param {Number} [length] The length.
1✔
155
   */
1✔
156
  trim(length) {
1✔
157
    if (length === null || length === undefined) {
×
158
      length = this.length;
×
159
    }
×
160
    this._array.length = length;
×
161
  }
×
162

1✔
163
  reset() {
1✔
UNCOV
164
    this._array = [];
×
UNCOV
165
    this._map = new Map();
×
UNCOV
166
    this._length = 0;
×
UNCOV
167
  }
×
168

1✔
169
  find(target) {
1✔
170
    return this._map.has(target);
×
171
  }
×
172
}
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