UNPKG

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