UNPKG

1.05 kBJavaScriptView Raw
1import {
2 some
3} from 'min-dash';
4
5
6/**
7 * Is an element of the given BPMN type?
8 *
9 * @param {djs.model.Base|ModdleElement} element
10 * @param {string} type
11 *
12 * @return {boolean}
13 */
14export function is(element, type) {
15 var bo = getBusinessObject(element);
16
17 return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
18}
19
20
21/**
22 * Return true if element has any of the given types.
23 *
24 * @param {djs.model.Base} element
25 * @param {Array<string>} types
26 *
27 * @return {boolean}
28 */
29export function isAny(element, types) {
30 return some(types, function(t) {
31 return is(element, t);
32 });
33}
34
35/**
36 * Return the business object for a given element.
37 *
38 * @param {djs.model.Base|ModdleElement} element
39 *
40 * @return {ModdleElement}
41 */
42export function getBusinessObject(element) {
43 return (element && element.businessObject) || element;
44}
45
46/**
47 * Return the di object for a given element.
48 *
49 * @param {djs.model.Base} element
50 *
51 * @return {ModdleElement}
52 */
53export function getDi(element) {
54 return element && element.di;
55}
\No newline at end of file