From 8118eb261b80998df19ac330c9999fdd2d1f8682 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Tue, 6 Oct 2020 16:42:07 -0700 Subject: [PATCH] feat: add typescript definitions --- index.d.ts | 18 ++++++++++++++++++ package.json | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..46b0ab6 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,18 @@ +declare module 'navaid' { + type Promisable = T | Promise; + + export type Params = Record; + export type UnknownHandler = (uri: string) => void; + export type RouteHandler = (params?: T) => Promisable; + + export interface Router { + format(uri: string): string | false; + route(uri: string, replace?: boolean): void; + on(pattern: string, handler: RouteHandler): Router; + run(uri?: string): Router; + listen(uri?: string): Router; + unlisten?: VoidFunction; + } + + export default function (base?: string, on404?: UnknownHandler): Router; +} diff --git a/package.json b/package.json index 7fa3f10..be6cc74 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "unpkg": "dist/navaid.min.js", "module": "dist/navaid.mjs", "main": "dist/navaid.js", + "types": "index.d.ts", "license": "MIT", "author": { "name": "Luke Edwards", @@ -21,6 +22,7 @@ "test": "uvu -r esm test" }, "files": [ + "*.d.ts", "dist" ], "keywords": [