( str: string, i: number, )
| 40 | const SIMPLE_LANGUAGE_REGEXP = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/; |
| 41 | |
| 42 | function parseLanguage( |
| 43 | str: string, |
| 44 | i: number, |
| 45 | ): LanguageSpecificity | undefined { |
| 46 | const match = SIMPLE_LANGUAGE_REGEXP.exec(str); |
| 47 | if (!match) { |
| 48 | return undefined; |
| 49 | } |
| 50 | |
| 51 | const [, prefix, suffix] = match; |
| 52 | if (!prefix) { |
| 53 | return undefined; |
| 54 | } |
| 55 | |
| 56 | const full = suffix !== undefined ? `${prefix}-${suffix}` : prefix; |
| 57 | |
| 58 | let q = 1; |
| 59 | if (match[3]) { |
| 60 | const params = match[3].split(";"); |
| 61 | for (const param of params) { |
| 62 | const [key, value] = param.trim().split("="); |
| 63 | if (key === "q" && value) { |
| 64 | q = parseFloat(value); |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return { prefix, suffix, full, i, o: undefined, q, s: undefined }; |
| 71 | } |
| 72 | |
| 73 | function parseAcceptLanguage(accept: string): LanguageSpecificity[] { |
| 74 | const accepts = accept.split(","); |
no outgoing calls
no test coverage detected