Last active
September 19, 2019 19:56
-
-
Save frzi/a1bc8e2064bf1022c48151afd91aeb2f to your computer and use it in GitHub Desktop.
Polka Typescript definitions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Potential candidate for @types/polka. | |
*/ | |
// Type definitions for polka 1.0.0 | |
// Project: https://github.com/lukeed/polka | |
// Definitions by: Freek Zijlmans <https://github.com/frzi> | |
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | |
// TypeScript Version: 3.0 | |
/// <reference types="node" /> | |
/// <reference types="trouter" /> | |
import { IncomingMessage, ServerResponse } from 'http'; | |
import { Server } from 'net' | |
import Trouter from 'trouter'; | |
declare function polka(options?: polka.Options): polka.Polka; | |
declare namespace polka { | |
type NextHandler = (err?: Error | string) => void; | |
type RequestHandler = (req: IncomingMessage, res: ServerResponse, next?: NextHandler) => void; | |
type Middleware = Polka | RequestHandler; | |
type ErrorHandler = (err: Error | string, req: IncomingMessage, res: ServerResponse, next: NextHandler) => void; | |
interface Options { | |
onError?: ErrorHandler; | |
onNoMatch?: RequestHandler; | |
server?: typeof Server; | |
} | |
interface URLDescription { | |
_raw: string; | |
href: string; | |
path: string; | |
pathname: string; | |
query: string | null; | |
search: string | null; | |
} | |
interface Polka extends Trouter<RequestHandler> { | |
readonly server: typeof Server; | |
readonly wares: RequestHandler[]; | |
readonly onError: ErrorHandler; | |
readonly onNoMatch: RequestHandler; | |
attach: (req: IncomingMessage, res: ServerResponse) => void; | |
parse: (req: IncomingMessage) => URLDescription | void; | |
use(...handlers: Middleware[]): this; | |
use(pattern: string, ...handlers: Middleware[]): this; | |
readonly handler: RequestHandler | |
listen: Server['listen']; | |
} | |
} | |
export = polka; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey hey 👋
Checking in to let you know that
wares
has been removed