Skip to content

Commit 6c7f334

Browse files
authored
fix: wrong default options (#65)
* fix: wrong default options * fix * fix: typo
1 parent d44580d commit 6c7f334

File tree

10 files changed

+302
-442
lines changed

10 files changed

+302
-442
lines changed

deno/http.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ export type CookieOptions = CookieSerializeOptions & {
125125
name?: string
126126
}
127127

128+
/**
129+
* Cookie locale options type
130+
*/
131+
export type CookieLocaleOptions = {
132+
/**
133+
* The default language tag
134+
*/
135+
lang?: string
136+
/**
137+
* Cookie name
138+
*/
139+
name?: string
140+
}
141+
128142
/**
129143
* Header options type
130144
*/
@@ -154,13 +168,15 @@ export function parseDefaultHeader(input: string): string[] {
154168
* get languages from header with getter function
155169
*
156170
* @param getter - the header string getter function
171+
* @param options - the {@link HeaderOptions | header options}
157172
*
158173
* @returns The array of language tags
159174
*/
160175
export function getHeaderLanguagesWithGetter(
161176
getter: () => string | null | undefined,
162-
{ name = ACCEPT_LANGUAGE_HEADER, parser = parseDefaultHeader }: HeaderOptions = {}
177+
options: HeaderOptions = {}
163178
): string[] {
179+
const { name = ACCEPT_LANGUAGE_HEADER, parser = parseDefaultHeader } = options
164180
const langString = getter()
165181
return langString
166182
? name === ACCEPT_LANGUAGE_HEADER
@@ -247,34 +263,27 @@ export type PathOptions = {
247263
* get the language from the path
248264
*
249265
* @param path - the target path
250-
* @param options.lang - the language tag, which is as default `'en-US'`. optional
251-
* @param options.parser - the path language parser, optional
266+
* @param options - the {@link PathOptions | path options} object
252267
*
253268
* @returns the language that is parsed by the path language parser, if the language is not detected, return a `options.lang` value
254269
*/
255-
export function getPathLanguage(
256-
path: string | URL,
257-
{ lang = DEFAULT_LANG_TAG, parser = pathLanguageParser }: PathOptions = {}
258-
): string {
270+
export function getPathLanguage(path: string | URL, options: PathOptions = {}): string {
271+
const { lang = DEFAULT_LANG_TAG, parser = pathLanguageParser } = options
259272
return (parser || pathLanguageParser)(path) || lang
260273
}
261274

262275
/**
263276
* get the locale from the path
264277
*
265278
* @param path - the target path
266-
* @param options.lang - the language tag, which is as default `'en-US'`. optional
267-
* @param options.parser - the path language parser, optional
279+
* @param options - the {@link PathOptions | path options} object
268280
*
269281
* @throws {RangeError} Throws the {@link RangeError} if the language in the path, that is not a well-formed BCP 47 language tag.
270282
*
271283
* @returns The locale that resolved from path
272284
*/
273-
export function getPathLocale(
274-
path: string | URL,
275-
{ lang = DEFAULT_LANG_TAG, parser = pathLanguageParser }: PathOptions = {}
276-
): Intl.Locale {
277-
return new Intl.Locale(getPathLanguage(path, { lang, parser }))
285+
export function getPathLocale(path: string | URL, options: PathOptions = {}): Intl.Locale {
286+
return new Intl.Locale(getPathLanguage(path, options))
278287
}
279288

280289
function getURLSearchParams(input: string | URL | URLSearchParams): URLSearchParams {
@@ -322,6 +331,7 @@ export function getQueryLanguage(
322331
* get the locale from the query
323332
*
324333
* @param query - the target query
334+
* @param options - The {@link QueryOptions | query options}
325335
* @param options.lang - the language tag, which is as default `'en-US'`. optional
326336
* @param options.name - the query param name, default `'locale'`. optional
327337
*
@@ -331,7 +341,8 @@ export function getQueryLanguage(
331341
*/
332342
export function getQueryLocale(
333343
query: string | URL | URLSearchParams,
334-
{ lang = DEFAULT_LANG_TAG, name = 'locale' }: QueryOptions = {}
344+
options: QueryOptions = {}
335345
): Intl.Locale {
346+
const { lang = DEFAULT_LANG_TAG, name = 'locale' } = options
336347
return new Intl.Locale(getQueryLanguage(query, { lang, name }))
337348
}

deno/shared.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export function toLocale(val: string | Intl.Locale): Intl.Locale {
6161
*/
6262
export function validateLangTag(lang: string): boolean {
6363
try {
64-
// @ts-ignore NOTE: https://github.com/microsoft/TypeScript/pull/56079
6564
Intl.getCanonicalLocales(lang)
6665
return true
6766
} catch {
@@ -93,7 +92,7 @@ export function parseAcceptLanguage(value: string): string[] {
9392
* ```ts
9493
* const oldLangName = 'en_US'
9594
* const langTag = normalizeLanguageName(oldLangName)
96-
* conosle.log(langTag) // en-US
95+
* console.log(langTag) // en-US
9796
* ```
9897
*
9998
* @param langName - The target language name

0 commit comments

Comments
 (0)