Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export default tsEslint.config(
'n/file-extension-in-import': ['error', 'always'],
'n/no-unsupported-features/node-builtins': 'off', // we don't use node in this package, and most errors are due to "navigator.xxx is still an experimental feature and is not supported until Node.js yyy"
// apply a subset of unicorn rules for now
'unicorn/prefer-includes': 'error',
'unicorn/prefer-number-properties': 'error',
'unicorn/prefer-switch': 'error',
},
Expand Down
36 changes: 18 additions & 18 deletions packages/core/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class Client {
static IS_NS =
typeof window !== 'undefined' &&
navigator.userAgent != null &&
navigator.userAgent.indexOf('Mozilla/') >= 0 &&
navigator.userAgent.indexOf('MSIE') < 0 &&
navigator.userAgent.indexOf('Edge/') < 0;
navigator.userAgent.includes('Mozilla/') &&
!navigator.userAgent.includes('MSIE') &&
!navigator.userAgent.includes('Edge/');

/**
* True if the current browser is Safari.
Expand All @@ -91,7 +91,7 @@ class Client {
* Returns true if the user agent contains Android.
*/
static IS_ANDROID =
typeof window !== 'undefined' && navigator.appVersion.indexOf('Android') >= 0;
typeof window !== 'undefined' && navigator.appVersion.includes('Android');

/**
* Returns true if the user agent is an iPad, iPhone or iPod.
Expand Down Expand Up @@ -119,7 +119,7 @@ class Client {
/**
* True if the current browser is Firefox.
*/
static IS_FF = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
static IS_FF = navigator.userAgent.toLowerCase().includes('firefox');

/**
* True if -moz-transform is available as a CSS style. This is the case
Expand All @@ -128,16 +128,16 @@ class Client {
*/
static IS_MT =
typeof window !== 'undefined' &&
((navigator.userAgent.indexOf('Firefox/') >= 0 &&
navigator.userAgent.indexOf('Firefox/1.') < 0 &&
navigator.userAgent.indexOf('Firefox/2.') < 0) ||
(navigator.userAgent.indexOf('Iceweasel/') >= 0 &&
navigator.userAgent.indexOf('Iceweasel/1.') < 0 &&
navigator.userAgent.indexOf('Iceweasel/2.') < 0) ||
(navigator.userAgent.indexOf('SeaMonkey/') >= 0 &&
navigator.userAgent.indexOf('SeaMonkey/1.') < 0) ||
(navigator.userAgent.indexOf('Iceape/') >= 0 &&
navigator.userAgent.indexOf('Iceape/1.') < 0));
((navigator.userAgent.includes('Firefox/') &&
!navigator.userAgent.includes('Firefox/1.') &&
!navigator.userAgent.includes('Firefox/2.')) ||
(navigator.userAgent.includes('Iceweasel/') &&
!navigator.userAgent.includes('Iceweasel/1.') &&
!navigator.userAgent.includes('Iceweasel/2.')) ||
(navigator.userAgent.includes('SeaMonkey/') &&
!navigator.userAgent.includes('SeaMonkey/1.')) ||
(navigator.userAgent.includes('Iceape/') &&
!navigator.userAgent.includes('Iceape/1.')));

/**
* True if the browser supports SVG.
Expand All @@ -155,7 +155,7 @@ class Client {
(!document.createElementNS ||
document.createElementNS(NS_SVG, 'foreignObject').toString() !==
'[object SVGForeignObjectElement]' ||
navigator.userAgent.indexOf('Opera/') >= 0);
navigator.userAgent.includes('Opera/'));

/**
* True if the client is a Windows.
Expand Down Expand Up @@ -195,8 +195,8 @@ class Client {
*/
static IS_LOCAL =
typeof window !== 'undefined' &&
document.location.href.indexOf('http://') < 0 &&
document.location.href.indexOf('https://') < 0;
!document.location.href.includes('http://') &&
!document.location.href.includes('https://');
}

export default Client;
2 changes: 1 addition & 1 deletion packages/core/src/gui/MaxLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class MaxLog {
MaxLog.textarea.value = MaxLog.textarea.value + string;

// Workaround for no update in Presto 2.5.22 (Opera 10.5)
if (navigator.userAgent != null && navigator.userAgent.indexOf('Presto/2.5') >= 0) {
if (navigator.userAgent?.includes('Presto/2.5')) {
MaxLog.textarea.style.visibility = 'hidden';
MaxLog.textarea.style.visibility = 'visible';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/gui/MaxWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export default class MaxWindow extends EventSource {
*/
setScrollable(scrollable: boolean): void {
// Workaround for hang in Presto 2.5.22 (Opera 10.5)
if (navigator.userAgent == null || navigator.userAgent.indexOf('Presto/2.5') < 0) {
if (!navigator.userAgent?.includes('Presto/2.5')) {
if (scrollable) {
this.contentWrapper.style.overflow = 'auto';
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/i18n/Translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default class Translations {
static isLanguageSupported = (lan: string): boolean => {
const languages = TranslationsConfig.getLanguages();
if (languages) {
return languages.indexOf(lan) >= 0;
return languages.includes(lan);
}
return true;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/serialization/ObjectCodec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class ObjectCodec {
* Write is true if the field is being encoded, else it is being decoded.
*/
isExcluded(obj: any, attr: string, value: any, write?: boolean): boolean {
return attr == ObjectIdentity.FIELD_NAME || this.exclude.indexOf(attr) >= 0;
return attr == ObjectIdentity.FIELD_NAME || this.exclude.includes(attr);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/util/cloneUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const clone = function _clone(
for (const i in obj) {
if (
i != ObjectIdentity.FIELD_NAME &&
(transients == null || transients.indexOf(i) < 0)
(transients == null || !transients.includes(i))
) {
if (!shallow && typeof obj[i] === 'object') {
clone[i] = _clone(obj[i]);
Expand Down
39 changes: 20 additions & 19 deletions packages/core/src/util/domUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,29 @@ limitations under the License.
import { NODE_TYPE } from './Constants.js';
import { isNullish } from '../internal/utils.js';

// Known block elements for handling linefeed (list is not complete)
const blocks = new Set([
'BLOCKQUOTE',
'DIV',
'H1',
'H2',
'H3',
'H4',
'H5',
'H6',
'OL',
'P',
'PRE',
'TABLE',
'UL',
]);

/**
* Returns the text content of the specified node.
*
* @param elems DOM nodes to return the text for.
*/
export const extractTextWithWhitespace = (elems: Element[]): string => {
// Known block elements for handling linefeeds (list is not complete)
const blocks = [
'BLOCKQUOTE',
'DIV',
'H1',
'H2',
'H3',
'H4',
'H5',
'H6',
'OL',
'P',
'PRE',
'TABLE',
'UL',
];
const ret: string[] = [];

function doExtract(elts: Element[]) {
Expand Down Expand Up @@ -68,7 +69,7 @@ export const extractTextWithWhitespace = (elems: Element[]): string => {
doExtract(<Element[]>Array.from(elem.childNodes));
}

if (i < elts.length - 1 && blocks.indexOf(elts[i + 1].nodeName) >= 0) {
if (i < elts.length - 1 && blocks.has(elts[i + 1].nodeName)) {
ret.push('\n');
}
}
Expand Down Expand Up @@ -146,7 +147,7 @@ export const write = (parent: Element, text: string) => {
const doc = parent.ownerDocument;
const node = doc.createTextNode(text);

if (parent != null) {
if (parent) {
parent.appendChild(node);
}

Expand All @@ -164,7 +165,7 @@ export const writeln = (parent: Element, text: string) => {
const doc = parent.ownerDocument;
const node = doc.createTextNode(text);

if (parent != null) {
if (parent) {
parent.appendChild(node);
parent.appendChild(document.createElement('br'));
}
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/util/mathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export const getPortConstraints = (
}
}

if (directions.indexOf('north') >= 0) {
if (directions.includes('north')) {
switch (quad) {
case 0:
returnValue |= DIRECTION_MASK.NORTH;
Expand All @@ -270,7 +270,7 @@ export const getPortConstraints = (
break;
}
}
if (directions.indexOf('west') >= 0) {
if (directions.includes('west')) {
switch (quad) {
case 0:
returnValue |= DIRECTION_MASK.WEST;
Expand All @@ -286,7 +286,7 @@ export const getPortConstraints = (
break;
}
}
if (directions.indexOf('south') >= 0) {
if (directions.includes('south')) {
switch (quad) {
case 0:
returnValue |= DIRECTION_MASK.SOUTH;
Expand All @@ -302,7 +302,7 @@ export const getPortConstraints = (
break;
}
}
if (directions.indexOf('east') >= 0) {
if (directions.includes('east')) {
switch (quad) {
case 0:
returnValue |= DIRECTION_MASK.EAST;
Expand Down Expand Up @@ -674,7 +674,7 @@ export const isNumeric = (n: any): n is number | string => {
return (
!Number.isNaN(Number.parseFloat(n)) &&
Number.isFinite(+n) &&
(typeof n !== 'string' || n.toLowerCase().indexOf('0x') < 0)
(typeof n !== 'string' || !n.toLowerCase().includes('0x'))
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/GraphSelectionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class GraphSelectionModel extends EventSource {
* Returns true if the given {@link Cell} is selected.
*/
isSelected(cell: Cell) {
return this.cells.indexOf(cell) >= 0;
return this.cells.includes(cell);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/cell/Cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export class Cell implements IdentityObject {
if (
this.edges.length === 0 ||
edge.getTerminal(!isOutgoing) !== this ||
this.edges.indexOf(edge) < 0
!this.edges.includes(edge)
) {
this.edges.push(edge);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class GraphHierarchyModel {
internalTargetCell.connectsAsTarget = [];
}

if (internalTargetCell.connectsAsTarget.indexOf(internalEdge) < 0) {
if (!internalTargetCell.connectsAsTarget.includes(internalEdge)) {
internalTargetCell.connectsAsTarget.push(internalEdge);
}
}
Expand Down Expand Up @@ -238,7 +238,7 @@ class GraphHierarchyModel {

internalEdge.source = internalVertices[i];

if (internalVertices[i].connectsAsSource.indexOf(internalEdge) < 0) {
if (!internalVertices[i].connectsAsSource.includes(internalEdge)) {
internalVertices[i].connectsAsSource.push(internalEdge);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/view/layout/hierarchical/SwimlaneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class SwimlaneModel {
internalTargetCell.connectsAsTarget = [];
}

if (internalTargetCell.connectsAsTarget.indexOf(internalEdge) < 0) {
if (!internalTargetCell.connectsAsTarget.includes(internalEdge)) {
internalTargetCell.connectsAsTarget.push(internalEdge);
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ class SwimlaneModel {

internalEdge.source = internalVertices[i];

if (internalVertices[i].connectsAsSource.indexOf(internalEdge) < 0) {
if (!internalVertices[i].connectsAsSource.includes(internalEdge)) {
internalVertices[i].connectsAsSource.push(internalEdge);
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/view/mixins/CellsMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ export const CellsMixin: PartialType = {
geo.height
);

if (cells.indexOf(parent) >= 0) {
if (cells.includes(parent)) {
bbox.x += tmp.x;
bbox.y += tmp.y;
}
Expand All @@ -2063,7 +2063,7 @@ export const CellsMixin: PartialType = {
} else {
bbox = Rectangle.fromRectangle(geo);

if (parent && parent.isVertex() && cells.indexOf(parent) >= 0) {
if (parent && parent.isVertex() && cells.includes(parent)) {
tmp = this.getBoundingBoxFromGeometry([parent], false);

if (tmp) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/mixins/SwimlaneMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const SwimlaneMixin: PartialType = {
// Checks if parent is dropped into child if not cloning
let parentCell = cell;
if (!clone) {
while (parentCell && cells.indexOf(parentCell) < 0) {
while (parentCell && !cells.includes(parentCell)) {
parentCell = parentCell.getParent();
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/view/shape/Shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ class Shape {
let dx = pt.x - tmp.x;
let dy = pt.y - tmp.y;

if (rounded && (dx !== 0 || dy !== 0) && exclude.indexOf(i - 1) < 0) {
if (rounded && (dx !== 0 || dy !== 0) && !exclude.includes(i - 1)) {
// Draws a line from the last point to the current
// point with a spacing of size off the current point
// into direction of the last point
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/view/style/edge/Manhattan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const ManhattanConnector: EdgeStyleFunction = (
}

function toPointFromString(pointString: string) {
const xy = pointString.split(pointString.indexOf('@') === -1 ? ' ' : '@');
const xy = pointString.split(!pointString.includes('@') ? ' ' : '@');
return new Point(Number.parseInt(xy[0], 10), Number.parseInt(xy[1], 10));
}

Expand Down Expand Up @@ -477,7 +477,7 @@ export const ManhattanConnector: EdgeStyleFunction = (
: getDirectionAngle(startCenter, currentPoint, opt.directions.length);

// if get the endpoint
if (endPointsKeys.indexOf(currentKey) >= 0) {
if (endPointsKeys.includes(currentKey)) {
// stop route to enter the end point in opposite direction.
const directionChangedAngle = getDirectionChange(
currentDirectionAngle,
Expand Down
Loading