forked from adamlaska/browser-compat-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.js
More file actions
26 lines (24 loc) · 704 Bytes
/
query.js
File metadata and controls
26 lines (24 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const bcd = require('..');
/**
* Get a subtree of compat data.
*
* @param {string} path Dotted path to a given feature (e.g., `css.properties.background`)
* @param {*} [data=bcd] A tree to query. All of BCD, by default.
* @returns {*} A BCD subtree
* @throws {ReferenceError} For invalid identifiers
*/
function query(path, data = bcd) {
const pathElements = path.split('.');
let lookup = data;
while (pathElements.length) {
const next = pathElements.shift();
lookup = lookup[next];
if (lookup === undefined) {
throw new ReferenceError(
`${path} is not a valid tree identifier (failed at '${next}')`,
);
}
}
return lookup;
}
module.exports = query;