Skip to content

Commit

Permalink
docs: add api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Oct 19, 2023
1 parent ec5b366 commit 5e3acd5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/h3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()

/**
Expand Down
2 changes: 1 addition & 1 deletion src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 5e3acd5

Please sign in to comment.