Skip to content

Commit 2043cca

Browse files
committed
refactor: explicit extensions and types
1 parent 6cf82d7 commit 2043cca

File tree

16 files changed

+69
-45
lines changed

16 files changed

+69
-45
lines changed

src/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { NullProtoObj } from "./_utils";
2-
import type { RouterContext } from "./types";
1+
import { NullProtoObj } from "./_utils.ts";
2+
import type { RouterContext } from "./types.ts";
33

44
/**
55
* Create a new router context.

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export { createRouter } from "./context";
1+
export { createRouter } from "./context.ts";
22

3-
export type { RouterContext } from "./types";
3+
export type { RouterContext } from "./types.ts";
44

5-
export { addRoute } from "./operations/add";
6-
export { findRoute } from "./operations/find";
7-
export { removeRoute } from "./operations/remove";
8-
export { findAllRoutes } from "./operations/find-all";
5+
export { addRoute } from "./operations/add.ts";
6+
export { findRoute } from "./operations/find.ts";
7+
export { removeRoute } from "./operations/remove.ts";
8+
export { findAllRoutes } from "./operations/find-all.ts";

src/operations/_utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { NullProtoObj } from "../_utils";
2-
import type { MatchedRoute, ParamsIndexMap } from "../types";
1+
import { NullProtoObj } from "../_utils.ts";
2+
import type { MatchedRoute, ParamsIndexMap } from "../types.ts";
33

4-
export function splitPath(path: string) {
4+
export function splitPath(path: string): string[] {
55
return path.split("/").filter(Boolean);
66
}
77

src/operations/add.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { NullProtoObj } from "../_utils";
2-
import type { RouterContext, ParamsIndexMap } from "../types";
3-
import { splitPath } from "./_utils";
1+
import { NullProtoObj } from "../_utils.ts";
2+
import type { RouterContext, ParamsIndexMap } from "../types.ts";
3+
import { splitPath } from "./_utils.ts";
44

55
/**
66
* Add a route to the router context.
@@ -10,7 +10,7 @@ export function addRoute<T>(
1010
method: string = "",
1111
path: string,
1212
data?: T,
13-
) {
13+
): void {
1414
const segments = splitPath(path);
1515

1616
let node = ctx.root;

src/operations/find-all.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import type { RouterContext, Node, MatchedRoute, MethodData } from "../types";
2-
import { getMatchParams, splitPath } from "./_utils";
1+
import type {
2+
RouterContext,
3+
Node,
4+
MatchedRoute,
5+
MethodData,
6+
} from "../types.ts";
7+
import { getMatchParams, splitPath } from "./_utils.ts";
38

49
/**
510
* Find all route patterns that match the given path.

src/operations/find.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import type { RouterContext, MatchedRoute, Node, MethodData } from "../types";
2-
import { getMatchParams, splitPath } from "./_utils";
1+
import type {
2+
RouterContext,
3+
MatchedRoute,
4+
Node,
5+
MethodData,
6+
} from "../types.ts";
7+
import { getMatchParams, splitPath } from "./_utils.ts";
38

49
/**
510
* Find a route by path.

src/operations/remove.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { RouterContext, Node } from "../types";
2-
import { splitPath } from "./_utils";
1+
import type { RouterContext, Node } from "../types.ts";
2+
import { splitPath } from "./_utils.ts";
33

44
/**
55
* Remove a route from the router context.
@@ -8,7 +8,7 @@ export function removeRoute<T>(
88
ctx: RouterContext<T>,
99
method: string,
1010
path: string,
11-
) {
11+
): void {
1212
const segments = splitPath(path);
1313
return _remove(ctx.root, method || "", segments, 0);
1414
}

test/_utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { Node, RouterContext } from "../src/types";
2-
import { createRouter as _createRouter, addRoute } from "../src";
1+
import type { Node, RouterContext } from "../src/types.ts";
2+
import { createRouter as _createRouter, addRoute } from "../src/index.ts";
33

44
export function createRouter<
55
T extends Record<string, string> = Record<string, string>,
@@ -22,7 +22,7 @@ export function formatTree(
2222
depth = 0,
2323
result = [] as string[],
2424
prefix = "",
25-
) {
25+
): string | string[] {
2626
result.push(
2727
// prettier-ignore
2828
`${prefix}${depth === 0 ? "" : "├── "}${node.key ? `/${node.key}` : (depth === 0 ? "<root>" : "<?>")}${_formatMethods(node)}`,

test/basic.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from "vitest";
2-
import { createRouter, formatTree } from "./_utils";
3-
import { findRoute, removeRoute } from "../src";
2+
import { createRouter, formatTree } from "./_utils.ts";
3+
import { findRoute, removeRoute } from "../src/index.ts";
44

55
describe("Basic router", () => {
66
const router = createRouter([

test/bench/impl.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect } from "vitest";
2-
import { requests } from "./input";
3-
import { createInstances } from "./impl";
2+
import { requests } from "./input.ts";
3+
import { createInstances } from "./impl.ts";
44

55
describe("benchmark", () => {
66
const instances = createInstances();

0 commit comments

Comments
 (0)