{"id":26975152,"url":"https://github.com/izure1/traffic-traversal","last_synced_at":"2026-04-29T10:03:25.723Z","repository":{"id":96353240,"uuid":"594022319","full_name":"izure1/traffic-traversal","owner":"izure1","description":"Calculate the weights between each vertex node and help you find the fastest route.","archived":false,"fork":false,"pushed_at":"2025-06-14T13:42:47.000Z","size":254,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-29T04:39:59.840Z","etag":null,"topics":["dijkstra-algorithm","node","route","spf","traffic","traversal","traversal-algorithms","vertex"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/izure1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-27T12:16:20.000Z","updated_at":"2025-06-14T13:42:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"9e859127-2f83-4d4d-b44d-d3b79361ea5b","html_url":"https://github.com/izure1/traffic-traversal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/izure1/traffic-traversal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Ftraffic-traversal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Ftraffic-traversal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Ftraffic-traversal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Ftraffic-traversal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/izure1","download_url":"https://codeload.github.com/izure1/traffic-traversal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/izure1%2Ftraffic-traversal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32420356,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dijkstra-algorithm","node","route","spf","traffic","traversal","traversal-algorithms","vertex"],"created_at":"2025-04-03T11:19:16.816Z","updated_at":"2026-04-29T10:03:25.685Z","avatar_url":"https://github.com/izure1.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# traffic-traversal\r\n\r\n[![](https://data.jsdelivr.com/v1/package/npm/traffic-traversal/badge)](https://www.jsdelivr.com/package/npm/traffic-traversal)\r\n![Github node.js workflow](https://github.com/izure1/traffic-traversal/actions/workflows/node.js.yml/badge.svg)\r\n\r\nCalculate the weights between each vertex node and help you find the fastest route.\r\n\r\n```typescript\r\nimport { TrafficGraph, TrafficTraversal } from 'traffic-traversal'\r\n\r\nconst graph = TrafficGraph.Create()\r\n\r\ngraph.to('start', {\r\n  b: 10,\r\n  c: 20\r\n}).to('b', { goal: 5 }).to('c', { goal: 5 })\r\n\r\nconst traversal = TrafficTraversal.Create(graph.state)\r\n\r\ntraversal.routes('start', 'goal') // ['start', 'b', 'goal']\r\n\r\ntraversal.traffic('start', 'goal') // 15\r\ntraversal.traffic('goal', 'start') // Infinity\r\n\r\ntraversal.reachable('start', 'goal') // true\r\ntraversal.reachable('goal', 'start') // false\r\n\r\ntraversal.depth('start', 'goal') // 2\r\ntraversal.depth('goal', 'start') // Infinity\r\n\r\ntraversal.distance('start', 'goal') // 2\r\ntraversal.distance('goal', 'start') // 2\r\n\r\ntraversal.edges('start') // ['b', 'c', 'goal']\r\ntraversal.edges('start', 1) // ['b', 'c']\r\n```\r\n\r\n## Method\r\n\r\n### `TrafficGraph`\r\n\r\n#### `constructor`(data?: `TrafficGraphData`)\r\n\r\nCreate a new graph instance. You can generate from existing data using `data` parameters.\r\n\r\n#### (getter) `data`: `TrafficGraphData`\r\n\r\nReturns to an array in the form that can serialize the graph information of the current instance.\r\n\r\n#### (getter) `state`: `Readonly\u003cITrafficGraphState\u003e`\r\n\r\nThe current status of the instance is exported to an immutable object.\r\n\r\n#### (getter) `vertices`: `string[]`\r\n\r\nReturns all the vertices listed in the current instance in an array.\r\n\r\n#### (getter) `clone`: `TrafficGraph`\r\n\r\nCurrently copied instance and returns to a new instance.\r\n\r\n#### `to`(source: `string`, dest: `GraphVertex`): `this`\r\n\r\nCreate a single direction weight route. It is possible to traverse the `source` to `dest`, but vice versa is impossible. If you had the same vertex before, the value is overwritten.\r\n\r\nYou can specify relative values. If you fill in the prior character `+=`, `-=`, `*=`, `/=`, The target value is calculated based on the current value of the property.\r\n\r\n#### `both`(a: `string`, b: `GraphVertex`): `this`\r\n\r\nSet the weight route that leads to both directions between the two vertices. 'a' vertex and 'b' vertex can traverse to each other.\r\n\r\nFor example, `graph.both('a', { b: 1 })` is same as `graph.to('a', { b: 1 }).to('b', { a: 1 })`\r\n\r\nYou can specify relative values. If you fill in the prior character `+=`, `-=`, `*=`, `/=`, The target value is calculated based on the current value of the property.\r\n\r\n#### `all`(dest: `GraphVertex`): `this`\r\n\r\nSet the weight between all vertices passed by parameters.\r\n\r\nFor example, `graph.all({ a: 1, b: 2, c: 3 })` is same as `graph.to('a', { b: 2, c: 3 }).to('b', { a: 1, c: 3 }).to('c', { a: 1, b: 2 })`\r\n\r\nYou can specify relative values. If you fill in the prior character `+=`, `-=`, `*=`, `/=`, The target value is calculated based on the current value of the property.\r\n\r\n#### `unlinkTo`(source: `string`, dest: `string`): `this`\r\n\r\nDelete the single direction weight route created by the `to` method.\r\n\r\n#### `unlinkBoth`(a: `string`, b: `string`): `this`\r\n\r\nDelete the bidirectional weight route created by the `both` method.\r\n\r\n#### `drop`(vertex: `string`): `this`\r\n\r\nDelete certain vertices. All weight routes connected to the vertex are deleted.\r\n\r\n#### `has`(vertex: `string`): `boolean`\r\n\r\nIt returns whether the instance has a vertex.\r\n\r\n#### `hasAll`(...vertices: `string[]`): `boolean`\r\n\r\nIt returns whether all the vertices exist in that instance. Returns `false` if any of the vertices are missing.\r\n\r\n#### `invert`(): `this`\r\n\r\nInvert all weights in an instance. For example, when A to B has a `2` weight, it will be `-2`.\r\nIt's useful for switching the shortest to longest routes or minimum to maximum traffic in a graph.\r\n\r\n### `TrafficTraversal`\r\n\r\n#### `constructor`(trafficGraphState: `ITrafficGraphState`)\r\n\r\nCreate an instance that is responsible for the route and utility functions of the graph instance. It takes a `graph.state` instance as a parameter.\r\n\r\n#### `routes`(from: `string`, to: `string`): `string[]`\r\n\r\nFinds the route with the lowest weight between two vertices and returns it as an array.\r\n\r\n#### `edges`(vertex: `string`, depth = `-1`): `string[]`\r\n\r\nReturns a list of vertices adjacent to that vertex as an array. You can set a depth limit using the `depth` parameter.\r\n\r\n#### `reachable`(from: `string`, to: `string`): `boolean`\r\n\r\nReturns whether the target vertex can be reached from the starting vertex.\r\n\r\n#### `traffic`(from: `string`, to: `string`): `number`\r\n\r\nReturns the sum of the least weighted routes from the starting vertex to the target vertex. If unreachable, returns `Infinity`.\r\n\r\n#### `depth`(from: `string`, to: `string`): `number`\r\n\r\nReturns the shortest distance from the starting vertex to the target vertex. This is similar to the `distance` method, but takes direction into account. If unreachable, returns `Infinity`.\r\n\r\n#### `distance`(a: `string`, b: `string`): `number`\r\n\r\nReturns the shortest distance between two vertices. This is similar to the `depth` method, but does not take direction into account. If unreachable, returns `Infinity`.\r\n\r\n## Install\r\n\r\n### Node.js (cjs)\r\n\r\n```bash\r\nnpm i traffic-traversal\r\n```\r\n\r\n### Browser (esm)\r\n\r\n```html\r\n\u003cscript type=\"module\"\u003e\r\n  import { TrafficGraph, TrafficTraversal } from 'https://cdn.jsdelivr.net/npm/traffic-traversal@1.x.x/dist/esm/index.min.js'\r\n\u003c/script\u003e\r\n```\r\n\r\n## License\r\n\r\nMIT LICENSE\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizure1%2Ftraffic-traversal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fizure1%2Ftraffic-traversal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fizure1%2Ftraffic-traversal/lists"}