Socket
Socket
Sign inDemoInstall

h3

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3 - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

40

dist/index.d.ts

@@ -6,19 +6,19 @@ import { IncomingMessage, ServerResponse, OutgoingMessage } from 'node:http';

declare type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
declare type Encoding = false | "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
type HTTPMethod = "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE";
type Encoding = false | "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
interface H3EventContext extends Record<string, any> {
}
declare type EventHandlerResponse<T = any> = T | Promise<T>;
type EventHandlerResponse<T = any> = T | Promise<T>;
interface EventHandler<T = any> {
"__is_handler__"?: true;
__is_handler__?: true;
(event: H3Event): EventHandlerResponse<T>;
}
declare type LazyEventHandler = () => EventHandler | Promise<EventHandler>;
declare type RequestHeaders = {
type LazyEventHandler = () => EventHandler | Promise<EventHandler>;
type RequestHeaders = {
[name: string]: string | undefined;
};
declare type NodeListener = (req: IncomingMessage, res: ServerResponse) => void;
declare type NodePromisifiedHandler = (req: IncomingMessage, res: ServerResponse) => Promise<any>;
declare type NodeMiddleware = (req: IncomingMessage, res: ServerResponse, next: (err?: Error) => any) => any;
type NodeListener = (req: IncomingMessage, res: ServerResponse) => void;
type NodePromisifiedHandler = (req: IncomingMessage, res: ServerResponse) => Promise<any>;
type NodeMiddleware = (req: IncomingMessage, res: ServerResponse, next: (err?: Error) => any) => any;
declare const defineNodeListener: (handler: NodeListener) => NodeListener;

@@ -76,3 +76,3 @@ declare const defineNodeMiddleware: (middleware: NodeMiddleware) => NodeMiddleware;

get path(): string | undefined;
/** @deprecated Please use `event.node.res` instead. **/
/** @deprecated Please use `event.node.req` instead. **/
get req(): IncomingMessage;

@@ -102,3 +102,3 @@ /** @deprecated Please use `event.node.res` instead. **/

}
declare type Stack = Layer[];
type Stack = Layer[];
interface InputLayer {

@@ -110,4 +110,4 @@ route?: string;

}
declare type InputStack = InputLayer[];
declare type Matcher = (url: string, event?: H3Event) => boolean;
type InputStack = InputLayer[];
type Matcher = (url: string, event?: H3Event) => boolean;
interface AppUse {

@@ -159,6 +159,6 @@ (route: string | string[], handler: EventHandler | EventHandler[], options?: Partial<InputLayer>): App;

*/
declare function createError(input: string | Partial<H3Error> & {
declare function createError(input: string | (Partial<H3Error> & {
status?: number;
statusText?: string;
}): H3Error;
})): H3Error;
/**

@@ -186,3 +186,3 @@ * Receive an error and return the corresponding response.<br>

*/
declare function readRawBody(event: H3Event, encoding?: Encoding): Encoding extends false ? Buffer : Promise<string | Buffer | undefined>;
declare function readRawBody<E extends Encoding = "utf8">(event: H3Event, encoding?: E): E extends false ? Promise<Buffer | undefined> : Promise<string | undefined>;
/**

@@ -297,5 +297,5 @@ * Reads request body and try to safely parse using [destr](https://github.com/unjs/destr)

declare type RouterMethod = Lowercase<HTTPMethod>;
declare type RouterUse = (path: string, handler: EventHandler, method?: RouterMethod | RouterMethod[]) => Router;
declare type AddRouteShortcuts = Record<RouterMethod, RouterUse>;
type RouterMethod = Lowercase<HTTPMethod>;
type RouterUse = (path: string, handler: EventHandler, method?: RouterMethod | RouterMethod[]) => Router;
type AddRouteShortcuts = Record<RouterMethod, RouterUse>;
interface Router extends AddRouteShortcuts {

@@ -307,3 +307,5 @@ add: RouterUse;

interface CreateRouterOptions {
/** @deprecated Please use `preemptive` instead. **/
preemtive?: boolean;
preemptive?: boolean;
}

@@ -310,0 +312,0 @@ declare function createRouter(opts?: CreateRouterOptions): Router;

{
"name": "h3",
"version": "1.0.1",
"version": "1.0.2",
"description": "Tiny JavaScript Server",

@@ -22,16 +22,7 @@ "repository": "unjs/h3",

],
"scripts": {
"build": "unbuild",
"dev": "vitest",
"lint": "eslint --ext ts,mjs,cjs .",
"play": "jiti ./playground/index.ts",
"profile": "0x -o -D .profile -P 'autocannon -c 100 -p 10 -d 40 http://localhost:$PORT' ./playground/server.cjs",
"release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
"test": "pnpm lint && vitest run --coverage"
},
"dependencies": {
"cookie-es": "^0.5.0",
"destr": "^1.2.1",
"destr": "^1.2.2",
"radix3": "^1.0.0",
"ufo": "^1.0.0"
"ufo": "^1.0.1"
},

@@ -41,21 +32,31 @@ "devDependencies": {

"@types/express": "^4.17.14",
"@types/node": "^18.11.9",
"@types/node": "^18.11.14",
"@types/supertest": "^2.0.12",
"@vitest/coverage-c8": "^0.25.2",
"@vitest/coverage-c8": "^0.25.8",
"autocannon": "^7.10.0",
"changelogen": "^0.4.0",
"connect": "^3.7.0",
"eslint": "^8.27.0",
"eslint-config-unjs": "^0.0.2",
"eslint": "^8.29.0",
"eslint-config-unjs": "^0.0.3",
"express": "^4.18.2",
"get-port": "^6.1.2",
"jiti": "^1.16.0",
"listhen": "^1.0.0",
"listhen": "^1.0.1",
"node-fetch-native": "^1.0.1",
"supertest": "^6.3.1",
"typescript": "^4.8.4",
"unbuild": "^0.9.4",
"vitest": "^0.25.2"
"prettier": "^2.8.1",
"supertest": "^6.3.3",
"typescript": "^4.9.4",
"unbuild": "^1.0.2",
"vitest": "^0.25.8"
},
"packageManager": "pnpm@7.16.0"
}
"packageManager": "pnpm@7.18.2",
"scripts": {
"build": "unbuild",
"dev": "vitest",
"lint": "eslint --ext ts,mjs,cjs . && prettier -c src test playground",
"play": "jiti ./playground/index.ts",
"profile": "0x -o -D .profile -P 'autocannon -c 100 -p 10 -d 40 http://localhost:$PORT' ./playground/server.cjs",
"release": "pnpm test && pnpm build && changelogen --release && pnpm publish && git push --follow-tags",
"test": "pnpm lint && vitest run --coverage"
}
}

@@ -116,9 +116,9 @@ [![npm downloads](https://img.shields.io/npm/dm/h3.svg?style=flat-square)](https://npmjs.com/package/h3)

- `useRawBody(event, encoding?)`
- `useBody(event)`
- `useCookies(event)`
- `useCookie(event, name)`
- `readRawBody(event, encoding?)`
- `readBody(event)`
- `parseCookies(event)`
- `getCookie(event, name)`
- `setCookie(event, name, value, opts?)`
- `deleteCookie(event, name, opts?)`
- `useQuery(event)`
- `getQuery(event)`
- `getRouterParams(event)`

@@ -136,3 +136,3 @@ - `send(event, data, type?)`

- `sendError(event, error, debug?)`
- `useMethod(event, default?)`
- `getMethod(event, default?)`
- `isMethod(event, expected, allowHead?)`

@@ -146,13 +146,22 @@ - `assertMethod(event, expected, allowHead?)`

### Add-ons
## Community Packages
More composable utilities can be found in community packages.
You can use more h3 event utilities made by the community.
- `validateBody(event, schema)` from [h3-typebox](https://github.com/kevinmarrec/h3-typebox)
- `validateQuery(event, schema)` from [h3-typebox](https://github.com/kevinmarrec/h3-typebox)
- `useValidatedBody(event, schema)` from [h3-zod](https://github.com/wobsoriano/h3-zod)
- `useValidatedQuery(event, schema)` from [h3-zod](https://github.com/wobsoriano/h3-zod)
Please check their READMEs for more details.
PRs are welcome to add your packages.
- [h3-cors](https://github.com/NozomuIkuta/h3-cors)
- `defineCorsEventHandler(options)`
- `isPreflight(event)`
- [h3-typebox](https://github.com/kevinmarrec/h3-typebox)
- `validateBody(event, schema)`
- `validateQuery(event, schema)`
- [h3-zod](https://github.com/wobsoriano/h3-zod)
- `useValidatedBody(event, schema)`
- `useValidatedQuery(event, schema)`
## License
MIT

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