# Yahoo! UI Library

### cookie 2.6.0

Yahoo! UI Library > cookie > YAHOO.util.Cookie

Show Private Show Protected Show Deprecated

## `static` Class YAHOO.util.Cookie

Cookie utility.

### Methods

#### _createCookieHash

`private static String _createCookieHash ( hash )`
Formats a cookie value for an object containing multiple values.

Parameters:
  `hash <Object>` An object of key-value pairs to create a string for.

Returns: `String`
  A string suitable for use as a cookie value.

#### _createCookieString

`private static String _createCookieString ( name , value , encodeValue , options )`
Creates a cookie string that can be assigned into document.cookie.

Parameters:
  `name <String>` The name of the cookie.
  `value <String>` The value of the cookie.
  `encodeValue <encodeValue>` True to encode the value, false to leave as-is.
  `options <Object>` (Optional) Options for the cookie.

Returns: `String`
  The formatted cookie string.

#### _parseCookieHash

`private static Object _parseCookieHash ( text )`
Parses a cookie hash string into an object.

Parameters:
  `text <String>` The cookie hash string to parse. The string should already be URL-decoded.

Returns: `Object`
  An object containing entries for each cookie value.

#### _parseCookieString

`private static Object _parseCookieString ( text , decode )`
Parses a cookie string into an object representing all accessible cookies.

Parameters:
  `text <String>` The cookie string to parse.
  `decode <Boolean>` (Optional) Indicates if the cookie values should be decoded or not. Default is true.

Returns: `Object`
  An object containing entries for each accessible cookie.

#### get

`static Variant get ( name , converter )`
Returns the cookie value for the given name.

Parameters:
  `name <String>` The name of the cookie to retrieve.
  `converter <Function>` (Optional) A function to run on the value before returning it. The function is not used if the cookie doesn't exist.

Returns: `Variant`
  If no converter is specified, returns a string or null if the cookie doesn't exist. If the converter is specified, returns the value returned from the converter or null if the cookie doesn't exist.

#### getHash

`static Object getHash ( name )`
Returns an object containing name-value pairs stored in the cookie with the given name.

Parameters:
  `name <String>` The name of the cookie to retrieve.

Returns: `Object`
  An object of name-value pairs if the cookie with the given name exists, null if it does not.

#### getSub

`static Variant getSub ( name , subName , converter )`
Returns the value of a subcookie.

Parameters:
  `name <String>` The name of the cookie to retrieve.
  `subName <String>` The name of the subcookie to retrieve.
  `converter <Function>` (Optional) A function to run on the value before returning it. The function is not used if the cookie doesn't exist.

Returns: `Variant`
  If the cookie doesn't exist, null is returned. If the subcookie doesn't exist, null if also returned. If no converter is specified and the subcookie exists, a string is returned. If a converter is specified and the subcookie exists, the value returned from the converter is returned.

#### remove

`static String remove ( name , options )`
Removes a cookie from the machine by setting its expiration date to sometime in the past.

Parameters:
  `name <String>` The name of the cookie to remove.
  `options <Object>` (Optional) An object containing one or more cookie options: path (a string), domain (a string), and secure (true/false). The expires option will be overwritten by the method.

Returns: `String`
  The created cookie string.

#### removeSub

`static String removeSub ( name , subName , options )`
Removes a sub cookie with a given name.

Parameters:
  `name <String>` The name of the cookie in which the subcookie exists.
  `subName <String>` The name of the subcookie to remove.
  `options <Object>` (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), and secure (true/false). This must be the same settings as the original subcookie.

Returns: `String`
  The created cookie string.

#### set

`static String set ( name , value , options )`
Sets a cookie with a given name and value.

Parameters:
  `name <String>` The name of the cookie to set.
  `value <Variant>` The value to set for the cookie.
  `options <Object>` (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), and secure (true/false).

Returns: `String`
  The created cookie string.

#### setSub

`static String setSub ( name , subName , value , options )`
Sets a sub cookie with a given name to a particular value.

Parameters:
  `name <String>` The name of the cookie to set.
  `subName <String>` The name of the subcookie to set.
  `value <Variant>` The value to set.
  `options <Object>` (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), and secure (true/false).

Returns: `String`
  The created cookie string.

#### setSubs

`static String setSubs ( name , value , options )`
Sets a cookie with a given name to contain a hash of name-value pairs.

Parameters:
  `name <String>` The name of the cookie to set.
  `value <Object>` An object containing name-value pairs.
  `options <Object>` (Optional) An object containing one or more cookie options: path (a string), domain (a string), expires (a Date object), and secure (true/false).

Returns: `String`
  The created cookie string.

Copyright © 2008 Yahoo! Inc. All rights reserved.