From b559940277a4a52861fb4733cc5412cd0e1fffdb Mon Sep 17 00:00:00 2001 From: David Newell Date: Thu, 15 Aug 2024 11:04:07 +0000 Subject: [PATCH] Using Object.hasOwn instead of hasOwnProperty --- lib/acyclic.js | 4 ++-- lib/add-border-segments.js | 2 +- lib/coordinate-system.js | 4 ++-- lib/layout.js | 10 +++++----- lib/order/build-layer-graph.js | 2 +- lib/order/sort-subgraph.js | 4 ++-- lib/order/sort.js | 2 +- lib/position/bk.js | 6 +++--- lib/rank/network-simplex.js | 2 +- lib/rank/util.js | 2 +- lib/util.js | 2 +- 11 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/acyclic.js b/lib/acyclic.js index a67f71f1..c862413c 100644 --- a/lib/acyclic.js +++ b/lib/acyclic.js @@ -33,13 +33,13 @@ function dfsFAS(g) { let visited = {}; function dfs(v) { - if (visited.hasOwnProperty(v)) { + if (Object.hasOwn(visited, v)) { return; } visited[v] = true; stack[v] = true; g.outEdges(v).forEach(e => { - if (stack.hasOwnProperty(e.w)) { + if (Object.hasOwn(stack, e.w)) { fas.push(e); } else { dfs(e.w); diff --git a/lib/add-border-segments.js b/lib/add-border-segments.js index e8871182..a06365b1 100644 --- a/lib/add-border-segments.js +++ b/lib/add-border-segments.js @@ -10,7 +10,7 @@ function addBorderSegments(g) { children.forEach(dfs); } - if (node.hasOwnProperty("minRank")) { + if (Object.hasOwn(node, "minRank")) { node.borderLeft = []; node.borderRight = []; for (let rank = node.minRank, maxRank = node.maxRank + 1; diff --git a/lib/coordinate-system.js b/lib/coordinate-system.js index 6a4e8190..d6e03fc8 100644 --- a/lib/coordinate-system.js +++ b/lib/coordinate-system.js @@ -41,7 +41,7 @@ function reverseY(g) { g.edges().forEach(e => { let edge = g.edge(e); edge.points.forEach(reverseYOne); - if (edge.hasOwnProperty("y")) { + if (Object.hasOwn(edge, "y")) { reverseYOne(edge); } }); @@ -57,7 +57,7 @@ function swapXY(g) { g.edges().forEach(e => { let edge = g.edge(e); edge.points.forEach(swapXYOne); - if (edge.hasOwnProperty("x")) { + if (Object.hasOwn(edge, "x")) { swapXYOne(edge); } }); diff --git a/lib/layout.js b/lib/layout.js index 5846495b..532a0e23 100644 --- a/lib/layout.js +++ b/lib/layout.js @@ -84,7 +84,7 @@ function updateInputGraph(inputGraph, layoutGraph) { let layoutLabel = layoutGraph.edge(e); inputLabel.points = layoutLabel.points; - if (layoutLabel.hasOwnProperty("x")) { + if (Object.hasOwn(layoutLabel, "x")) { inputLabel.x = layoutLabel.x; inputLabel.y = layoutLabel.y; } @@ -233,7 +233,7 @@ function translateGraph(g) { g.nodes().forEach(v => getExtremes(g.node(v))); g.edges().forEach(e => { let edge = g.edge(e); - if (edge.hasOwnProperty("x")) { + if (Object.hasOwn(edge, "x")) { getExtremes(edge); } }); @@ -253,8 +253,8 @@ function translateGraph(g) { p.x -= minX; p.y -= minY; }); - if (edge.hasOwnProperty("x")) { edge.x -= minX; } - if (edge.hasOwnProperty("y")) { edge.y -= minY; } + if (Object.hasOwn(edge, "x")) { edge.x -= minX; } + if (Object.hasOwn(edge, "y")) { edge.y -= minY; } }); graphLabel.width = maxX - minX + marginX; @@ -283,7 +283,7 @@ function assignNodeIntersects(g) { function fixupEdgeLabelCoords(g) { g.edges().forEach(e => { let edge = g.edge(e); - if (edge.hasOwnProperty("x")) { + if (Object.hasOwn(edge, "x")) { if (edge.labelpos === "l" || edge.labelpos === "r") { edge.width -= edge.labeloffset; } diff --git a/lib/order/build-layer-graph.js b/lib/order/build-layer-graph.js index b55a099c..3bce3ac7 100644 --- a/lib/order/build-layer-graph.js +++ b/lib/order/build-layer-graph.js @@ -54,7 +54,7 @@ function buildLayerGraph(g, rank, relationship) { result.setEdge(u, v, { weight: g.edge(e).weight + weight }); }); - if (node.hasOwnProperty("minRank")) { + if (Object.hasOwn(node, "minRank")) { result.setNode(v, { borderLeft: node.borderLeft[rank], borderRight: node.borderRight[rank] diff --git a/lib/order/sort-subgraph.js b/lib/order/sort-subgraph.js index 9e8a319c..8fe1c0be 100644 --- a/lib/order/sort-subgraph.js +++ b/lib/order/sort-subgraph.js @@ -20,7 +20,7 @@ function sortSubgraph(g, v, cg, biasRight) { if (g.children(entry.v).length) { let subgraphResult = sortSubgraph(g, entry.v, cg, biasRight); subgraphs[entry.v] = subgraphResult; - if (subgraphResult.hasOwnProperty("barycenter")) { + if (Object.hasOwn(subgraphResult, "barycenter")) { mergeBarycenters(entry, subgraphResult); } } @@ -36,7 +36,7 @@ function sortSubgraph(g, v, cg, biasRight) { if (g.predecessors(bl).length) { let blPred = g.node(g.predecessors(bl)[0]), brPred = g.node(g.predecessors(br)[0]); - if (!result.hasOwnProperty("barycenter")) { + if (!Object.hasOwn(result, "barycenter")) { result.barycenter = 0; result.weight = 0; } diff --git a/lib/order/sort.js b/lib/order/sort.js index 5f939078..61fe42d7 100644 --- a/lib/order/sort.js +++ b/lib/order/sort.js @@ -4,7 +4,7 @@ module.exports = sort; function sort(entries, biasRight) { let parts = util.partition(entries, entry => { - return entry.hasOwnProperty("barycenter"); + return Object.hasOwn(entry, "barycenter"); }); let sortable = parts.lhs, unsortable = parts.rhs.sort((a, b) => b.i - a.i), diff --git a/lib/position/bk.js b/lib/position/bk.js index 14fbfa86..4df530cd 100644 --- a/lib/position/bk.js +++ b/lib/position/bk.js @@ -152,7 +152,7 @@ function hasConflict(conflicts, v, w) { v = w; w = tmp; } - return !!conflicts[v] && conflicts[v].hasOwnProperty(w); + return !!conflicts[v] && Object.hasOwn(conflicts[v], w); } /* @@ -389,7 +389,7 @@ function sep(nodeSep, edgeSep, reverseSep) { let delta; sum += vLabel.width / 2; - if (vLabel.hasOwnProperty("labelpos")) { + if (Object.hasOwn(vLabel, "labelpos")) { switch (vLabel.labelpos.toLowerCase()) { case "l": delta = -vLabel.width / 2; break; case "r": delta = vLabel.width / 2; break; @@ -404,7 +404,7 @@ function sep(nodeSep, edgeSep, reverseSep) { sum += (wLabel.dummy ? edgeSep : nodeSep) / 2; sum += wLabel.width / 2; - if (wLabel.hasOwnProperty("labelpos")) { + if (Object.hasOwn(wLabel, "labelpos")) { switch (wLabel.labelpos.toLowerCase()) { case "l": delta = wLabel.width / 2; break; case "r": delta = -wLabel.width / 2; break; diff --git a/lib/rank/network-simplex.js b/lib/rank/network-simplex.js index 7daab442..220bb2d0 100644 --- a/lib/rank/network-simplex.js +++ b/lib/rank/network-simplex.js @@ -132,7 +132,7 @@ function dfsAssignLowLim(tree, visited, nextLim, v, parent) { visited[v] = true; tree.neighbors(v).forEach(w => { - if (!visited.hasOwnProperty(w)) { + if (!Object.hasOwn(visited, w)) { nextLim = dfsAssignLowLim(tree, visited, nextLim, w, v); } }); diff --git a/lib/rank/util.js b/lib/rank/util.js index 452b88ab..33df9807 100644 --- a/lib/rank/util.js +++ b/lib/rank/util.js @@ -33,7 +33,7 @@ function longestPath(g) { function dfs(v) { var label = g.node(v); - if (visited.hasOwnProperty(v)) { + if (Object.hasOwn(visited, v)) { return label.rank; } visited[v] = true; diff --git a/lib/util.js b/lib/util.js index 17bedbc4..e51024e1 100644 --- a/lib/util.js +++ b/lib/util.js @@ -165,7 +165,7 @@ function normalizeRanks(g) { let min = applyWithChunking(Math.min, nodeRanks); g.nodes().forEach(v => { let node = g.node(v); - if (node.hasOwnProperty("rank")) { + if (Object.hasOwn(node, "rank")) { node.rank -= min; } });