# graphology-traversal

> Traversal functions for graphology.

Latest version **0.3.1** (published 2022-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install graphology-traversal
pnpm add graphology-traversal
yarn add graphology-traversal
bun add graphology-traversal
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2022-04-21 |
| First published | 2020-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1749 |
| Maintainers | yomguithereal |
| Keywords | graph, graphology, traversal, dfs, bfs |

## Links

- npm: https://www.npmjs.com/package/graphology-traversal
- Repository: https://github.com/graphology/graphology
- Homepage: https://github.com/graphology/graphology#readme
- Issues: https://github.com/graphology/graphology/issues
- npm.io page: https://npm.io/package/graphology-traversal

## Dependencies (2)

- [graphology-utils](https://npm.io/package/graphology-utils.md) ^2.0.0
- [graphology-indices](https://npm.io/package/graphology-indices.md) ^0.17.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2022-04-21
- 0.3.0 — 2021-12-09
- 0.2.2 — 2021-10-15
- 0.2.1 — 2021-03-19
- 0.2.0 — 2020-11-15
- 0.1.0 — 2020-11-14
- 0.0.1 — 2020-11-14

## README

# Graphology Traversal

Miscellaneous traversal functions to be used with [`graphology`](https://graphology.github.io).

## Installation

```
npm install graphology-traversal
```

## Usage

- [bfs](#bfs)
- [bfsFromNode](#bfsfromnode)
- [dfs](#dfs)
- [dfsFromNode](#bfsfromnode)

### bfs

Perform a BFS (Breadth-First Search) over the given graph using a callback.

```js
import {bfs} from 'graphology-traversal';
// Alternatively, to only load the relevant code
import {bfs} from 'graphology-traversal/bfs';

bfs(graph, function (node, attr, depth) {
  console.log(node, attr, depth);
});

// Stopping at depth 3
bfs(graph, function (node, attr, depth) {
  return depth >= 3;
});
```

_Arguments_

- **graph** _Graph_: a graphology instance.
- **callback** _function_: iteration callback taking the traversed node, its attributes and the traversal's depth. Returning `true` will prevent the traversal from following the next neighbors.
- **options** _?object_: traversal options:
  - **mode** _?string_ [`outbound`]: type of neighbors to traverse.

### bfsFromNode

Perform a BFS (Breadth-First Search) over the given graph, starting from the given node, using a callback.

```js
import {bfsFromNode} from 'graphology-traversal';
// Alternatively, to only load the relevant code
import {bfsFromNode} from 'graphology-traversal/bfs';

bfsFromNode(graph, 'node1', function (node, attr, depth) {
  console.log(node, attr, depth);
});

// Stopping at depth 3
bfsFromNode(graph, 'node1', function (node, attr, depth) {
  return depth >= 3;
});
```

_Arguments_

- **graph** _Graph_: a graphology instance.
- **node** _string\|number_: starting node.
- **callback** _function_: iteration callback taking the traversed node, its attributes and the traversal's depth. Returning `true` will prevent the traversal from following the next neighbors.
- **options** _?object_: traversal options:
  - **mode** _?string_ [`outbound`]: type of neighbors to traverse.

### dfs

Perform a DFS (Depth-First Search) over the given graph using a callback.

```js
import {dfs} from 'graphology-traversal';
// Alternatively, to only load the relevant code
import {dfs} from 'graphology-traversal/dfs';

dfs(graph, function (node, attr, depth) {
  console.log(node, attr, depth);
});

// Stopping at depth 3
dfs(graph, function (node, attr, depth) {
  return depth >= 3;
});
```

_Arguments_

- **graph** _Graph_: a graphology instance.
- **callback** _function_: iteration callback taking the traversed node, its attributes and the traversal's depth. Returning `true` will prevent the traversal from following the next neighbors.
- **options** _?object_: traversal options:
  - **mode** _?string_ [`outbound`]: type of neighbors to traverse.

### dfsFromNode

Perform a DFS (Depth-First Search) over the given graph, starting from the given node, using a callback.

```js
import {dfsFromNode} from 'graphology-traversal';
// Alternatively, to only load the relevant code
import {dfsFromNode} from 'graphology-traversal/dfs';

dfsFromNode(graph, 'node1', function (node, attr, depth) {
  console.log(node, attr, depth);
});

// Stopping at depth 3
dfsFromNode(graph, 'node1', function (node, attr, depth) {
  return depth >= 3;
});
```

_Arguments_

- **graph** _Graph_: a graphology instance.
- **node** _string\|number_: starting node.
- **callback** _function_: iteration callback taking the traversed node, its attributes and the traversal's depth. Returning `true` will prevent the traversal from following the next neighbors.
- **options** _?object_: traversal options:
  - **mode** _?string_ [`outbound`]: type of neighbors to traverse.

---
_Source: https://npm.io/package/graphology-traversal · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
