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

visgl / loaders.gl / 25070233425

28 Apr 2026 06:20PM UTC coverage: 59.434% (+0.01%) from 59.423%
25070233425

push

github

web-flow
website: Add tabs for navigating between format docs (#3407)

11310 of 20887 branches covered (54.15%)

Branch coverage included in aggregate %.

89 of 136 new or added lines in 13 files covered. (65.44%)

1742 existing lines in 132 files now uncovered.

23500 of 37682 relevant lines covered (62.36%)

16296.63 hits per line

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

83.33
/modules/core/src/lib/api/load.ts
1
// loaders.gl
2
// SPDX-License-Identifier: MIT
3
// Copyright (c) vis.gl contributors
4

5
import type {
6
  DataType,
7
  Loader,
8
  LoaderContext,
9
  LoaderOptions,
10
  LoaderOptionsWithShape,
11
  LoaderOptionsType,
12
  LoaderShapeType,
13
  LoaderReturnType,
14
  LoaderArrayOptionsType,
15
  LoaderArrayReturnType,
16
  SourceLoader
17
} from '@loaders.gl/loader-utils';
18
import {isBlob, isSourceLoader} from '@loaders.gl/loader-utils';
19
import {isLoaderObject} from '../loader-utils/normalize-loader';
20
import {getFetchFunction} from '../loader-utils/get-fetch-function';
21
import {normalizeLoaderOptions} from '../loader-utils/option-utils';
22
import {fetchFile} from '../fetch/fetch-file';
23

24
import {parse} from './parse';
25
import {parseSync} from './parse-sync';
26
import {parseInBatches} from './parse-in-batches';
27
import {loadInBatches} from './load-in-batches';
28
import {selectLoader} from './select-loader';
29

30
/**
31
 * Parses `data` using a specified loader
32
 * Note: Load does duplicate a lot of parse.
33
 * it can also call fetchFile on string urls, which `parse` won't do.
34
 * @param data
35
 * @param loaders
36
 * @param options
37
 * @param context
38
 */
39

40
export async function load<
41
  LoaderT extends Loader,
42
  OptionsT extends LoaderOptions = LoaderOptionsWithShape<
43
    LoaderOptionsType<LoaderT>,
44
    LoaderShapeType<LoaderT>
45
  >
46
>(
47
  url: string | DataType,
48
  loader: LoaderT,
49
  options?: OptionsT,
50
  context?: LoaderContext
51
): Promise<LoaderReturnType<LoaderT>>;
52

53
export async function load<
54
  LoaderArrayT extends Loader[],
55
  OptionsT extends LoaderOptions = LoaderArrayOptionsType<LoaderArrayT>
56
>(
57
  url: string | DataType,
58
  loaders: LoaderArrayT,
59
  options?: OptionsT,
60
  context?: LoaderContext
61
): Promise<LoaderArrayReturnType<LoaderArrayT>>;
62

63
/**
64
 * Loads data asynchronously by matching a pre-registered loader
65
 * @deprecated Loader registration is deprecated, use load(data, loaders, options) instead
66
 */
67
export async function load(
68
  url: string | DataType,
69
  loaders?: LoaderOptions,
70
  context?: LoaderContext
71
): Promise<unknown>;
72

73
// export async function load(url: string | DataType, loaders: LoaderOptions): Promise<any>;
74

75
// implementation signature
76
export async function load(
77
  url: string | DataType,
78
  loaders?: Loader[] | LoaderOptions,
79
  options?: LoaderOptions | LoaderContext,
80
  context?: LoaderContext
81
): Promise<unknown> {
82
  let resolvedLoaders: Loader | Loader[];
83
  let resolvedOptions: LoaderOptions | undefined;
84

85
  // Signature: load(url, options)
86
  if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
983✔
87
    resolvedLoaders = [];
4✔
88
    resolvedOptions = loaders as LoaderOptions;
4✔
89
    context = undefined; // context not supported in short signature
4✔
90
  } else {
91
    resolvedLoaders = loaders as Loader | Loader[];
979✔
92
    resolvedOptions = options as LoaderOptions;
979✔
93
  }
94

95
  if (!Array.isArray(resolvedLoaders) && isSourceLoader(resolvedLoaders)) {
983✔
96
    const runtimeCoreApi = {
10✔
97
      fetchFile,
98
      parse,
99
      parseSync,
100
      parseInBatches,
101
      load,
102
      loadInBatches
103
    };
104
    return resolvedLoaders.createDataSource(
10✔
105
      url as string | Blob,
106
      (resolvedOptions || {}) as LoaderOptionsType<SourceLoader>,
18✔
107
      runtimeCoreApi
108
    );
109
  }
110

111
  if (
973!
112
    Array.isArray(resolvedLoaders) &&
987!
113
    resolvedLoaders.length === 1 &&
114
    isSourceLoader(resolvedLoaders[0])
115
  ) {
116
    const runtimeCoreApi = {
×
117
      fetchFile,
118
      parse,
119
      parseSync,
120
      parseInBatches,
121
      load,
122
      loadInBatches
123
    };
124
    return resolvedLoaders[0].createDataSource(
×
125
      url as string | Blob,
126
      (resolvedOptions || {}) as LoaderOptionsType<SourceLoader>,
×
127
      runtimeCoreApi
128
    );
129
  }
130

131
  if (typeof url === 'string' || isBlob(url)) {
973✔
132
    const selectedLoader = await selectLoader(url, resolvedLoaders as Loader | Loader[], {
957✔
133
      ...resolvedOptions,
134
      core: {...resolvedOptions?.core, nothrow: true}
135
    });
136

137
    if (selectedLoader && isSourceLoader(selectedLoader)) {
957!
138
      return selectedLoader.createDataSource(
×
139
        url,
140
        (resolvedOptions || {}) as LoaderOptionsType<SourceLoader>,
×
141
        {
142
          fetchFile,
143
          parse,
144
          parseSync,
145
          parseInBatches,
146
          load,
147
          loadInBatches
148
        }
149
      );
150
    }
151
  }
152

153
  // Select fetch function
154
  const fetch = getFetchFunction(resolvedOptions);
973✔
155

156
  // at this point, `url` could be already loaded binary data
157
  let data = url;
973✔
158
  // url is a string, fetch the url
159
  if (typeof url === 'string') {
973✔
160
    data = await fetch(url);
956✔
161
    // URL is Blob or File, fetchFile handles it (alt: we could generate ObjectURL here)
162
  }
163

164
  if (isBlob(url)) {
973✔
165
    // The fetch response object will contain blob.name
166
    // @ts-expect-error TODO - This may not work for overridden fetch functions
UNCOV
167
    data = await fetch(url);
1✔
168
  }
169

170
  if (typeof url === 'string') {
973✔
171
    const normalizedOptions = normalizeLoaderOptions(resolvedOptions || {});
956✔
172
    if (!normalizedOptions.core?.baseUrl) {
956!
173
      resolvedOptions = {
956✔
174
        ...resolvedOptions,
175
        core: {
176
          ...resolvedOptions?.core,
177
          baseUrl: url
178
        }
179
      };
180
    }
181
  }
182

183
  // Data is loaded (at least we have a `Response` object) so time to hand over to `parse`
184
  // return await parse(data, loaders as Loader[], options);
185
  return Array.isArray(resolvedLoaders)
973✔
186
    ? await parse(data, resolvedLoaders, resolvedOptions, context) // loader array overload
187
    : await parse(data, resolvedLoaders, resolvedOptions, context); // single loader overload
188
}
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