• 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

31.94
/modules/json/src/lib/encoder-utils/encode-table-row.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4
// Copyright 2022 Foursquare Labs, Inc.
1✔
5

1✔
6
import type {Feature, Table} from '@loaders.gl/schema';
1✔
7
import {getTableRowAsObject} from '@loaders.gl/schema-utils';
1✔
8
import {getRowPropertyObject} from './encode-utils';
1✔
9
import {Utf8ArrayBufferEncoder} from './utf8-encoder';
1✔
10

1✔
11
type Row = {[key: string]: unknown};
1✔
12

1✔
13
// Helpers
1✔
14

1✔
15
/**
1✔
16
 * Encode a row. Currently this ignores properties in the geometry column.
1✔
17
 */
1✔
18
export function encodeTableRow(
1✔
UNCOV
19
  table: Table,
×
UNCOV
20
  rowIndex: number,
×
UNCOV
21
  geometryColumnIndex: number,
×
UNCOV
22
  utf8Encoder: Utf8ArrayBufferEncoder
×
UNCOV
23
): void {
×
UNCOV
24
  const row = getTableRowAsObject(table, rowIndex);
×
UNCOV
25
  if (!row) return;
×
UNCOV
26
  const featureWithProperties = getFeatureFromRow(table, row, geometryColumnIndex);
×
UNCOV
27
  const featureString = JSON.stringify(featureWithProperties);
×
UNCOV
28
  utf8Encoder.push(featureString);
×
UNCOV
29
}
×
30

1✔
31
/**
1✔
32
 * Encode a row as a Feature. Currently this ignores properties objects in the geometry column.
1✔
33
 */
1✔
UNCOV
34
function getFeatureFromRow(table: Table, row: Row, geometryColumnIndex: number): Feature {
×
UNCOV
35
  // Extract non-feature/geometry properties
×
UNCOV
36
  const properties = getRowPropertyObject(table, row, [geometryColumnIndex]);
×
UNCOV
37

×
UNCOV
38
  // Extract geometry feature
×
UNCOV
39
  const columnName = table.schema?.fields[geometryColumnIndex].name;
×
UNCOV
40
  let featureOrGeometry =
×
UNCOV
41
    columnName && (row[columnName] as {[key: string]: unknown} | string | null | undefined);
×
UNCOV
42

×
UNCOV
43
  // GeoJSON support null geometries
×
UNCOV
44
  if (!featureOrGeometry) {
×
UNCOV
45
    // @ts-ignore Feature type does not support null geometries
×
UNCOV
46
    return {type: 'Feature', geometry: null, properties};
×
UNCOV
47
  }
×
UNCOV
48

×
UNCOV
49
  // Support string geometries?
×
UNCOV
50
  // TODO: This assumes GeoJSON strings, which may not be the correct format
×
UNCOV
51
  // (could be WKT, encoded WKB...)
×
UNCOV
52
  if (typeof featureOrGeometry === 'string') {
×
UNCOV
53
    try {
×
UNCOV
54
      featureOrGeometry = JSON.parse(featureOrGeometry);
×
UNCOV
55
    } catch (err) {
×
56
      throw new Error('Invalid string geometry');
×
57
    }
×
UNCOV
58
  }
×
UNCOV
59

×
UNCOV
60
  if (typeof featureOrGeometry !== 'object' || typeof featureOrGeometry?.type !== 'string') {
×
61
    throw new Error('invalid geometry column value');
×
62
  }
×
UNCOV
63

×
UNCOV
64
  if (featureOrGeometry?.type === 'Feature') {
×
UNCOV
65
    // @ts-ignore Feature type does not support null geometries
×
UNCOV
66
    return {...featureOrGeometry, properties};
×
UNCOV
67
  }
×
68

×
69
  // @ts-ignore Feature type does not support null geometries
×
70
  return {type: 'Feature', geometry: featureOrGeometry, properties};
×
71
}
×
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