MCPcopy Create free account
hub / github.com/DIYgod/RSSHub / parseCookieArray

Function parseCookieArray

lib/utils/playwright-utils.ts:8–18  ·  view source on GitHub ↗
(cookies, domainFilter?: string | RegExp)

Source from the content-addressed store, hash-verified

6 * @return {string} Cookie-header-style cookie string (e.g. "foobar; foo=bar; baz=qux")
7 */
8const 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.

Callers 2

getCookiesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected