all files / bpmn-js/lib/features/modeling/util/ ModelingUtil.js

100% Statements 8/8
100% Branches 4/4
100% Functions 3/3
100% Lines 8/8
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44                                36956× 124843×                             3532× 2427×     3532× 4956× 2791×       741×  
import {
  some
} from 'min-dash';
 
import { is } from '../../../util/ModelUtil';
 
 
/**
 * Return true if element has any of the given types.
 *
 * @param {djs.model.Base} element
 * @param {Array<String>} types
 *
 * @return {Boolean}
 */
export function isAny(element, types) {
  return some(types, function(t) {
    return is(element, t);
  });
}
 
 
/**
 * Return the parent of the element with any of the given types.
 *
 * @param {djs.model.Base} element
 * @param {String|Array<String>} anyType
 *
 * @return {djs.model.Base}
 */
export function getParent(element, anyType) {
 
  if (typeof anyType === 'string') {
    anyType = [ anyType ];
  }
 
  while ((element = element.parent)) {
    if (isAny(element, anyType)) {
      return element;
    }
  }
 
  return null;
}