(cookies, domainFilter?: string | RegExp)
| 6 | * @return {string} Cookie-header-style cookie string (e.g. "foobar; foo=bar; baz=qux") |
| 7 | */ |
| 8 | const parseCookieArray = (cookies, domainFilter?: string | RegExp) => { |
| 9 | if (typeof domainFilter === 'string') { |
| 10 | const dotDomain = '.' + domainFilter; |
| 11 | cookies = cookies.filter(({ domain }) => domain === domainFilter || domain.endsWith(dotDomain)); |
| 12 | } else if (domainFilter && domainFilter.test !== undefined) { |
| 13 | cookies = cookies.filter(({ domain }) => domainFilter.test(domain)); |
| 14 | } |
| 15 | // {name: '', value: 'foobar'} => 'foobar' // https://stackoverflow.com/questions/42531198/cookie-without-a-name |
| 16 | // {name: 'foo', value: 'bar'} => 'foo=bar' |
| 17 | return cookies.map(({ name, value }) => (name ? `${name}=${value}` : value)).join('; '); |
| 18 | }; |
| 19 | |
| 20 | /** |
| 21 | * Construct a browser cookie array from a Cookie-header-style cookie string. |
no outgoing calls
no test coverage detected