github
1903 of 2546 branches covered (74.74%)
Branch coverage included in aggregate %.
775 of 823 new or added lines in 10 files covered. (94.17%)
17884 existing lines in 262 files now uncovered.37927 of 62547 relevant lines covered (60.64%)
158.97 hits per line
1 |
import {Feature} from 'geojson'; |
1✔ |
2 |
import {assert} from '../utils'; |
|
3 |
|
1✔ |
4 |
const ALLOWED_ATTR_TYPES = Object.freeze(['function', 'string']); |
1✔ |
5 |
|
1✔ |
6 |
export type AttributeSelector<DataT = Feature, OutT = any> =
|
1✔ |
7 |
| string
|
1✔ |
8 |
| ((d: DataT, info: any) => OutT); |
1✔ |
9 |
|
1✔ |
10 |
export function getAttrValue<DataT = Feature, OutT = any>(
|
1✔ |
UNCOV
11
|
attr: string | AttributeSelector<DataT, OutT>,
|
× |
UNCOV
12
|
d: DataT, |
× |
UNCOV
13
|
info: any |
× |
UNCOV
14
|
): OutT { |
× |
UNCOV
15
|
assert(typeof d === 'object', 'Expected "data" to be an object'); |
× |
UNCOV
16
|
assert(ALLOWED_ATTR_TYPES.includes(typeof attr), 'Expected "attr" to be a function or string'); |
× |
UNCOV
17
|
|
× |
UNCOV
18
|
// Is function
|
× |
UNCOV
19
|
if (typeof attr === 'function') { |
× |
UNCOV
20
|
return attr(d, info);
|
× |
UNCOV
21
|
} |
× |
UNCOV
22
|
return (d as unknown as Feature)?.properties?.[attr] as OutT;
|
× |
UNCOV
23
|
} |
× |