is-component-of.js 691 B

12345678910111213141516171819202122
  1. var configuration = require('../../configuration');
  2. function isComponentOf(property1, property2, shallow) {
  3. return isDirectComponentOf(property1, property2)
  4. || !shallow && !!configuration[property1.name].shorthandComponents && isSubComponentOf(property1, property2);
  5. }
  6. function isDirectComponentOf(property1, property2) {
  7. var descriptor = configuration[property1.name];
  8. return 'components' in descriptor && descriptor.components.indexOf(property2.name) > -1;
  9. }
  10. function isSubComponentOf(property1, property2) {
  11. return property1
  12. .components
  13. .some(function(component) {
  14. return isDirectComponentOf(component, property2);
  15. });
  16. }
  17. module.exports = isComponentOf;