/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MAIN //

/**
* Returns the cookie values for a list of cookie names.
*
* ## Notes
*
* -   If unable to resolve a cookie with a provided name, the returned value is `null`.
*
* @private
* @param {string} cookie - string containing a list of cookies
* @param {Array<string>} names - cookie names
* @returns {Object} cookie values
*/
function getCookies( cookie, names ) {
	var list;
	var tmp;
	var o;
	var i;
	var k;

	// Initialize the output object...
	for ( i = 0; i < names.length; i++ ) {
		o[ names[ i ] ] = null;
	}
	// Convert the list to an array of cookies:
	list = cookie.split( /;\s*/ ); // Note: RFC 6265 (https://datatracker.ietf.org/doc/html/rfc6265) mandates a single space after each semicolon; however, some user agents may not abide by this requirement

	// Search for cookies having the desired names...
	for ( i = 0; i < list.length; i++ ) {
		// Each cookie is comprised of key=value pairs:
		tmp = list[ i ].split( '=' );
		k = tmp[ 0 ];

		// Note: we assume that `name` does not need to be decoded and we assume that keys and values are not surrounded by whitespace...
		if ( o[ k ] === null ) {
			// Note: for cookies having the same name but, e.g., different domains and/or paths, we take the first occurrence...
			o[ k ] = decodeURIComponent( tmp[ 1 ] );
		}
	}
	return o;
}


// EXPORTS //

module.exports = getCookies;

/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MAIN //

/**
* Returns the cookie values for a list of cookie names.
*
* ## Notes
*
* -   If unable to resolve a cookie with a provided name, the returned value is `null`.
*
* @private
* @param {string} cookie - string containing a list of cookies
* @param {Array<string>} names - cookie names
* @returns {Object} cookie values
*/
function getCookies( cookie, names ) {
	var list;
	var tmp;
	var o;
	var i;
	var k;

	// Initialize the output object...
	o = {};
	for ( i = 0; i < names.length; i++ ) {
		o[ names[ i ] ] = null;
	}
	// Convert the list to an array of cookies:
	list = cookie.split( /;\s*/ ); // Note: RFC 6265 (https://datatracker.ietf.org/doc/html/rfc6265) mandates a single space after each semicolon; however, some user agents may not abide by this requirement

	// Search for cookies having the desired names...
	for ( i = 0; i < list.length; i++ ) {
		// Each cookie is comprised of key=value pairs:
		tmp = list[ i ].split( '=' );
		k = tmp[ 0 ];

		// Note: we assume that `name` does not need to be decoded and we assume that keys and values are not surrounded by whitespace...
		if ( o[ k ] === null ) {
			// Note: for cookies having the same name but, e.g., different domains and/or paths, we take the first occurrence...
			o[ k ] = decodeURIComponent( tmp[ 1 ] );
		}
	}
	return o;
}


// EXPORTS //

module.exports = getCookies;

Fix missing variable initialization