terra-route 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ import typescriptEslint from "@typescript-eslint/eslint-plugin";
2
+ import tsParser from "@typescript-eslint/parser";
3
+ import eslintPluginPrettier from "eslint-plugin-prettier";
4
+ import prettierConfig from "eslint-config-prettier";
5
+ import json from "@eslint/json";
6
+ import markdown from "@eslint/markdown";
7
+
8
+ const ignores = ["**/node_modules", "**/dist", "**/docs", ".github", ".husky", ".vscode", "**/public", "**/coverage", "packages/e2e/playwright-report"];
9
+
10
+ export default [
11
+ {
12
+ ignores
13
+ },
14
+ {
15
+ files: ["**/*.json"],
16
+ language: "json/json",
17
+ plugins: {
18
+ json,
19
+ }
20
+ },
21
+ {
22
+ files: ["**/*.md"],
23
+ plugins: {
24
+ markdown
25
+ },
26
+ language: "markdown/commonmark",
27
+ },
28
+ {
29
+ name: "prettier", // Configuration name
30
+ files: ["**/*.{js,jsx,ts,tsx,json,md,yml,yaml,html,css}"],
31
+ ignores: ['**.json'],
32
+ plugins: {
33
+ prettier: eslintPluginPrettier, // Include Prettier plugin
34
+ },
35
+ rules: {
36
+ ...prettierConfig.rules, // Disable ESLint rules that conflict with Prettier
37
+ },
38
+ },
39
+ {
40
+ name: "typescript", // Configuration name
41
+ files: ["**/*.ts"], // TypeScript-specific configuration
42
+ plugins: {
43
+ "@typescript-eslint": typescriptEslint, // Include TypeScript ESLint plugin
44
+ },
45
+ languageOptions: {
46
+ parser: tsParser,
47
+ },
48
+ rules: {
49
+ "@typescript-eslint/no-empty-function": "warn",
50
+ "@typescript-eslint/no-explicit-any": "warn",
51
+ "no-console": process.env.CI ? "error" : "warn",
52
+ },
53
+ },
54
+ ];
package/package.json CHANGED
@@ -1,110 +1,93 @@
1
1
  {
2
- "name": "terra-route",
3
- "version": "0.0.3",
4
- "description": "A library for routing along GeoJSON LineString networks",
5
- "scripts": {
6
- "docs": "typedoc",
7
- "docs:serve": "serve ./docs",
8
- "test": "jest",
9
- "benchmark": "tsx benchmark/benchmark.ts",
10
- "build": "microbundle",
11
- "watch": "microbundle --watch --format modern",
12
- "unused": "knip",
13
- "lint": "eslint --ext .ts src/",
14
- "lint:quiet": "eslint --ext .ts --quiet src/",
15
- "lint:fix": "eslint --fix --ext .ts src/",
16
- "lint:fix:quiet": "eslint --fix --quiet --ext .ts src/"
17
- },
18
- "type": "module",
19
- "source": "src/terra-route.ts",
20
- "exports": {
2
+ "name": "terra-route",
3
+ "version": "0.0.5",
4
+ "description": "A library for routing along GeoJSON LineString networks",
5
+ "scripts": {
6
+ "docs": "typedoc",
7
+ "docs:serve": "serve ./docs",
8
+ "test": "jest",
9
+ "benchmark": "tsx benchmark/benchmark.ts",
10
+ "build": "microbundle",
11
+ "watch": "microbundle --watch --format modern",
12
+ "unused": "knip",
13
+ "lint": "eslint --config eslint.config.mjs",
14
+ "lint:quiet": "eslint --quiet --config eslint.config.mjs",
15
+ "lint:fix": "eslint --fix --config eslint.config.mjs",
16
+ "lint:fix:quiet": "eslint --fix --quiet --config eslint.config.mjs",
17
+ "format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\"",
18
+ "format:quiet": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\" --log-level=silent"
19
+ },
20
+ "type": "module",
21
+ "source": "src/terra-route.ts",
22
+ "exports": {
23
+ "types": "./dist/terra-route.d.ts",
24
+ "require": "./dist/terra-route.cjs",
25
+ "default": "./dist/terra-route.modern.js"
26
+ },
21
27
  "types": "./dist/terra-route.d.ts",
22
- "require": "./dist/terra-route.cjs",
23
- "default": "./dist/terra-route.modern.js"
24
- },
25
- "types": "./dist/terra-route.d.ts",
26
- "main": "./dist/terra-route.cjs",
27
- "module": "./dist/terra-route.module.js",
28
- "unpkg": "./dist/terra-route.umd.js",
29
- "author": "James Milner",
30
- "license": "MIT",
31
- "devDependencies": {
32
- "@types/jest": "^29.5.14",
33
- "@types/lodash": "^4.17.13",
34
- "@typescript-eslint/eslint-plugin": "8.16.0",
35
- "@typescript-eslint/parser": "8.16.0",
36
- "eslint": "8.57.1",
37
- "eslint-config-prettier": "9.1.0",
38
- "eslint-plugin-prettier": "5.2.1",
39
- "geojson": "^0.5.0",
40
- "geojson-path-finder": "^2.0.2",
41
- "jest": "^29.7.0",
42
- "knip": "^5.38.1",
43
- "microbundle": "0.15.1",
44
- "serve": "^14.2.4",
45
- "ts-jest": "^29.2.5",
46
- "tsx": "^4.19.3",
47
- "typedoc": "^0.28.1",
48
- "typescript": "^5.6.3"
49
- },
50
- "dependencies": {
51
- "@turf/turf": "^7.1.0"
52
- },
53
- "keywords": [
54
- "geojson",
55
- "linestring",
56
- "routing",
57
- "pathfinding",
58
- "network",
59
- "geospatial",
60
- "astar",
61
- "djikstra"
62
- ],
63
- "eslintConfig": {
64
- "parser": "@typescript-eslint/parser",
65
- "plugins": [
66
- "@typescript-eslint"
67
- ],
68
- "rules": {
69
- "@typescript-eslint/no-empty-function": "warn",
70
- "@typescript-eslint/no-explicit-any": "warn"
28
+ "main": "./dist/terra-route.cjs",
29
+ "module": "./dist/terra-route.module.js",
30
+ "unpkg": "./dist/terra-route.umd.js",
31
+ "author": "James Milner",
32
+ "license": "MIT",
33
+ "devDependencies": {
34
+ "@eslint/json": "^0.11.0",
35
+ "@eslint/markdown": "^6.3.0",
36
+ "@types/jest": "^29.5.14",
37
+ "@types/lodash": "^4.17.13",
38
+ "@typescript-eslint/eslint-plugin": "8.16.0",
39
+ "@typescript-eslint/parser": "8.16.0",
40
+ "eslint": "8.57.1",
41
+ "eslint-config-prettier": "9.1.0",
42
+ "eslint-plugin-prettier": "5.2.1",
43
+ "geojson": "^0.5.0",
44
+ "geojson-path-finder": "^2.0.2",
45
+ "jest": "^29.7.0",
46
+ "knip": "^5.38.1",
47
+ "microbundle": "0.15.1",
48
+ "serve": "^14.2.4",
49
+ "ts-jest": "^29.2.5",
50
+ "tsx": "^4.19.3",
51
+ "typedoc": "^0.28.1",
52
+ "typescript": "^5.8.3"
71
53
  },
72
- "extends": [
73
- "plugin:@typescript-eslint/recommended",
74
- "prettier"
75
- ]
76
- },
77
- "prettier": {
78
- "printWidth": 80,
79
- "semi": true,
80
- "useTabs": true
81
- },
82
- "knip": {
83
- "$schema": "https://unpkg.com/knip@5/schema.json",
84
- "entry": [
85
- "src/terra-route.ts"
86
- ],
87
- "project": [
88
- "src/**/*.ts"
54
+ "dependencies": {},
55
+ "keywords": [
56
+ "geojson",
57
+ "linestring",
58
+ "routing",
59
+ "pathfinding",
60
+ "network",
61
+ "geospatial",
62
+ "astar",
63
+ "djikstra"
89
64
  ],
90
- "include": [
91
- "files",
92
- "types"
93
- ]
94
- },
95
- "typedocOptions": {
96
- "entryPoints": [
97
- "src/terra-route.ts"
98
- ],
99
- "excludeExternals": true,
100
- "exclude": [
101
- "benchmark/",
102
- "coverage/",
103
- "dist/",
104
- "node_modules/"
105
- ],
106
- "out": "docs",
107
- "skipErrorChecking": true,
108
- "sourceLinkExternal": true
109
- }
65
+ "knip": {
66
+ "$schema": "https://unpkg.com/knip@5/schema.json",
67
+ "entry": [
68
+ "src/terra-route.ts"
69
+ ],
70
+ "project": [
71
+ "src/**/*.ts"
72
+ ],
73
+ "include": [
74
+ "files",
75
+ "types"
76
+ ]
77
+ },
78
+ "typedocOptions": {
79
+ "entryPoints": [
80
+ "src/terra-route.ts"
81
+ ],
82
+ "excludeExternals": true,
83
+ "exclude": [
84
+ "benchmark/",
85
+ "coverage/",
86
+ "dist/",
87
+ "node_modules/"
88
+ ],
89
+ "out": "docs",
90
+ "skipErrorChecking": true,
91
+ "sourceLinkExternal": true
92
+ }
110
93
  }
package/src/min-heap.ts CHANGED
@@ -38,38 +38,50 @@ export class MinHeap {
38
38
  }
39
39
 
40
40
  private bubbleDown(idx: number): void {
41
- const length = this.heap.length;
42
- const node = this.heap[idx];
41
+ const { heap } = this;
42
+ const length = heap.length;
43
+ // Grab the parent node once, then move it down only if needed
44
+ const node = heap[idx];
45
+ const nodeKey = node.key;
46
+ const nodeIndex = node.index;
43
47
 
44
48
  while (true) {
49
+ // Calculate left and right child indexes
45
50
  const leftIdx = (idx << 1) + 1;
46
- const rightIdx = leftIdx + 1;
47
- let smallestIdx = idx;
48
-
49
- if (
50
- leftIdx < length &&
51
- (this.heap[leftIdx].key < this.heap[smallestIdx].key ||
52
- (this.heap[leftIdx].key === this.heap[smallestIdx].key &&
53
- this.heap[leftIdx].index < this.heap[smallestIdx].index))
54
- ) {
55
- smallestIdx = leftIdx;
56
- }
57
-
58
- if (
59
- rightIdx < length &&
60
- (this.heap[rightIdx].key < this.heap[smallestIdx].key ||
61
- (this.heap[rightIdx].key === this.heap[smallestIdx].key &&
62
- this.heap[rightIdx].index < this.heap[smallestIdx].index))
63
- ) {
64
- smallestIdx = rightIdx;
51
+ if (leftIdx >= length) {
52
+ // No children => we’re already in place
53
+ break;
65
54
  }
66
55
 
67
- if (smallestIdx === idx) break;
56
+ // Assume left child is the smaller one by default
57
+ let smallestIdx = leftIdx;
58
+ let smallestKey = heap[leftIdx].key;
59
+ let smallestIndex = heap[leftIdx].index;
68
60
 
69
- this.heap[idx] = this.heap[smallestIdx];
70
- this.heap[smallestIdx] = node;
61
+ const rightIdx = leftIdx + 1;
62
+ if (rightIdx < length) {
63
+ // Compare left child vs. right child
64
+ const rightKey = heap[rightIdx].key;
65
+ const rightIndex = heap[rightIdx].index;
66
+ if (rightKey < smallestKey || (rightKey === smallestKey && rightIndex < smallestIndex)) {
67
+ smallestIdx = rightIdx;
68
+ smallestKey = rightKey;
69
+ smallestIndex = rightIndex;
70
+ }
71
+ }
71
72
 
72
- idx = smallestIdx;
73
+ // Compare the smaller child with the parent
74
+ if (smallestKey < nodeKey || (smallestKey === nodeKey && smallestIndex < nodeIndex)) {
75
+ // Swap the smaller child up
76
+ heap[idx] = heap[smallestIdx];
77
+ idx = smallestIdx;
78
+ } else {
79
+ // We’re in the correct position now, so stop
80
+ break;
81
+ }
73
82
  }
83
+
84
+ // Place the original node in its final position
85
+ heap[idx] = node;
74
86
  }
75
87
  }