|
1 | | -import {filterMatches} from "./matches.js"; |
| 1 | +import { filterMatches } from "./matches.js"; |
2 | 2 |
|
3 | 3 | export interface NegotiateLanguagesOptions { |
4 | 4 | strategy?: "filtering" | "matching" | "lookup"; |
@@ -51,22 +51,19 @@ export interface NegotiateLanguagesOptions { |
51 | 51 | export function negotiateLanguages( |
52 | 52 | requestedLocales: Readonly<Array<string>>, |
53 | 53 | availableLocales: Readonly<Array<string>>, |
54 | | - { |
55 | | - strategy = "filtering", |
56 | | - defaultLocale, |
57 | | - }: NegotiateLanguagesOptions = {} |
| 54 | + { strategy = "filtering", defaultLocale }: NegotiateLanguagesOptions = {} |
58 | 55 | ): Array<string> { |
59 | | - |
60 | 56 | const supportedLocales = filterMatches( |
61 | | - Array.from(Object(requestedLocales)).map(String), |
62 | | - Array.from(Object(availableLocales)).map(String), |
| 57 | + Array.from(requestedLocales ?? []).map(String), |
| 58 | + Array.from(availableLocales ?? []).map(String), |
63 | 59 | strategy |
64 | 60 | ); |
65 | 61 |
|
66 | 62 | if (strategy === "lookup") { |
67 | 63 | if (defaultLocale === undefined) { |
68 | 64 | throw new Error( |
69 | | - "defaultLocale cannot be undefined for strategy `lookup`"); |
| 65 | + "defaultLocale cannot be undefined for strategy `lookup`" |
| 66 | + ); |
70 | 67 | } |
71 | 68 | if (supportedLocales.length === 0) { |
72 | 69 | supportedLocales.push(defaultLocale); |
|
0 commit comments