From 5e3acd5a75fe0cf208732ef22b31d56053fdcc46 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 20 Oct 2023 00:09:37 +0900 Subject: [PATCH] docs: add api docs --- src/h3.ts | 2 +- src/hono.ts | 2 +- src/node.ts | 2 +- src/shared.ts | 13 +++++++++++++ src/web.ts | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/h3.ts b/src/h3.ts index 3fb50f3..e3c3fea 100644 --- a/src/h3.ts +++ b/src/h3.ts @@ -226,7 +226,7 @@ export function setCookieLocale( * * @param {H3Event} event the {@link H3Event | H3} event * @param {PathOptions['lang']} options.lang the language tag, which is as default `'en-US'`. optional - * @param {PathOptions['parser']} options.parser the path language parser, optional + * @param {PathOptions['parser']} options.parser the path language parser, default {@link pathLanguageParser}, optional * * @throws {RangeError} Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag. * diff --git a/src/hono.ts b/src/hono.ts index b45344a..35eca33 100644 --- a/src/hono.ts +++ b/src/hono.ts @@ -234,7 +234,7 @@ export function setCookieLocale( * * @param {Context} context A {@link Context | Hono} context * @param {PathOptions['lang']} options.lang A language tag, which is as default `'en-US'`. optional - * @param {PathOptions['parser']} options.parser A path language parser, optional + * @param {PathOptions['parser']} options.parser the path language parser, default {@link pathLanguageParser}, optional * * @throws {RangeError} Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag. * diff --git a/src/node.ts b/src/node.ts index 0f0008e..1cd903e 100644 --- a/src/node.ts +++ b/src/node.ts @@ -289,7 +289,7 @@ function getURL(request: IncomingMessage): URL { * * @param {IncomingMessage} request the {@link IncomingMessage | request} * @param {PathOptions['lang']} options.lang the language tag, which is as default `'en-US'`. optional - * @param {PathOptions['parser']} options.parser the path language parser, optional + * @param {PathOptions['parser']} options.parser the path language parser, default {@link pathLanguageParser}, optional * * @throws {RangeError} Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag. * diff --git a/src/shared.ts b/src/shared.ts index c148fcc..68449d8 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -98,6 +98,13 @@ export interface PathLanguageParser { (path: string | URL): string } +/** + * create a parser, which can split with slash `/` + * + * @param index An index of locale, which is included in path + * + * @returns A return a parser, which has {@link PathLanguageParser} interface + */ export function createPathIndexLanguageParser( index = 0, ): PathLanguageParser { @@ -112,6 +119,12 @@ export function createPathIndexLanguageParser( } } +/** + * A path parser that can get the zeroth part of a path split by `/` as local value + * + * @description + * - `/en/nest/about` -> `en` + */ export let pathLanguageParser: PathLanguageParser = /* #__PURE__*/ createPathIndexLanguageParser() /** diff --git a/src/web.ts b/src/web.ts index eb8ac86..bc3f445 100644 --- a/src/web.ts +++ b/src/web.ts @@ -251,7 +251,7 @@ export function setCookieLocale( * * @param {Request} request the {@link Request | request} * @param {PathOptions['lang']} options.lang the language tag, which is as default `'en-US'`. optional - * @param {PathOptions['parser']} options.parser the path language parser, optional + * @param {PathOptions['parser']} options.parser the path language parser, default {@link pathLanguageParser}, optional * * @throws {RangeError} Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag. *