open-index/open-npm huggingface dataset:
npm package: @hatsy/serve-static
Description: Hatsy request handler that serves static content
Author: Ruslan Lopatin
Latest version: 3.0.0

# Static Content Handler

[![NPM][npm-image]][npm-url]
[![Build Status][build-status-img]][build-status-link]
[![Code Quality][quality-img]][quality-link]
[![Coverage][coverage-img]][coverage-link]
[![GitHub Project][github-image]][github-url]
[![API Documentation][api-docs-image]][api documentation]

[npm-image]: https://img.shields.io/npm/v/@hatsy/serve-static.svg?logo=npm
[npm-url]: https://www.npmjs.com/package/@hatsy/serve-static
[build-status-img]: https://github.com/hatsyjs/serve-static/workflows/Build/badge.svg
[build-status-link]: https://github.com/hatsyjs/serve-static/actions?query=workflow:Build
[quality-img]: https://app.codacy.com/project/badge/Grade/605eb2284cdd4152bdc5f7388ac83854
[quality-link]: https://www.codacy.com/gh/hatsyjs/serve-static/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hatsyjs/serve-static&utm_campaign=Badge_Grade
[coverage-img]: https://app.codacy.com/project/badge/Coverage/605eb2284cdd4152bdc5f7388ac83854
[coverage-link]: https://www.codacy.com/gh/hatsyjs/serve-static/dashboard?utm_source=github.com&utm_medium=referral&utm_content=hatsyjs/serve-static&utm_campaign=Badge_Coverage
[github-image]: https://img.shields.io/static/v1?logo=github&label=GitHub&message=project&color=informational
[github-url]: https://github.com/hatsyjs/serve-static
[api-docs-image]: https://img.shields.io/static/v1?logo=typescript&label=API&message=docs&color=informational
[api documentation]: https://hatsyjs.github.io/serve-static

## serveStatic()

This module contains a [serveStatic()] factory of request handler able to serve static content.

It is based on [send] and can be configured with [similar options][servestaticconfig].

```typescript
import { httpListener } from '@hatsy/hatsy';
import { dispatchByName, Routing } from '@hatsy/router';
import { serveStatic } from '@hatsy/serve-static';
import { createServer } from 'http';

const server = createServer(
  httpListener(
    Routing.for(
      dispatchByName({
        assets: serveStatic('static_html/assets', { extensions: ['png', 'jpeg', 'gif'] }),
      }),
    ),
  ),
);

server.listen(8080);
```

[send]: https://www.npmjs.com/package/send
[servestatic()]: https://hatsyjs.github.io/serve-static/modules.html#serveStatic
[servestaticconfig]: https://hatsyjs.github.io/serve-static/interfaces/ServeStaticConfig.html
npm package: @hatterjiang/term-color-render
Description: Render color for term use syntax like [red]text[/red]
Author: Hatter Jiang
Latest version: 1.0.3

# term color render

```js
import { renderColor } from "@hatterjiang/term-color-render";

console.log(renderColor('hello [red]red world[/red], [bold][green]bold and green text[/green][/bold]'));
```


Supported colors:
- `[red]red text[/red]`
- `[blue]blue text[/blue]`
- `[green]green text[/green]`
- `[yellow]yellow text[/yellow]`
- `[cyan]cyan text[/cyan]`
- `[pink]cyan text[/pink]`
- `[bold]bold text[/bold]`
- `[under]under text[/under]`
npm package: @hattip/adapter-bun
Description: Bun adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-bun`

Hattip adapter for [Bun](https://bun.sh).

## Usage

Assuming you have your Hattip handler defined in `handler.js` and your static assets are in the `public` directory, create an `entry-bun.js` file like the following and use `bun entry-bun.js` to run it:

```ts
import bunAdapter from "@hattip/adapter-bun";
import handler from "./handler.js";
import url from "node:url";
import path from "node:path";

const dir = path.resolve(
  path.dirname(url.fileURLToPath(new URL(import.meta.url))),
  "public",
);

export default bunAdapter(handler, { staticDir: dir });
```

You can leave out the `staticDir` option if you don't want to serve static assets.

## Options

- `staticDir`: The directory to serve static assets from. Leave undefined to not serve static assets.
- `trustProxy`: Whether to trust the `X-Forwarded-For` header.

The remaining options (`port`, `hostname` etc.) are passed to [Bun.serve](https://github.com/oven-sh/bun#bunserve---fast-http-server).

## `context.platform`

```ts
export interface BunPlatformInfo {
  /** Platform name */
  name: "bun";
  /** Bun server instance */
  server: Server;
}
```

## Environment variables

The `ctx.env()` function is implemented using `process.env`.

## Limitations

Bun support is preliminary and Bun itself is in early development:

- No way to determine the IP address of the client when `trustProxy` is false.
- No streaming, everything is cached.
npm package: @hattip/adapter-cloudflare-workers
Description: Cloudflare Workers adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-cloudflare-workers`

Hattip adapter for [Cloudflare Workers](https://workers.cloudflare.com).

## Usage

Assuming you have your Hattip handler defined in `handler.js`, create an entry file like the following and use [`@hattip/bundler-cloudflare-workers`](../../bundler/bundler-cloudflare-workers) or your favorite bundler to bundle it:

```js
import cloudflareWorkersAdapter from "@hattip/adapter-cloudflare-workers";
import handler from "./handler.js";

export default {
  fetch: cloudflareWorkersAdapter(handler),
};
```

If you don't need to serve static files, you can import the adapter from `@hattip/adapter-cloudflare-workers/no-static` instead. You will get an error if you use the default adapter but you don't set up `site = { bucket = "<YOUR STATIC FILES DIR>" }` in your `wrangler.toml`.

`@hattip/adapter-cloudflare-workers` uses the newer [modules format](https://blog.cloudflare.com/workers-javascript-modules) instead of the service worker format.

## `context.platform`

```ts
export interface CloudflareWorkersPlatformInfo {
  /** Platform name */
  name: "cloudflare-workers";
  /**
   * Bindings for secrets, environment variables, and other resources like
   * KV namespaces etc.
   */
  env: unknown;
  /**
   * Execution context
   */
  context: ExecutionContext;
}
```

## Environment variables

The `ctx.env()` function only returns bindings with a string value. Such bindings correspond to [secrets and environment variables](https://developers.cloudflare.com/workers/platform/environment-variables). [Other bindings](https://developers.cloudflare.com/workers/configuration/bindings) like KV or D1 will return `undefined`. You should use `ctx.platform.env` to access them instead.
npm package: @hattip/adapter-deno
Description: Deno adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-deno`

Hattip adapter for [Deno](https://deno.land). It requires Deno version 1.35.0 or higher.

## Usage

Assuming you have your Hattip handler defined in `handler.ts`, create an entry file like the following and run with `deno run -A entry.ts`:

```js
import { createServeHandler } from "npm:@hattip/adapter-deno";
import handler from "./handler.ts";

Deno.serve(createServeHandler(handler));
```

## Serving static files

If you want to serve static files, you can use the `serveDir` function from `std/http/file_server.ts`. Assuming your static files are in the `public` directory, you can use the following:

```js
import { createRequestHandler } from "npm:@hattip/adapter-deno";
import hattipHandler from "./handler.js";
import { serveDir } from "https://deno.land/std/http/file_server.ts";

const handler = createRequestHandler(hattipHandler);

Deno.serve(async (request, connInfo) => {
  const staticResponse = await serveDir(request, { fsRoot: "./public" });

  if (staticResponse.status !== 404) {
    return staticResponse;
  }

  return handler(request, connInfo);
});
```

## `context.platform`

`contex.platform.info` is a [`Deno.ServeHandlerInfo`](https://deno.land/api?s=Deno.ServeHandlerInfo) object.

## Environment variables

Usage of `ctx.env()` function requires `--allow-env` flag.
npm package: @hattip/adapter-fastly
Description: Fastly adapter for Hattip
Author: Jake Champion
Latest version: 0.0.49

# `@hattip/adapter-fastly`

Hattip adapter for [Fastly](https://developer.fastly.com/).

## Usage

Assuming you have your Hattip handler defined in `handler.js`, create an entry file like the following:

```js
import fastlyAdapter from "@hattip/adapter-fastly";
import handler from "./handler.js";

export default fastlyAdapter(handler);
```

## Static assets

To serve static assets, scaffold a project with [Fastly Static Publisher](https://github.com/fastly/compute-js-static-publish). Put your Hattip handler in `src/handler.js` and replace `src/index.js` with the following:

```js
import fastlyAdapter from "@hattip/adapter-fastly";
import handler from "./handler.js";
import { getServer } from "./statics.js";
const staticContentServer = getServer();

export default fastlyAdapter(async (ctx) => {
  const response = await staticContentServer.serveRequest(ctx.request);
  if (response != null) {
    return response;
  }

  return handler(ctx);
});
```

## `context.platform`

```ts
export interface FastlyPlatformInfo {
  /** Platform name */
  name: "fastly-compute";
  /** Event object */
  event: FetchEvent;
}
```

## Limitations

- Fastly doesn't support constructing a `Request` object with a stream body.
- Fastly doesn't support the `AES-GCM` crypto algorithm used by `@hattip/session`'s `EncryptedCookieStore`.
npm package: @hattip/adapter-lagon
Description: Lagon adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-lagon`

Hattip adapter for [Lagon](https://lagon.app/).

## Usage

Assuming you have your Hattip handler defined in `handler.js`, create an `entry-lagon.js` file like the following and use `lagon dev entry-lagon.js` to run it locally:

```ts
import lagonAdapter from "@hattip/adapter-lagon";
import hattipHandler from "./handler.js";

export const handler = lagonAdapter(hattipHandler);
```

The `lagon` command is provided by the `@lagon/cli` package. Lagon CLI takes care of the bundling, so you don't need a separate bundling step.

## Limitations

Lagon support is preliminary as Lagon itself is in early development.
npm package: @hattip/adapter-netlify-edge
Description: Netlify Edge Functions adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-netlify-edge`

Hattip adapter for [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions).

## Usage

Assuming you have your Hattip handler defined in `handler.js`, create an entry file like the following and use [`@hattip/bundler-netlify`](../../bundler/bundler-netlify) or your favorite bundler to bundle it:

```js
import netlifyEdgeAdapter from "@hattip/adapter-netlify-edge";
import handler from "./handler.js";

export default netlifyEdgeAdapter(handler);
```

## `context.platform`

```ts
interface NetlifyEdgePlatformInfo {
  /** Platform name */
  name: "netlify-edge";
  /** Netlify-specific context object */
  context: NetlifyContext;
}
```

See [Netlify's documentation](https://docs.netlify.com/functions/build-with-javascript/#synchronous-function-format) for the Netlify-specific context object.
npm package: @hattip/adapter-netlify-functions
Description: Netlify Functions adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-netlify-functions`

Hattip adapter for [Netlify Functions](https://docs.netlify.com/functions/overview/).

## Usage

Assuming you have your Hattip handler defined in `handler.js`, create an entry file like the following and use [`@hattip/bundler-netlify`](../../bundler/bundler-netlify) or your favorite bundler to bundle it:

```js
import netlifyFunctionsAdapter from "@hattip/adapter-netlify-functions";
import hattipHandler from "./handler.js";

export const handler = netlifyFunctionsAdapter(hattipHandler);
```

## `fetch` implementation

This adapter uses [`node-fetch`](https://github.com/node-fetch/node-fetch) as its `fetch` implementation.

## `context.passThrough` behavior

Calling `context.passThrough` has no effect, the placeholder response will be returned.

## `context.platform`

```ts
export interface NetlifyFunctionsPlatformInfo {
  name: "netlify-functions";
  event: NetlifyFunctionEvent;
  context: NetlifyFunctionContext;
}
```
npm package: @hattip/adapter-uwebsockets
Description: uWebSockets.js adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-uwebsockets`

Hattip adapter for [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) on Node.js.

## Usage

```js
import { createServer } from "@hattip/adapter-uwebsockets";
import handler from "./handler.js";

createServer(handler).listen(3000, "localhost", () => {
  console.log("Server listening on http://localhost:3000");
});
```

## API

```ts
/**
 * Create an HTTP server
 */
function createServer(
  handler: Handler,
  adapterOptions?: UWebSocketsAdapterOptions,
  appOptions?: appOptions,
): TemlateApp;

/** Adapter options */
export interface UWebSocketAdapterOptions {
  /**
   * Set the origin part of the URL to a constant value.
   * It defaults to `process.env.ORIGIN`. If neither is set,
   * the origin is computed from the protocol and hostname.
   * To determine the protocol, `req.protocol` is tried first.
   * If `trustProxy` is set, `X-Forwarded-Proto` header is used.
   * Otherwise, `req.socket.encrypted` is used.
   * To determine the hostname, `X-Forwarded-Host`
   * (if `trustProxy` is set) or `Host` header is used.
   */
  origin?: string;
  /**
   * Whether to trust `X-Forwarded-*` headers. `X-Forwarded-Proto`
   * and `X-Forwarded-Host` are used to determine the origin when
   * `origin` and `process.env.ORIGIN` are not set. `X-Forwarded-For`
   * is used to determine the IP address. The leftmost values are used
   * if multiple values are set. Defaults to true if `process.env.TRUST_PROXY`
   * is set to `1`, otherwise false.
   */
  trustProxy?: boolean;
  /** Use SSL (https) */
  ssl?: boolean;
  /** Static file directory */
  staticDir?: string;
  /**
   * Callback to configure the uWebSockets.js app.
   * Useful for adding WebSocket or HTTP routes before the Hattip handler
   * is added.
   */
  configureServer?: (app: TemplatedApp) => void;
}
```

## Limitations

This adapter is experimental. In particular, the static file server is very limited at the moment.

## Using native `fetch`

This adapter uses [`node-fetch`](https://github.com/node-fetch/node-fetch) if the `fetch` global is not available. You can disable this behavior by importing your adapter from `@hattip/adapter-uwebsockets/native-fetch`, which will throw an error if `fetch` is not available.

## `context.platform`

This adapter makes uWebSockets.js `request` (`HTTPRequest`) and `response` (`HTTPResponse`) objects available in `context.platform`.
npm package: @hattip/adapter-vercel-edge
Description: Vercel Edge Functions adapter for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/adapter-vercel-edge`

Hattip adapter for [Vercel Edge Functions](https://vercel.com/features/edge-functions).

## Usage

Assuming you have your Hattip handler defined in `handler.js`, create an entry file like the following and use [`@hattip/bundler-vercel`](../../bundler/bundler-vercel) or your favorite bundler to bundle it:

```js
import vercelEdgeAdapter from "@hattip/adapter-vercel-edge";
import handler from "./handler.js";

export default vercelEdgeAdapter(handler);
```

## `context.passThrough` behavior

The `vercelEdgeAdapter` function takes an optional second argument which is a boolean indicating whether the edge function is supposed to act like a middleware. It defaults to `false`. When `true`, calling `context.passThrough` will pass the request to the serverless function, otherwise, it will be ignored and the response will be returned as is.

## `context.platform`

This adapter's platform context contains the property `event` which is of type [`FetchEvent`](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent).
npm package: @hattip/bundler-aws-lambda
Description: AWS Lambda bundler for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/bundler-aws-lambda`

Hattip bundler for [AWS Lambda](https://aws.amazon.com/lambda). It uses [`esbuild`](https://esbuild.github.io) behind the scenes.

## CLI

```
Usage:
  $ hattip-aws-lambda <input> <output>

Commands:
  <input> <output>  Bundle the AWS Lambda Hattip app in <input> into <output> as a ZIP file for deployment

For more info, run any command with the `--help` flag:
  $ hattip-aws --help

Options:
  -c, --copy <path>  Copy the file/directory at <path> next to the output. Can be specified multiple times.
  --no-zip           Don't zip the output. <output> will then be the output directory. (default: true)
  -h, --help         Display this message
  -v, --version      Display version number
```

The input must be a module that exports an AWS handler entry similar to the following:

```js
import awsLambdaAdapter from "@hattip/adapter-aws-lambda";
// or import from "@hattip/adapter-aws-lambda/streaming" for streaming responses
import hattipHandler from "./handler.js";

export const handler = awsLambdaAdapter(hattipHandler);
```

The output is either a ZIP file or a directory containing the bundled app depending on whether the `--no-zip` flag is specified.

You can use the `--copy` flag to copy additional files or directories next to the output. This can be used for copying static assets to be served by the app.

## JavaScript API

```js
import { bundle } from "@hattip/bundler-aws-lambda";

// You can specify either `cfwEntry` or `handlerEntry` but not both.
await bundle({
  /** The entry point for the AWS Lambda handler */
  input: "path/to/entry.js",
  /** The output file or directory */
  output: "lambda.zip",
  /** Whether to zip the output */
  zip: true,
  /** Files or directories to copy next to the output */
  copy: ["path/to/public"],
});
```

The bundling function also accepts a second argument, a callback that is called with an esbuild options object for customizing the build.
npm package: @hattip/bundler-cloudflare-workers
Description: Cloudflare Workers bundler for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/bundler-cloudflare-workers`

Hattip bundler for [Cloudflare Workers](https://workers.cloudflare.com). It uses [`esbuild`](https://esbuild.github.io) behind the scenes.

## CLI

```
hattip-cloudflare-workers [...options] <input> <output>

Bundle the Hattip app in <input> into <output> as a Clourflare Workers module.

Options:
  -e, --entry    Interpret <input> as a Cloudflare Workers module entry instead of a Hattip handler entry
  -h, --help     Display this message
  -v, --version  Display version number
```

The input can be either a module that default exports a Hattip handler entry or a Cloudflare Workers module similar to the following:

```js
import cloudflareWorkersAdapter from "@hattip/adapter-cloudflare-workers";
import handler from "./handler.js";

export default {
  fetch: cloudflareWorkersAdapter(handler),
};
```

The output is a Clourflare Workers bundle that can be deployed with `wrangler` or tested with `wrangler dev`.

## JavaScript API

```js
import bundler from "@hattip/bundler-cloudflare-workers";

// You can specify either `cfwEntry` or `handlerEntry` but not both.
bundler({
  // cfwEntry: "entry-cloudflare-workers.js",
  handlerEntry: "./handler.js",
  output: "./cfw-bundle.js",
}).then(() => {
  console.log("Bundle complete");
});
```

The bundling function also accepts a second argument, a callback that is called with an esbuild options object for customizing the build.
npm package: @hattip/bundler-deno
Description: Deno bundler for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/bundler-deno`

Hattip bundler for [Deno](https://deno.land). It uses [`esbuild`](https://esbuild.github.io) behind the scenes.

## CLI

```
hattip-deno <input> <output>

Bundle the Hattip app in <input> into <output> as a Deno module.

Options:
  -h, --help     Display this message
  -v, --version  Display version number
```

The input should be a Deno module similar to the following:

```js
import { createRequestHandler } from "@hattip/adapter-deno";
import handler from "./handler.js";

Deno.serve(createRequestHandler(handler), { port: 3000 });
```

If you want serve static files too, you can use the `serveDir` function. Assuming your static files are in the `public` directory, you can use the following:

```js
import { serve, serveDir, createRequestHandler } from "@hattip/adapter-deno";
import hattipHandler from "./handler.js";

const handler = createRequestHandler(hattipHandler);

serve(
  async (request, connInfo) => {
    const staticResponse = await serveDir(request, { fsRoot: "./public" });

    if (staticResponse.status !== 404) {
      return staticResponse;
    }

    return handler(request, connInfo);
  },
  {
    port: 3000,
  },
);
```

The output is a Deno module that can be run with `deno run` or deployed to [Deno Deploy](https://deno.com/deploy).

## JavaScript API

🚧 TODO 🚧

Refer to the TypeScript for the time being.
npm package: @hattip/bundler-netlify
Description: Netlify bundler for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/bundler-netlify`

Hattip bundler for [Netlify Functions](https://docs.netlify.com/functions/overview) and [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions). It uses [`esbuild`](https://esbuild.github.io) behind the scenes.

## CLI

```
hattip-netlify
    Bundle a Hattip app for Netlify

For more info, run any command with the `--help` flag:
  $ hattip-netlify --help

Options:
  -o, --outputDir <path>  Root directory of the app
  -c, --clearOutputDir    Clear the output directory before bundling
  -s, --staticDir <path>  Static directory to copy to output
  -e, --edge <path>       Edge function entry file
  -S, --func <path>       Regular function entry file
  -h, --help              Display this message
  -v, --version           Display version number
```

The edge function entry should be in the following form:

```js
import netlifyEdgeAdapter from "@hattip/adapter-netlify-edge";
import handler from "./handler.js";

export default netlifyEdgeAdapter(handler);
```

The regular function entry should be in the following form:

```js
import netlifyFunctionsAdapter from "@hattip/adapter-netlify-functions";
import hattipHandler from "./handler.js";

export const handler = netlifyFunctionsAdapter(hattipHandler);
```

## JavaScript API

🚧 TODO 🚧

Refer to the TypeScript for the time being.
npm package: @hattip/bundler-vercel
Description: Vercel bundler for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/bundler-vercel`

Hattip bundler for [Vercel Serverless Functions](https://vercel.com/docs/concepts/functions#serverless-functions) and [Vercel Edge Functions](https://vercel.com/docs/concepts/functions#serverless-functions). It uses [`esbuild`](https://esbuild.github.io) behind the scenes.

## CLI

```
hattip-vercel
    Bundle a Hattip app for Vercel

Options:
  -o, --outputDir <path>   Root directory of the app
  -c, --clearOutputDir     Clear the output directory before bundling
  -s, --staticDir <path>   Static directory to copy to output
  -e, --edge <path>        Edge function entry file
  -S, --serverless <path>  Serverless function entry file
  -h, --help               Display this message
  -v, --version            Display version number
```

The edge function entry should be in the following form:

```js
import adapterVercel from "@hattip/adapter-vercel-edge";
import handler from "./handler.js";

export default adapterVercel(handler);
```

The serverless function entry should be in the following form:

```js
import { createMiddleware } from "@hattip/adapter-node";
import handler from "./handler.js";

export default createMiddleware(handler, { trustProxy: true });
```

The bundler output (by default `.vercel/output`) is compatible with the [Vercel Build Output API (v3)](https://vercel.com/docs/build-output-api/v3).

## JavaScript API

🚧 TODO 🚧

Refer to the TypeScript for the time being.
npm package: @hattip/cookie
Description: Cookie management for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/cookie`

Cookie parsing and serialization middleware for Hattip. This package exports three middleware functions:

## `cookie`

Creates a middleware that parses incoming cookies and serializes outgoing cookies. It combines the functionality of the `cookieParser` and `cookieSerializer`.

## `cookieParser`

Creates a middleware that parses incoming cookies and makes them available in the `cookie` property of the request context.

If you only want to parse cookies and not serialize them, you can import `cookieParser` from `"@hattip/cookie/parse"` to avoid extending the request context type with serialization features.

## `cookieSerializer`

Extends the request context type with `setCookie` and `deleteCookie` methods for sending and deleting cookies.

If you only want to serialize cookies and not parse them, you can import `cookieSerializer` from `"@hattip/cookie/serialize"` to avoid adding the `cookie` property to the request context type.