open-index/open-npm huggingface dataset:
npm package: @hattip/cors
Description: CORS middleware for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/cors`

[Cross-Origin Resource Sharing(CORS)](https://developer.mozilla.org/en/docs/Web/HTTP/Access_control_CORS) middleware for Hattip.

## Options

```js
export interface CorsOptions {
  /** `Access-Control-Allow-Origin`, default is request Origin header  */
  origin?:
    | string
    | ((ctx: RequestContext) => string | false | Promise<string | false>);
  /** `Access-Control-Allow-Methods`, default is 'GET,HEAD,PUT,POST,DELETE,PATCH'  */
  allowMethods?: string | string[] | null;
  /** `Access-Control-Expose-Headers`  */
  exposeHeaders?: string | string[];
  /** `Access-Control-Allow-Headers`  */
  allowHeaders?: string | string[];
  /** `Access-Control-Max-Age` in seconds  */
  maxAge?: string | number;
  /** `Access-Control-Allow-Credentials`  */
  credentials?: boolean | ((ctx: RequestContext) => boolean | Promise<boolean>);
  /**
   * `Cross-Origin-Opener-Policy` & `Cross-Origin-Embedder-Policy` headers.',
   * default is false
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/Planned_changes
   */
  secureContext?: boolean;
  /**
   * Handle `Access-Control-Request-Private-Network` request by return `Access-Control-Allow-Private-Network`, default to false
   * @see https://wicg.github.io/private-network-access/
   */
  privateNetworkAccess?: boolean;
}
```

## License

- This is a port of [koajs/cors](https://github.com/koajs/cors) by koajs and contributors under the [MIT License](./koajs-cors-license.txt). They are not affiliated with Hattip.
- Hattip port by [Fatih Aygün](https://github.com/cyco130) under the [MIT License](./LICENSE).
npm package: @hattip/graphql
Description: GraphQL middleware for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/graphql`

[GraphQL](https://graphql.org/) middleware for Hattip. This is a thin wrapper around [GraphQL Yoga](https://github.com/dotansimha/graphql-yoga).

## Usage

Install `@hattip/graphql` and `graphql`, then create and `use` the `yoga` middleware.

```ts
import { yoga, createSchema } from "@hattip/graphql";

// Create and initialize the other parts of your app
// ...

const schema = createSchema<{ requestContext: RequestContext }>({
  // Your GraphQL schema
  // ...
});

app.use("/graphql", yoga({ schema }));
```

## LICENSE

- This package comes bundled with `graphql-yoga` which is part of the [GraphQL Yoga](https://github.com/dotansimha/graphql-yoga) project by Graphcool, Prisma, and The Guild, under the [MIT License](./graphql-yoga.license.txt). They are not affiliated with Hattip.
- Hattip specific code is also licensed under the [MIT License](./LICENSE).
npm package: @hattip/headers
Description: Header parsing utilities for Hattip
Author: Fatih Aygün
Latest version: 0.0.49

# `@hattip/headers`

Header parsing and content negotiation utilities for Hattip.

## `parseHeaderValue`

`parseHeaderValue` parses a header value and returns an array of objects with a `value` and `directives` property. Each object represents a value (comma-separated) and its directives (semicolon-separated). It understands basic quoting and comments between parentheses.

```ts
const parsed = parseHeaderValue(`en-US, en;q=0.9, fr;q=0.8`);

assert.deepStrictEqual(parsed, [
  { value: "en-US", directives: {} },
  { value: "en", directives: { q: "0.9" } },
  { value: "fr", directives: { q: "0.8" } },
]);
```

## `accept`

Performs content negotiation on the `Accept` header:

```ts
const handler = accept("text/html, application/json", {
  "text/html": () => html("<h1>Hello world!</h1>"),
  "application/json": () => json({ message: "Hello world!" }),
  "*": () => new Response("Unacceptable", { status: 406 }),
});

const response = handler();
console.assert(response.headers.get("content-type") === "text/html");
```

`q` values and subtype and type wildcards requests are supported.

## `acceptLanguage`

Performs content negotiation on the `Accept-Language` header:

```ts
const handler = acceptLanguage("en-US, fr;q=0.8", {
  "en-US": () => "Hello!",
  fr: () => "Bonjour!",
  "*": () => "Hello!",
});

const result = handler();
console.assert(result === "Hello!");
```