github
4769 of 5426 branches covered (87.89%)
Branch coverage included in aggregate %.
13 of 14 new or added lines in 3 files covered. (92.86%)
6854 existing lines in 152 files now uncovered.47062 of 58712 relevant lines covered (80.16%)
4938.11 hits per line
1 |
// deck.gl
|
1✔ |
2 |
// SPDX-License-Identifier: MIT
|
1✔ |
3 |
// Copyright (c) vis.gl contributors
|
1✔ |
4 |
|
1✔ |
5 |
import {Feature} from 'geojson'; |
1✔ |
6 |
import {assert} from '../utils'; |
|
7 |
|
1✔ |
8 |
const ALLOWED_ATTR_TYPES = Object.freeze(['function', 'string']); |
1✔ |
9 |
|
1✔ |
10 |
export type AttributeSelector<DataT = Feature, OutT = any> =
|
1✔ |
11 |
| string
|
1✔ |
12 |
| ((d: DataT, info: any) => OutT); |
1✔ |
13 |
|
1✔ |
14 |
export function getAttrValue<DataT = Feature, OutT = any>(
|
1✔ |
UNCOV
15
|
attr: string | AttributeSelector<DataT, OutT>,
|
× |
UNCOV
16
|
d: DataT, |
× |
UNCOV
17
|
info: any |
× |
UNCOV
18
|
): OutT { |
× |
UNCOV
19
|
assert(typeof d === 'object', 'Expected "data" to be an object'); |
× |
UNCOV
20
|
assert(ALLOWED_ATTR_TYPES.includes(typeof attr), 'Expected "attr" to be a function or string'); |
× |
UNCOV
21
|
|
× |
UNCOV
22
|
// Is function
|
× |
UNCOV
23
|
if (typeof attr === 'function') { |
× |
UNCOV
24
|
return attr(d, info);
|
× |
UNCOV
25
|
} |
× |
UNCOV
26
|
return (d as unknown as Feature)?.properties?.[attr] as OutT;
|
× |
UNCOV
27
|
} |
× |