github
1710 of 2234 branches covered (76.54%)
Branch coverage included in aggregate %.
94 of 141 new or added lines in 25 files covered. (66.67%)
20319 existing lines in 272 files now uncovered.35902 of 63049 relevant lines covered (56.94%)
11.42 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
|
} |
× |