bpmn-js/lib/features/modeling/util/ModelingUtil.js
Nico Rehwaldt d3449ca87c chore(project): es6ify source code
* use ES6 import / export
* UTILS: export individual utilities
* TESTS: localize TestHelper includes

BREAKING CHANGE:

* all utilities export independent functions
* library sources got ported to ES6. You must now use
  a ES module bundler such as Browserify + babelify or
  Webpack to consume this library (or parts of it).
2018-04-03 16:32:14 +02:00

46 lines
789 B
JavaScript

'use strict';
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;
}