• 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

36.51
/modules/csv/src/lib/encoders/encode-csv.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 {Table} from '@loaders.gl/schema';
1✔
7
import {makeArrayRowIterator, getTableNumCols} from '@loaders.gl/schema-utils';
1✔
8
import {csvFormatRows} from 'd3-dsv';
1✔
9
import type {CSVWriterOptions} from '../../csv-writer';
1✔
10

1✔
11
type EncodableData = string | null;
1✔
12

1✔
13
/**
1✔
14
 * Encode a Table object as CSV
1✔
15
 */
1✔
16
export function encodeTableAsCSV(
1✔
UNCOV
17
  table: Table,
×
UNCOV
18
  options: CSVWriterOptions = {csv: {useDisplayNames: true}}
×
UNCOV
19
): string {
×
UNCOV
20
  const useDisplayNames = options.useDisplayNames || options.csv?.useDisplayNames;
×
UNCOV
21

×
UNCOV
22
  const fields = table.schema?.fields || [];
×
UNCOV
23

×
UNCOV
24
  const columnNames = fields.map((f) => {
×
UNCOV
25
    // This is a leaky abstraction, assuming Kepler metadata
×
UNCOV
26
    const displayName = f.metadata?.displayName;
×
UNCOV
27
    return useDisplayNames && typeof displayName === 'string' ? displayName : f.name;
×
UNCOV
28
  });
×
UNCOV
29
  const formattedData: EncodableData[][] = [columnNames];
×
UNCOV
30

×
UNCOV
31
  for (const row of makeArrayRowIterator(table)) {
×
UNCOV
32
    const formattedRow: EncodableData[] = [];
×
UNCOV
33
    for (let columnIndex = 0; columnIndex < getTableNumCols(table); ++columnIndex) {
×
UNCOV
34
      const value = row[columnIndex];
×
UNCOV
35
      formattedRow[columnIndex] = preformatFieldValue(value);
×
UNCOV
36
    }
×
UNCOV
37
    formattedData.push(formattedRow);
×
UNCOV
38
  }
×
UNCOV
39

×
UNCOV
40
  return csvFormatRows(formattedData);
×
UNCOV
41
}
×
42

1✔
43
/**
1✔
44
 * Stringifies a value
1✔
45
 * @todo Why is it called parse?
1✔
46
 */
1✔
47
const preformatFieldValue = (value: unknown): EncodableData => {
1✔
UNCOV
48
  if (value === null || value === undefined) {
×
UNCOV
49
    // TODO: It would be nice to distinguish between missing values and the empty string
×
UNCOV
50
    // https://github.com/d3/d3-dsv/issues/84
×
UNCOV
51
    return null;
×
UNCOV
52
  }
×
UNCOV
53
  if (value instanceof Date) {
×
UNCOV
54
    // d3-dsv formats dates without timezones if they don't have time info;
×
UNCOV
55
    // this forces them to always use fully-qualified ISO time strings
×
UNCOV
56
    return value.toISOString();
×
UNCOV
57
  }
×
UNCOV
58
  if (typeof value === 'object') {
×
59
    return JSON.stringify(value);
×
60
  }
×
UNCOV
61
  return String(value);
×
UNCOV
62
};
×
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