Skip to content

Commit 7c679ab

Browse files
authored
Merge pull request #449 from dagrejs/hasOwn
Using Object.hasOwn instead of hasOwnProperty
2 parents 71a8f04 + b559940 commit 7c679ab

11 files changed

+20
-20
lines changed

lib/acyclic.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ function dfsFAS(g) {
3333
let visited = {};
3434

3535
function dfs(v) {
36-
if (visited.hasOwnProperty(v)) {
36+
if (Object.hasOwn(visited, v)) {
3737
return;
3838
}
3939
visited[v] = true;
4040
stack[v] = true;
4141
g.outEdges(v).forEach(e => {
42-
if (stack.hasOwnProperty(e.w)) {
42+
if (Object.hasOwn(stack, e.w)) {
4343
fas.push(e);
4444
} else {
4545
dfs(e.w);

lib/add-border-segments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function addBorderSegments(g) {
1010
children.forEach(dfs);
1111
}
1212

13-
if (node.hasOwnProperty("minRank")) {
13+
if (Object.hasOwn(node, "minRank")) {
1414
node.borderLeft = [];
1515
node.borderRight = [];
1616
for (let rank = node.minRank, maxRank = node.maxRank + 1;

lib/coordinate-system.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function reverseY(g) {
4141
g.edges().forEach(e => {
4242
let edge = g.edge(e);
4343
edge.points.forEach(reverseYOne);
44-
if (edge.hasOwnProperty("y")) {
44+
if (Object.hasOwn(edge, "y")) {
4545
reverseYOne(edge);
4646
}
4747
});
@@ -57,7 +57,7 @@ function swapXY(g) {
5757
g.edges().forEach(e => {
5858
let edge = g.edge(e);
5959
edge.points.forEach(swapXYOne);
60-
if (edge.hasOwnProperty("x")) {
60+
if (Object.hasOwn(edge, "x")) {
6161
swapXYOne(edge);
6262
}
6363
});

lib/layout.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function updateInputGraph(inputGraph, layoutGraph) {
8484
let layoutLabel = layoutGraph.edge(e);
8585

8686
inputLabel.points = layoutLabel.points;
87-
if (layoutLabel.hasOwnProperty("x")) {
87+
if (Object.hasOwn(layoutLabel, "x")) {
8888
inputLabel.x = layoutLabel.x;
8989
inputLabel.y = layoutLabel.y;
9090
}
@@ -233,7 +233,7 @@ function translateGraph(g) {
233233
g.nodes().forEach(v => getExtremes(g.node(v)));
234234
g.edges().forEach(e => {
235235
let edge = g.edge(e);
236-
if (edge.hasOwnProperty("x")) {
236+
if (Object.hasOwn(edge, "x")) {
237237
getExtremes(edge);
238238
}
239239
});
@@ -253,8 +253,8 @@ function translateGraph(g) {
253253
p.x -= minX;
254254
p.y -= minY;
255255
});
256-
if (edge.hasOwnProperty("x")) { edge.x -= minX; }
257-
if (edge.hasOwnProperty("y")) { edge.y -= minY; }
256+
if (Object.hasOwn(edge, "x")) { edge.x -= minX; }
257+
if (Object.hasOwn(edge, "y")) { edge.y -= minY; }
258258
});
259259

260260
graphLabel.width = maxX - minX + marginX;
@@ -283,7 +283,7 @@ function assignNodeIntersects(g) {
283283
function fixupEdgeLabelCoords(g) {
284284
g.edges().forEach(e => {
285285
let edge = g.edge(e);
286-
if (edge.hasOwnProperty("x")) {
286+
if (Object.hasOwn(edge, "x")) {
287287
if (edge.labelpos === "l" || edge.labelpos === "r") {
288288
edge.width -= edge.labeloffset;
289289
}

lib/order/build-layer-graph.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function buildLayerGraph(g, rank, relationship) {
5454
result.setEdge(u, v, { weight: g.edge(e).weight + weight });
5555
});
5656

57-
if (node.hasOwnProperty("minRank")) {
57+
if (Object.hasOwn(node, "minRank")) {
5858
result.setNode(v, {
5959
borderLeft: node.borderLeft[rank],
6060
borderRight: node.borderRight[rank]

lib/order/sort-subgraph.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function sortSubgraph(g, v, cg, biasRight) {
2020
if (g.children(entry.v).length) {
2121
let subgraphResult = sortSubgraph(g, entry.v, cg, biasRight);
2222
subgraphs[entry.v] = subgraphResult;
23-
if (subgraphResult.hasOwnProperty("barycenter")) {
23+
if (Object.hasOwn(subgraphResult, "barycenter")) {
2424
mergeBarycenters(entry, subgraphResult);
2525
}
2626
}
@@ -36,7 +36,7 @@ function sortSubgraph(g, v, cg, biasRight) {
3636
if (g.predecessors(bl).length) {
3737
let blPred = g.node(g.predecessors(bl)[0]),
3838
brPred = g.node(g.predecessors(br)[0]);
39-
if (!result.hasOwnProperty("barycenter")) {
39+
if (!Object.hasOwn(result, "barycenter")) {
4040
result.barycenter = 0;
4141
result.weight = 0;
4242
}

lib/order/sort.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = sort;
44

55
function sort(entries, biasRight) {
66
let parts = util.partition(entries, entry => {
7-
return entry.hasOwnProperty("barycenter");
7+
return Object.hasOwn(entry, "barycenter");
88
});
99
let sortable = parts.lhs,
1010
unsortable = parts.rhs.sort((a, b) => b.i - a.i),

lib/position/bk.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function hasConflict(conflicts, v, w) {
152152
v = w;
153153
w = tmp;
154154
}
155-
return !!conflicts[v] && conflicts[v].hasOwnProperty(w);
155+
return !!conflicts[v] && Object.hasOwn(conflicts[v], w);
156156
}
157157

158158
/*
@@ -389,7 +389,7 @@ function sep(nodeSep, edgeSep, reverseSep) {
389389
let delta;
390390

391391
sum += vLabel.width / 2;
392-
if (vLabel.hasOwnProperty("labelpos")) {
392+
if (Object.hasOwn(vLabel, "labelpos")) {
393393
switch (vLabel.labelpos.toLowerCase()) {
394394
case "l": delta = -vLabel.width / 2; break;
395395
case "r": delta = vLabel.width / 2; break;
@@ -404,7 +404,7 @@ function sep(nodeSep, edgeSep, reverseSep) {
404404
sum += (wLabel.dummy ? edgeSep : nodeSep) / 2;
405405

406406
sum += wLabel.width / 2;
407-
if (wLabel.hasOwnProperty("labelpos")) {
407+
if (Object.hasOwn(wLabel, "labelpos")) {
408408
switch (wLabel.labelpos.toLowerCase()) {
409409
case "l": delta = wLabel.width / 2; break;
410410
case "r": delta = -wLabel.width / 2; break;

lib/rank/network-simplex.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function dfsAssignLowLim(tree, visited, nextLim, v, parent) {
132132

133133
visited[v] = true;
134134
tree.neighbors(v).forEach(w => {
135-
if (!visited.hasOwnProperty(w)) {
135+
if (!Object.hasOwn(visited, w)) {
136136
nextLim = dfsAssignLowLim(tree, visited, nextLim, w, v);
137137
}
138138
});

lib/rank/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function longestPath(g) {
3333

3434
function dfs(v) {
3535
var label = g.node(v);
36-
if (visited.hasOwnProperty(v)) {
36+
if (Object.hasOwn(visited, v)) {
3737
return label.rank;
3838
}
3939
visited[v] = true;

lib/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function normalizeRanks(g) {
165165
let min = applyWithChunking(Math.min, nodeRanks);
166166
g.nodes().forEach(v => {
167167
let node = g.node(v);
168-
if (node.hasOwnProperty("rank")) {
168+
if (Object.hasOwn(node, "rank")) {
169169
node.rank -= min;
170170
}
171171
});

0 commit comments

Comments
 (0)