Socket
Socket
Sign inDemoInstall

itty-router

Package Overview
Dependencies
Maintainers
2
Versions
265
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

itty-router - npm Package Compare versions

Comparing version 4.3.0-next.4 to 5.0.0-next.1

types.d.ts

10

AutoRouter.d.ts

@@ -1,8 +0,2 @@

import { RouteHandler } from 'IttyRouter';
import { ResponseHandler, RouterOptions } from './Router';
type AutoRouterOptions = {
missing?: RouteHandler;
format?: ResponseHandler;
} & RouterOptions;
export declare const AutoRouter: ({ format, missing, finally: f, before, ...options }?: AutoRouterOptions) => import("./Router").RouterType<import("IttyRouter").IRequest, any[]>;
export {};
import { AutoRouterOptions } from './types';
export declare const AutoRouter: ({ format, missing, finally: f, before, ...options }?: AutoRouterOptions) => import("types/RouterType").RouterType<import("types/IRequest").IRequest, any[]>;

2

cors.d.ts

@@ -1,2 +0,2 @@

import { IRequest } from 'IttyRouter';
import { IRequest } from './types';
export type CorsOptions = {

@@ -3,0 +3,0 @@ credentials?: true;

@@ -1,7 +0,2 @@

export interface ResponseFormatter {
(body?: any, options?: ResponseInit): Response;
}
export interface BodyTransformer {
(body: any): string;
}
export declare const createResponse: (format?: string, transform?: BodyTransformer) => ResponseFormatter;
import { ResponseFormatter } from './types';
export declare const createResponse: (format?: string, transform?: ((body: any) => any) | undefined) => ResponseFormatter;

@@ -1,11 +0,2 @@

interface ErrorLike extends Error {
status?: number;
[any: string]: any;
}
export type ErrorBody = string | object;
export interface ErrorFormatter {
(statusCode?: number, body?: ErrorBody): Response;
(error: ErrorLike): Response;
}
import { ErrorFormatter } from './types';
export declare const error: ErrorFormatter;
export {};

@@ -1,1 +0,1 @@

export declare const html: import("./createResponse").ResponseFormatter;
export declare const html: import("types").ResponseFormatter;

@@ -18,1 +18,2 @@ export * from './IttyRouter';

export * from './cors';
export * from './types';

@@ -1,51 +0,2 @@

export type GenericTraps = Record<string, any>;
export type RequestLike = {
method: string;
url: string;
} & GenericTraps;
export type IRequestStrict = {
method: string;
url: string;
route: string;
params: {
[key: string]: string;
};
query: {
[key: string]: string | string[] | undefined;
};
proxy?: any;
} & Request;
export type IRequest = IRequestStrict & GenericTraps;
export type IttyRouterOptions = {
base?: string;
routes?: RouteEntry[];
} & Record<string, any>;
export type RouteHandler<R = IRequest, Args extends Array<any> = any[]> = {
(request: R, ...args: Args): any;
};
export type RouteEntry = [
httpMethod: string,
match: RegExp,
handlers: RouteHandler[],
path?: string
];
export type Route<R = IRequest, A extends Array<any> = any[]> = <RequestType = R, Args extends Array<any> = A>(path: string, ...handlers: RouteHandler<RequestType, Args>[]) => IttyRouterType<RequestType, Args>;
export type UniversalRoute<RequestType = IRequest, Args extends any[] = any[]> = (path: string, ...handlers: RouteHandler<RequestType, Args>[]) => IttyRouterType<UniversalRoute<RequestType, Args>, Args>;
export type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
export type CustomRoutes<R = Route> = {
[key: string]: R;
};
export type IttyRouterType<R = IRequest, A extends any[] = any[], Output = any> = {
__proto__: IttyRouterType<R>;
routes: RouteEntry[];
fetch: <Args extends any[] = A>(request: RequestLike, ...extra: Args) => Promise<Output>;
all: Route<R, A>;
delete: Route<R, A>;
get: Route<R, A>;
head: Route<R, A>;
options: Route<R, A>;
patch: Route<R, A>;
post: Route<R, A>;
put: Route<R, A>;
} & CustomRoutes<Route<R, A>>;
export declare const IttyRouter: <RequestType = IRequest, Args extends any[] = any[]>({ base, routes, ...other }?: IttyRouterOptions) => IttyRouterType<RequestType, Args>;
import { IRequest, IttyRouterOptions, IttyRouterType } from './types';
export declare const IttyRouter: <RequestType extends IRequest = IRequest, Args extends any[] = any[]>({ base, routes, ...other }?: IttyRouterOptions) => IttyRouterType<RequestType, Args>;

@@ -1,1 +0,1 @@

export declare const jpeg: import("./createResponse").ResponseFormatter;
export declare const jpeg: import("types").ResponseFormatter;

@@ -1,1 +0,1 @@

export declare const json: import("./createResponse").ResponseFormatter;
export declare const json: import("types").ResponseFormatter;
{
"name": "itty-router",
"version": "4.3.0-next.4",
"version": "5.0.0-next.1",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",

@@ -79,2 +79,7 @@ "main": "./index.js",

},
"./types": {
"import": "./types.mjs",
"require": "./types.js",
"types": "./types.d.ts"
},
"./webp": {

@@ -81,0 +86,0 @@ "import": "./webp.mjs",

@@ -1,1 +0,1 @@

export declare const png: import("./createResponse").ResponseFormatter;
export declare const png: import("types").ResponseFormatter;

@@ -12,4 +12,4 @@ <p align="center">

</a>
<a href="https://deno.bundlejs.com/?q=itty-router/Router" target="_blank">
<img src="https://deno.bundlejs.com/?q=itty-router/Router&badge&badge-style=flat-square" alt="bundle size" />
<a href="https://edge.bundlejs.com/?q=itty-router/Router" target="_blank">
<img src="https://edge.bundlejs.com/?q=itty-router/Router&badge&badge-style=flat-square" alt="bundle size" />
</a>

@@ -45,2 +45,4 @@ <a href="https://github.com/kwhitley/itty-router/actions/workflows/verify.yml" target="_blank">

### [v5.x Documentation](https://itty.dev/itty-router) &nbsp; | &nbsp; [Discord](https://discord.gg/53vyrZAu9u)
---

@@ -50,13 +52,17 @@

## Features
- Tiny. We have routers from [~450 bytes](https://itty.dev/itty-router/routers/ittyrouter) to a [~1kB bytes](https://itty.dev/itty-router/routers/autorouter) batteries-included version. For comparison, [express.js](https://www.npmjs.com/package/express) is over 200x as large.
- Web Standards - Use it [anywhere, in any environment](https://itty.dev/itty-router/runtimes).
- No assumptions. Return anything you like, pass in any arguments you like.
- Tiny. Routers from [~450 bytes](https://itty.dev/itty-router/routers/ittyrouter) to a [~970 bytes](https://itty.dev/itty-router/routers/autorouter) batteries-included version (~240-500x smaller than Express.js).
- Web Standards. Use it [anywhere, in any environment](https://itty.dev/itty-router/runtimes).
- No assumptions. Return anything; pass in anything.
- Dead-simple user-code. We want _your_ code to be tiny too.
- Future-proof. HTTP methods not-yet-invented already work with it.
- [Route-parsing](https://itty.dev/itty-router/route-patterns) & [query parsing](https://itty.dev/itty-router/route-patterns#query).
- [Middleware](https://itty.dev/itty-router/middleware) - use ours or write your own.
- [Nesting](https://itty.dev/itty-router/nesting).
- [Supports Nesting](https://itty.dev/itty-router/nesting).
## Example (Cloudflare Worker or Bun)
## Example

@@ -78,44 +84,14 @@ ```js

# [Full Documentation](https://itty.dev/itty-router) @ [itty.dev](https://itty.dev)
<br />
Complete API documentation is available at [itty.dev/itty-router](https://itty.dev/itty-router), or join our [Discord](https://discord.gg/53vyrZAu9u) channel to chat with community members for quick help!
## Need Help?
[Complete API documentation](https://itty.dev/itty-router) is available on [itty.dev](https://itty.dev/itty-router), or join our [Discord](https://discord.gg/53vyrZAu9u) channel to chat with community members for quick help!
## Join the Discussion!
Have a question? Suggestion? Idea? Complaint? Want to send a gift basket? Join us on [Discord](https://discord.gg/53vyrZAu9u)!
Have a question? Suggestion? Idea? Complaint? Want to send a gift basket?
# A Special Thanks :heart:
Join us on [Discord](https://discord.gg/53vyrZAu9u)!
As the community and contributor list has grown (and thus an individualized list here is no longer easily maintainable), I'd like to thank each and every one of you for making itty far greater than its humble origins. The robustness you see today, the careful consideration of every byte spent on features, the API choices, the code-golfing itself... are all thanks to the efforts and feedback from the community. I'd especially like to thank the core contributors and PR-authors, as well as the fantastic folks on the [itty Discord](https://discord.gg/53vyrZAu9u) group, for their tireless work refining this little beast and answering community questions.
## Special Thanks: Contributors
These folks are the real heroes, making open source the powerhouse that it is! Help out and get your name added to this list! <3
#### Constant Feedback, Suggestions, Moral Support & Community Building
- TBD
#### Core Concepts
- [@mvasigh](https://github.com/mvasigh) - proxy hack wizard behind itty, coding partner in crime, maker of the entire doc site, etc, etc.
- [@hunterloftis](https://github.com/hunterloftis) - router.handle() method now accepts extra arguments and passed them to route functions
- [@SupremeTechnopriest](https://github.com/SupremeTechnopriest) - improved TypeScript support and documentation! :D
#### Code Golfing
- [@taralx](https://github.com/taralx) - router internal code-golfing refactor for performance and character savings
- [@DrLoopFall](https://github.com/DrLoopFall) - v4.x re-minification
#### Fixes & Build
- [@taralx](https://github.com/taralx) - QOL fixes for contributing (dev dep fix and test file consistency) <3
- [@technoyes](https://github.com/technoyes) - three kind-of-a-big-deal errors fixed. Imagine the look on my face... thanks man!! :)
- [@roojay520](https://github.com/roojay520) - TS interface fixes
- [@jahands](https://github.com/jahands) - v4.x TS fixes
- and many, many others
#### Documentation
- [@arunsathiya](https://github.com/arunsathiya),
[@poacher2k](https://github.com/poacher2k),
[@ddarkr](https://github.com/ddarkr),
[@kclauson](https://github.com/kclauson),
[@jcapogna](https://github.com/jcapogna)

@@ -1,14 +0,2 @@

import { IRequest, IttyRouterOptions, IttyRouterType, Route, RouteHandler } from './IttyRouter';
export type ResponseHandler<ResponseType = any, RequestType = IRequest, Args extends any[] = any[]> = (response: ResponseType, request: RequestType, ...args: Args) => any;
export type ErrorHandler<ErrorType = Error, RequestType = IRequest, Args extends any[] = any[]> = (response: ErrorType, request: RequestType, ...args: Args) => any;
export type RouterType<R = Route, Args extends any[] = any[]> = {
before?: RouteHandler[];
catch?: ErrorHandler;
finally?: ResponseHandler[];
} & IttyRouterType<R, Args>;
export type RouterOptions = {
before?: RouteHandler[];
catch?: ErrorHandler;
finally?: ResponseHandler[];
} & IttyRouterOptions;
import { IRequest, RouterOptions, RouterType } from './types';
export declare const Router: <RequestType = IRequest, Args extends any[] = any[]>({ base, routes, ...other }?: RouterOptions) => RouterType<RequestType, Args>;

@@ -1,1 +0,1 @@

export declare const text: import("./createResponse").ResponseFormatter;
export declare const text: import("types").ResponseFormatter;

@@ -1,1 +0,1 @@

export declare const webp: import("./createResponse").ResponseFormatter;
export declare const webp: import("types").ResponseFormatter;

@@ -1,5 +0,2 @@

import { IRequest, IRequestStrict } from './IttyRouter';
export type HasContent<ContentType> = {
content: ContentType;
} & IRequestStrict;
import { IRequest } from './types';
export declare const withContent: (request: IRequest) => Promise<void>;

@@ -1,2 +0,2 @@

import { IRequest } from './IttyRouter';
import { IRequest } from './types';
export declare const withCookies: (r: IRequest) => void;

@@ -1,2 +0,2 @@

import { IRequest } from './IttyRouter';
import { IRequest } from './types';
export declare const withParams: (request: IRequest) => void;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc