build(docs-infra): improve directive API doc templates (#25768)

Closes #22790
Closes #25530

PR Close #25768
This commit is contained in:
Pete Bacon Darwin
2018-08-31 15:57:53 +01:00
committed by Alex Rickabaugh
parent 57de9fc41a
commit f22deb2e2d
13 changed files with 155 additions and 41 deletions

View File

@ -3,7 +3,21 @@ module.exports = function hasValues() {
name: 'hasValues',
process: function(list, property) {
if (!list || !Array.isArray(list)) return false;
return list.some(item => item[property]);
return list.some(item => readProperty(item, property.split('.'), 0));
}
};
};
};
/**
* Search deeply into an object via a collection of property segments, starting at the
* indexed segment.
*
* E.g. if `obj = { a: { b: { c: 10 }}}` then
* `readProperty(obj, ['a', 'b', 'c'], 0)` will return true;
* but
* `readProperty(obj, ['a', 'd'], 0)` will return false;
*/
function readProperty(obj, propertySegments, index) {
const value = obj[propertySegments[index]];
return !!value && (index === propertySegments.length - 1 || readProperty(value, propertySegments, index + 1));
}