• 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

45.21
/modules/textures/src/lib/texture-api/async-deep-map.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
/*
1✔
6
Asynchronously maps a deep structure of values (e.g. objects and arrays of urls).
1✔
7

1✔
8
E.g. a mipmapped cubemap
1✔
9
{
1✔
10
  [CUBE_FACE_FRONT]: [
1✔
11
    "image-front-0.jpg",
1✔
12
    "image-front-1.jpg",
1✔
13
    "image-front-2.jpg",
1✔
14
  ],
1✔
15
  [CUBE_MAP_BACK]: [
1✔
16
    ...
1✔
17
  ]
1✔
18
}
1✔
19
*/
1✔
20
export type Options = Record<string, any>;
1✔
21
export type Func = (url: string, options: Options) => unknown;
1✔
22

1✔
23
const isObject = (value: any): boolean => value && typeof value === 'object';
1✔
24

1✔
25
// Loads a deep structure of urls (objects and arrays of urls)
1✔
26
// Returns an object with six key-value pairs containing the images (or image mip arrays)
1✔
27
// for each cube face
1✔
UNCOV
28
export async function asyncDeepMap(tree: unknown, func: Func, options: Options = {}) {
×
UNCOV
29
  return await mapSubtree(tree, func, options);
×
UNCOV
30
}
×
31

1✔
UNCOV
32
export async function mapSubtree(object: unknown, func: Func, options: Options) {
×
UNCOV
33
  if (Array.isArray(object)) {
×
UNCOV
34
    return await mapArray(object, func, options);
×
UNCOV
35
  }
×
UNCOV
36

×
UNCOV
37
  if (isObject(object)) {
×
UNCOV
38
    return await mapObject(object as object, func, options);
×
UNCOV
39
  }
×
UNCOV
40

×
UNCOV
41
  // TODO - ignore non-urls, non-arraybuffers?
×
UNCOV
42
  const url = object as string;
×
UNCOV
43
  return await func(url, options);
×
UNCOV
44
}
×
45

1✔
46
// HELPERS
1✔
47

1✔
UNCOV
48
async function mapObject(
×
UNCOV
49
  object: Record<string, any>,
×
UNCOV
50
  func: Func,
×
UNCOV
51
  options: Options
×
UNCOV
52
): Promise<Record<string, any>> {
×
UNCOV
53
  const promises: Promise<any>[] = [];
×
UNCOV
54
  const values: Record<string, any> = {};
×
UNCOV
55

×
UNCOV
56
  for (const key in object) {
×
UNCOV
57
    const url = object[key];
×
UNCOV
58
    const promise = mapSubtree(url, func, options).then((value) => {
×
UNCOV
59
      values[key] = value;
×
UNCOV
60
    });
×
UNCOV
61
    promises.push(promise);
×
UNCOV
62
  }
×
UNCOV
63

×
UNCOV
64
  await Promise.all(promises);
×
UNCOV
65

×
UNCOV
66
  return values;
×
UNCOV
67
}
×
68

1✔
UNCOV
69
async function mapArray(urlArray: string[], func: Func, options = {}): Promise<any[]> {
×
UNCOV
70
  const promises = urlArray.map((url) => mapSubtree(url, func, options));
×
UNCOV
71
  return await Promise.all(promises);
×
UNCOV
72
}
×
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