File tree Expand file tree Collapse file tree 5 files changed +17
-4
lines changed
Expand file tree Collapse file tree 5 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -226,7 +226,7 @@ export function setCookieLocale(
226226 *
227227 * @param {H3Event } event the {@link H3Event | H3} event
228228 * @param {PathOptions['lang'] } options.lang the language tag, which is as default `'en-US'`. optional
229- * @param {PathOptions['parser'] } options.parser the path language parser, optional
229+ * @param {PathOptions['parser'] } options.parser the path language parser, default { @link pathLanguageParser}, optional
230230 *
231231 * @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
232232 *
Original file line number Diff line number Diff line change @@ -234,7 +234,7 @@ export function setCookieLocale(
234234 *
235235 * @param {Context } context A {@link Context | Hono} context
236236 * @param {PathOptions['lang'] } options.lang A language tag, which is as default `'en-US'`. optional
237- * @param {PathOptions['parser'] } options.parser A path language parser, optional
237+ * @param {PathOptions['parser'] } options.parser the path language parser, default { @link pathLanguageParser} , optional
238238 *
239239 * @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
240240 *
Original file line number Diff line number Diff line change @@ -289,7 +289,7 @@ function getURL(request: IncomingMessage): URL {
289289 *
290290 * @param {IncomingMessage } request the {@link IncomingMessage | request}
291291 * @param {PathOptions['lang'] } options.lang the language tag, which is as default `'en-US'`. optional
292- * @param {PathOptions['parser'] } options.parser the path language parser, optional
292+ * @param {PathOptions['parser'] } options.parser the path language parser, default { @link pathLanguageParser}, optional
293293 *
294294 * @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
295295 *
Original file line number Diff line number Diff line change @@ -98,6 +98,13 @@ export interface PathLanguageParser {
9898 ( path : string | URL ) : string
9999}
100100
101+ /**
102+ * create a parser, which can split with slash `/`
103+ *
104+ * @param index An index of locale, which is included in path
105+ *
106+ * @returns A return a parser, which has {@link PathLanguageParser} interface
107+ */
101108export function createPathIndexLanguageParser (
102109 index = 0 ,
103110) : PathLanguageParser {
@@ -112,6 +119,12 @@ export function createPathIndexLanguageParser(
112119 }
113120}
114121
122+ /**
123+ * A path parser that can get the zeroth part of a path split by `/` as local value
124+ *
125+ * @description
126+ * - `/en/nest/about` -> `en`
127+ */
115128export let pathLanguageParser : PathLanguageParser = /* #__PURE__*/ createPathIndexLanguageParser ( )
116129
117130/**
Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ export function setCookieLocale(
251251 *
252252 * @param {Request } request the {@link Request | request}
253253 * @param {PathOptions['lang'] } options.lang the language tag, which is as default `'en-US'`. optional
254- * @param {PathOptions['parser'] } options.parser the path language parser, optional
254+ * @param {PathOptions['parser'] } options.parser the path language parser, default { @link pathLanguageParser}, optional
255255 *
256256 * @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
257257 *
You can’t perform that action at this time.
0 commit comments