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(
226
226
*
227
227
* @param {H3Event } event the {@link H3Event | H3} event
228
228
* @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
230
230
*
231
231
* @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
232
232
*
Original file line number Diff line number Diff line change @@ -234,7 +234,7 @@ export function setCookieLocale(
234
234
*
235
235
* @param {Context } context A {@link Context | Hono} context
236
236
* @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
238
238
*
239
239
* @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
240
240
*
Original file line number Diff line number Diff line change @@ -289,7 +289,7 @@ function getURL(request: IncomingMessage): URL {
289
289
*
290
290
* @param {IncomingMessage } request the {@link IncomingMessage | request}
291
291
* @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
293
293
*
294
294
* @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
295
295
*
Original file line number Diff line number Diff line change @@ -98,6 +98,13 @@ export interface PathLanguageParser {
98
98
( path : string | URL ) : string
99
99
}
100
100
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
+ */
101
108
export function createPathIndexLanguageParser (
102
109
index = 0 ,
103
110
) : PathLanguageParser {
@@ -112,6 +119,12 @@ export function createPathIndexLanguageParser(
112
119
}
113
120
}
114
121
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
+ */
115
128
export let pathLanguageParser : PathLanguageParser = /* #__PURE__*/ createPathIndexLanguageParser ( )
116
129
117
130
/**
Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ export function setCookieLocale(
251
251
*
252
252
* @param {Request } request the {@link Request | request}
253
253
* @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
255
255
*
256
256
* @throws {RangeError } Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
257
257
*
You can’t perform that action at this time.
0 commit comments