{"id":25636607,"url":"https://github.com/bbecquet/jkstra","last_synced_at":"2025-04-14T22:11:00.725Z","repository":{"id":18707648,"uuid":"21918211","full_name":"bbecquet/jkstra","owner":"bbecquet","description":"JavaScript graph routing library","archived":false,"fork":false,"pushed_at":"2021-11-28T12:27:02.000Z","size":278,"stargazers_count":49,"open_issues_count":6,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T08:33:33.631Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bbecquet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-16T21:08:11.000Z","updated_at":"2024-08-19T10:19:23.000Z","dependencies_parsed_at":"2022-09-26T21:51:10.123Z","dependency_job_id":null,"html_url":"https://github.com/bbecquet/jkstra","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbecquet%2Fjkstra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbecquet%2Fjkstra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbecquet%2Fjkstra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bbecquet%2Fjkstra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bbecquet","download_url":"https://codeload.github.com/bbecquet/jkstra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248968914,"owners_count":21191162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-02-23T00:48:51.846Z","updated_at":"2025-04-14T22:11:00.700Z","avatar_url":"https://github.com/bbecquet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jkstra - A simple graph and routing library\n\n**jkstra** is a JavaScript library to work with **graphs** - as in \"data structures\", with edges and vertices, not as in \"graphics\".\n\n[See an interactive demo](http://bbecquet.github.io/jkstra/demo/).\n\nIt was made originally as a base model for a webapp that needed to run offline shortest path computations on a public transportation network.\n\nFor now it supports simple directed graphs and provides implementations Dijkstra and A\\* algorithms to find shortest paths in it.\n\n```bash\nnpm install jkstra\n```\n\n## Simple example\n\n```javascript\nvar jkstra = require(\"\u003cpath_to_jkstra\u003e\");\n\nvar graph = new jkstra.Graph();\n\nvar n = []; // to easily keep references to the node objects\n\nn.push(graph.addVertex(0));\nn.push(graph.addVertex(1));\nn.push(graph.addVertex(2));\nn.push(graph.addVertex(3));\nn.push(graph.addVertex(4)); // the parameter is arbitrary data assigned to the node\nn.push(graph.addVertex({ id: 666, label: \"A node holding complex data\" }));\n\nconsole.log(n[3].data); // =\u003e 3\nconsole.log(n[5].data); // =\u003e {id: 666, label: 'A node holding complex data'}\n\ngraph.addEdge(n[0], n[1], 7); // The edges are directed. Here, only the edge from 0 to 1 is created.\ngraph.addEdgePair(n[0], n[2], 9); // But two opposite edges sharing the same data can be easily created\ngraph.addEdge(n[0], n[5], 14);\ngraph.addEdge(n[1], n[2], 10);\ngraph.addEdge(n[1], n[3], 15);\ngraph.addEdge(n[2], n[5], 2);\ngraph.addEdge(n[2], n[3], 12); // As for the nodes, you can assign any data to the edge.\ngraph.addEdge(n[3], n[4], 6); // Here we use it to store a single value which will be used as a cost.\ngraph.addEdge(n[5], n[4], 10);\n\n// you can access edges from nodes with the outEdges/inEdges function\nconsole.log(\n  graph\n    .outEdges(n[5])\n    .map(function (e) {\n      return e.data;\n    })\n    .join()\n);\n// =\u003e [10]\n\nvar dijkstra = new jkstra.algos.Dijkstra(graph);\n\n// computes the shortestPath between nodes 0 and 4,\n// using the single number stored in each as its cost\nvar path = dijkstra.shortestPath(n[0], n[4], {\n  edgeCost: function (e) {\n    return e.data;\n  },\n});\n\n// the result is an array of the edge objects that make the path\nconsole.log(\n  path\n    .map(function (e) {\n      return e.data;\n    })\n    .join()\n);\n// =\u003e [9, 2, 10]\n```\n\n## [API](doc/API.md)\n\n## License\n\nMIT.\n\n## Author\n\n[Benjamin Becquet](http://bbecquet.net/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbecquet%2Fjkstra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbbecquet%2Fjkstra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbbecquet%2Fjkstra/lists"}