• 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

77.18
/modules/loader-utils/src/lib/javascript-utils/is-type.ts
1
// loaders.gl
1✔
2
// SPDX-License-Identifier: MIT
1✔
3
// Copyright (c) vis.gl contributors
1✔
4

1✔
5
/* eslint-disable @typescript-eslint/unbound-method */
1✔
6

1✔
7
import type {Readable} from 'stream';
1✔
8

1✔
9
/** Minimal shape for Node.js Buffer-like values */
1✔
10
type NodeBufferLike = {buffer: ArrayBufferLike; isBuffer: true};
1✔
11

1✔
12
/** Minimal shape for Node.js writable streams */
1✔
13
type NodeWritableStream = {
1✔
14
  end: (...args: unknown[]) => unknown;
1✔
15
  write: (...args: unknown[]) => unknown;
1✔
16
  writable: boolean;
1✔
17
};
1✔
18

1✔
19
/** Minimal shape for WritableStream-like DOM implementations */
1✔
20
type WritableDOMStreamLike = WritableStream | {abort: () => unknown; getWriter: () => unknown};
1✔
21

1✔
22
/** A DOM or Node readable stream */
1✔
23
export type ReadableStreamType = ReadableStream | Readable;
1✔
24

1✔
25
/** Checks whether a value is a boolean */
1✔
26
const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean';
1✔
27

1✔
28
/** Checks whether a value is a function */
1✔
29
const isFunction = (value: unknown): value is (...args: unknown[]) => unknown =>
1✔
30
  typeof value === 'function';
6✔
31

1✔
32
/** Checks whether a value is a non-null object */
1✔
33
export const isObject = (value: unknown): value is object =>
1✔
34
  value !== null && typeof value === 'object';
20✔
35

1✔
36
/** Checks whether a value is a plain object (created by the Object constructor) */
1✔
37
export const isPureObject = (value: unknown): value is Record<string, unknown> =>
1✔
38
  isObject(value) && value.constructor === {}.constructor;
10✔
39

1✔
40
/** Checks whether a value is an ArrayBuffer */
1✔
41
export const isArrayBuffer = (value: unknown): value is ArrayBuffer =>
1✔
NEW
42
  typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer;
×
43

1✔
44
/** Checks whether a value is ArrayBuffer-like */
1✔
45
export const isArrayBufferLike = (value: unknown): value is ArrayBufferLike =>
1✔
NEW
46
  isObject(value) &&
×
NEW
47
  typeof (value as ArrayBufferLike).byteLength === 'number' &&
×
NEW
48
  typeof (value as ArrayBufferLike).slice === 'function';
×
49

1✔
50
/** Checks whether a value behaves like a promise */
1✔
51
export const isPromise = (value: unknown): value is Promise<unknown> =>
1✔
52
  isObject(value) && 'then' in value && isFunction((value as {then: unknown}).then);
2!
53

1✔
54
/** Checks whether a value implements the iterable protocol */
1✔
55
export const isIterable = (value: unknown): value is Iterable<unknown> =>
1✔
NEW
56
  Boolean(value) && isFunction((value as Iterable<unknown>)[Symbol.iterator]);
×
57

1✔
58
/** Checks whether a value implements the async iterable protocol */
1✔
59
export const isAsyncIterable = (value: unknown): value is AsyncIterable<unknown> =>
1✔
NEW
60
  Boolean(value) && isFunction((value as AsyncIterable<unknown>)[Symbol.asyncIterator]);
×
61

1✔
62
/** Checks whether a value is an iterator (has a next function) */
1✔
63
export const isIterator = (value: unknown): value is Iterator<unknown> =>
1✔
64
  Boolean(value) && isFunction((value as Iterator<unknown>).next);
2✔
65

1✔
66
/** Checks whether a value is a fetch Response or a duck-typed equivalent */
1✔
67
export const isResponse = (value: unknown): value is Response =>
1✔
68
  (typeof Response !== 'undefined' && value instanceof Response) ||
3✔
69
  (isObject(value) &&
2✔
70
    isFunction((value as {arrayBuffer?: unknown}).arrayBuffer) &&
2!
NEW
71
    isFunction((value as {text?: unknown}).text) &&
×
NEW
72
    isFunction((value as {json?: unknown}).json));
×
73

1✔
74
/** Checks whether a value is a File */
1✔
75
export const isFile = (value: unknown): value is File =>
1✔
NEW
76
  typeof File !== 'undefined' && value instanceof File;
×
77

1✔
78
/** Checks whether a value is a Blob */
1✔
79
export const isBlob = (value: unknown): value is Blob =>
1✔
80
  typeof Blob !== 'undefined' && value instanceof Blob;
4✔
81

1✔
82
/** Checks for Node.js Buffers without triggering bundlers to include the Buffer polyfill */
1✔
83
export const isBuffer = (value: unknown): value is NodeBufferLike =>
1✔
NEW
84
  Boolean(
×
NEW
85
    value &&
×
NEW
86
      typeof value === 'object' &&
×
NEW
87
      (value as Partial<NodeBufferLike>).isBuffer &&
×
NEW
88
      'buffer' in (value as NodeBufferLike)
×
NEW
89
  );
×
90

1✔
91
/** Checks whether a value looks like a DOM WritableStream */
1✔
92
export const isWritableDOMStream = (value: unknown): value is WritableDOMStreamLike =>
1✔
NEW
93
  isObject(value) &&
×
NEW
94
  isFunction((value as WritableDOMStreamLike).abort) &&
×
NEW
95
  isFunction((value as WritableDOMStreamLike).getWriter);
×
96

1✔
97
/** Checks whether a value looks like a DOM ReadableStream */
1✔
98
export const isReadableDOMStream = (value: unknown): value is ReadableStream =>
1✔
99
  (typeof ReadableStream !== 'undefined' && value instanceof ReadableStream) ||
2✔
100
  (isObject(value) &&
1✔
101
    isFunction((value as ReadableStream).tee) &&
1!
NEW
102
    isFunction((value as ReadableStream).cancel) &&
×
NEW
103
    isFunction((value as ReadableStream).getReader));
×
104
// Not implemented in Firefox: && isFunction(x.pipeTo)
1✔
105

1✔
106
/** Checks whether a value looks like a Node.js writable stream */
1✔
107
export const isWritableNodeStream = (value: unknown): value is NodeWritableStream =>
1✔
NEW
108
  isObject(value) &&
×
NEW
109
  isFunction((value as NodeWritableStream).end) &&
×
NEW
110
  isFunction((value as NodeWritableStream).write) &&
×
NEW
111
  isBoolean((value as NodeWritableStream).writable);
×
112

1✔
113
/** Checks whether a value looks like a Node.js readable stream */
1✔
114
export const isReadableNodeStream = (value: unknown): value is Readable =>
1✔
115
  isObject(value) &&
1✔
116
  isFunction((value as Readable).read) &&
1!
NEW
117
  isFunction((value as Readable).pipe) &&
×
NEW
118
  isBoolean((value as Readable).readable);
×
119

1✔
120
/** Checks whether a value is any readable stream (DOM or Node.js) */
1✔
121
export const isReadableStream = (value: unknown): value is ReadableStreamType =>
1✔
122
  isReadableDOMStream(value) || isReadableNodeStream(value);
2✔
123

1✔
124
/** Checks whether a value is any writable stream (DOM or Node.js) */
1✔
125
export const isWritableStream = (value: unknown): value is WritableStream | NodeWritableStream =>
1✔
NEW
126
  isWritableDOMStream(value) || isWritableNodeStream(value);
×
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