Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit 57f9889

Browse files
committed
chore: updating types
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 5f1e061 commit 57f9889

File tree

3 files changed

+75
-26
lines changed

3 files changed

+75
-26
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@api-modeling/graphlib",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"description": "A directed and undirected multi-graph library",
55
"author": "Chris Pettitt <[email protected]>",
66
"license": "MIT",

src/graph.d.ts

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,46 +75,46 @@ export declare class Graph<G, N, E> {
7575
* undirected.edge("b", "a"); // returns "my-label"
7676
* ```
7777
*
78-
* @returns {boolean} `true` if the graph is directed.
78+
* @returns `true` if the graph is directed.
7979
*/
8080
isDirected(): boolean;
8181

8282
/**
83-
* @returns {boolean} `true` if the graph is a [multigraph](https://github.com/dagrejs/graphlib/wiki/API-Reference#multigraphs).
83+
* @returns `true` if the graph is a [multigraph](https://github.com/dagrejs/graphlib/wiki/API-Reference#multigraphs).
8484
*/
8585
isMultigraph(): boolean;
8686

8787
/**
88-
* @returns {boolean} `true` if the graph is [compound](https://github.com/dagrejs/graphlib/wiki/API-Reference#compound-graphs).
88+
* @returns `true` if the graph is [compound](https://github.com/dagrejs/graphlib/wiki/API-Reference#compound-graphs).
8989
*/
9090
isCompound(): boolean;
9191

9292
/**
9393
* Sets the label for the graph to `label`.
9494
*/
95-
setGraph(label: any): Graph<G,N,E>;
95+
setGraph(label: G): this;
9696

9797
/**
9898
* @returns The currently assigned label for the graph. If no label has been assigned, returns undefined
9999
*/
100-
graph(): any|undefined;
100+
graph(): G|undefined;
101101

102102
/**
103103
* Defaults to be set when creating a new node
104104
*/
105-
_defaultNodeLabelFn(node?: NodeIdentifier): any|undefined;
105+
_defaultNodeLabelFn(node?: NodeIdentifier): N|undefined;
106106

107107
/**
108108
* Defaults to be set when creating a new edge
109109
*/
110-
_defaultEdgeLabelFn(v: NodeIdentifier, w: NodeIdentifier, name?: string): any|undefined;
110+
_defaultEdgeLabelFn(v: NodeIdentifier, w: NodeIdentifier, name?: string): E|undefined;
111111

112112
/**
113113
* Sets a new default value that is assigned to nodes that are created without a label.
114114
* If the value is not a function it is assigned as the label directly.
115115
* If the value is a function, it is called with the id of the node being created.
116116
*/
117-
setDefaultNodeLabel(newDefault: string|((node?: NodeIdentifier) => any)): Graph<G,N,E>;
117+
setDefaultNodeLabel(newDefault: string|((node?: NodeIdentifier) => N)): this;
118118

119119
/**
120120
* @returns the number of nodes in the graph.
@@ -138,7 +138,7 @@ export declare class Graph<G, N, E> {
138138
/**
139139
* Shortcut to calling `setNode()` on each array element
140140
*/
141-
setNodes(vs: NodeIdentifier[], value?: N): Graph<G,N,E>;
141+
setNodes(vs: NodeIdentifier[], value?: N): this;
142142

143143
/**
144144
* Creates or updates the value for the node v in the graph.
@@ -149,7 +149,7 @@ export declare class Graph<G, N, E> {
149149
* @param v The node to set
150150
* @returns the graph, allowing this to be chained with other functions. Takes O(1) time.
151151
*/
152-
setNode(v: NodeIdentifier, label?: N): Graph<G,N,E>;
152+
setNode(v: NodeIdentifier, label?: N): this;
153153

154154
/**
155155
* @returns the label assigned to the node or undefined when not found. Takes O(1) time.
@@ -167,7 +167,7 @@ export declare class Graph<G, N, E> {
167167
*
168168
* @returns the graph, allowing this to be chained with other functions. Takes O(|E|) time.
169169
*/
170-
removeNode(v: NodeIdentifier): Graph<G,N,E>;
170+
removeNode(v: NodeIdentifier): this;
171171

172172
/**
173173
* Sets the parent for `v` to `parent` if it is defined or removes the parent for `v` if `parent` is undefined.
@@ -176,7 +176,7 @@ export declare class Graph<G, N, E> {
176176
* @param parent The parent to set. Removes the parent when not set.
177177
* @returns the graph, allowing this to be chained with other functions. Takes O(1) time.
178178
*/
179-
setParent(v: NodeIdentifier, parent?: NodeIdentifier): Graph<G,N,E>;
179+
setParent(v: NodeIdentifier, parent?: NodeIdentifier): this;
180180

181181
_removeFromParentsChildList(v: NodeIdentifier): void;
182182

@@ -213,6 +213,7 @@ export declare class Graph<G, N, E> {
213213

214214
/**
215215
* @param filter The filter function.
216+
* @returns A copy of the graph with filtered nodes.
216217
*/
217218
filterNodes(filter: (id: NodeIdentifier) => boolean): Graph<G,N,E>;
218219

@@ -221,7 +222,7 @@ export declare class Graph<G, N, E> {
221222
* If the value is not a function it is assigned as the label directly.
222223
* If the value is a function, it is called with the parameters (v, w, name).
223224
*/
224-
setDefaultEdgeLabel(newDefault: string|((v:NodeIdentifier, w:NodeIdentifier, name?: string|number) => any)): Graph<G,N,E>;
225+
setDefaultEdgeLabel(newDefault: string|((v:NodeIdentifier, w:NodeIdentifier, name?: string|number) => E)): this;
225226

226227
/**
227228
* @returns the number of edges in the graph.
@@ -233,7 +234,7 @@ export declare class Graph<G, N, E> {
233234
*/
234235
edges(): Edge<E>[];
235236

236-
setPath(vs: NodeIdentifier[], value?: string): Graph<G,N,E>;
237+
setPath(vs: NodeIdentifier[], value?: string): this;
237238

238239
/**
239240
* Creates or updates the label for the edge (v, w) with the optionally supplied name.
@@ -251,33 +252,70 @@ export declare class Graph<G, N, E> {
251252
* @param name
252253
* @returns Returns the graph, allowing this to be chained with other functions.
253254
*/
254-
setEdge(v: NodeIdentifier|Edge<E>, w?: NodeIdentifier|E, value?: E, name?: string|number): Graph<G,N,E>;
255+
setEdge(v: NodeIdentifier, w: NodeIdentifier, value?: E, name?: string|number): this;
256+
/**
257+
* Creates or updates the label for the edge (v, w) with the optionally supplied name.
258+
* If `label` is supplied it is set as the value for the edge. If `label` is not supplied and the edge
259+
* is created by this call then the default edge label will be assigned.
260+
* The name parameter is only useful with multi graphs.
261+
* setEdge(v, w, [value, [name]])
262+
* setEdge({ v, w, [name] }, [value])
263+
*
264+
* Takes O(1) time.
265+
*
266+
* @param edge
267+
* @param value
268+
* @returns Returns the graph, allowing this to be chained with other functions.
269+
*/
270+
setEdge(edge: Edge<E>, value?: E): this;
255271

256272
/**
257273
* The name parameter is only useful with multi graphs. `v` and `w` can be interchanged for undirected graphs.
258274
*
259275
* Takes O(1) time.
260276
*
261-
* @param v
262-
* @param w Required when `v` is not an edge. When the `v` is an object then this is `name` param.
277+
* @param v The id of the source node
278+
* @param w The id of the target node
279+
* @param name
280+
* @returns the label for the edge (v, w) if the graph has an edge between `v` and `w` with the optional name.
281+
* Returns `undefined` if there is no such edge in the graph.
282+
*/
283+
edge(v: NodeIdentifier, w: NodeIdentifier, name?: string|number): E|undefined;
284+
/**
285+
* The name parameter is only useful with multi graphs. `v` and `w` can be interchanged for undirected graphs.
286+
*
287+
* Takes O(1) time.
288+
*
289+
* @param edge
263290
* @param name
264291
* @returns the label for the edge (v, w) if the graph has an edge between `v` and `w` with the optional name.
265292
* Returns `undefined` if there is no such edge in the graph.
266293
*/
267-
edge(v: Edge<E>|NodeIdentifier, w?: NodeIdentifier|string, name?: string|number): E|undefined;
294+
edge(edge: Edge<E>, name?: string|number): E|undefined;
268295

269296
/**
270297
* The name parameter is only useful with [multi graphs](https://github.com/dagrejs/graphlib/wiki/API-Reference#multigraphs).
271298
* `v` and `w` can be interchanged for undirected graphs.
272299
*
273300
* Takes O(1) time.
274301
*
275-
* @param v
276-
* @param w Required when `v` is not an edge. When the `v` is an object then this is `name` param.
302+
* @param v The id of the source node
303+
* @param w The id of the target node
304+
* @param name
305+
* @returns `true` if the graph has an edge between `v` and `w` with the optional name.
306+
*/
307+
hasEdge(v: NodeIdentifier, w: NodeIdentifier, name?: string): boolean;
308+
/**
309+
* The name parameter is only useful with [multi graphs](https://github.com/dagrejs/graphlib/wiki/API-Reference#multigraphs).
310+
* `v` and `w` can be interchanged for undirected graphs.
311+
*
312+
* Takes O(1) time.
313+
*
314+
* @param edge The edge to test
277315
* @param name
278316
* @returns `true` if the graph has an edge between `v` and `w` with the optional name.
279317
*/
280-
hasEdge(v: Edge<E>|NodeIdentifier, w?: NodeIdentifier|string, name?: string): boolean;
318+
hasEdge(edge: Edge<E>, name?: string): boolean;
281319

282320
/**
283321
* Removes the edge (v, w) if the graph has an edge between `v` and `w` with the optional name.
@@ -286,11 +324,22 @@ export declare class Graph<G, N, E> {
286324
*
287325
* Takes O(1) time.
288326
*
289-
* @param v
290-
* @param w Required when `v` is not an edge. When the `v` is an object then this is `name` param.
327+
* @param edge The edge to remove.
328+
* @param name
329+
*/
330+
removeEdge(edge: Edge<E>, name?: string): this;
331+
/**
332+
* Removes the edge (v, w) if the graph has an edge between `v` and `w` with the optional name.
333+
* If not this function does nothing. The `name` parameter is only useful with multi graphs.
334+
* `v` and `w` can be interchanged for undirected graphs.
335+
*
336+
* Takes O(1) time.
337+
*
338+
* @param v The id of the source node
339+
* @param w The id of the target node
291340
* @param name
292341
*/
293-
removeEdge(v: Edge<E>|NodeIdentifier, w?: NodeIdentifier|string, name?: string): Graph<G,N,E>;
342+
removeEdge(v: NodeIdentifier, w: NodeIdentifier, name?: string): this;
294343

295344
/**
296345
* Returns all edges that point to the node `v`.

0 commit comments

Comments
 (0)