mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-28 17:35:49 +08:00
Add new definitions for docCookies
Definitions for Mozilla document.cookies wrapper
This commit is contained in:
27
docCookies/docCookies-tests.ts
Normal file
27
docCookies/docCookies-tests.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
// Type definitions for docCookies
|
||||
// Project: https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
|
||||
// Definitions by: Jon Egerton <https://github.com/jonegerton>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="docCookies.d.ts" />
|
||||
|
||||
docCookies.setItem("test0", "Hello world!");
|
||||
docCookies.setItem("test1", "Unicode test: \u00E0\u00E8\u00EC\u00F2\u00F9", Infinity);
|
||||
docCookies.setItem("test2", "Hello world!", new Date(2020, 5, 12));
|
||||
docCookies.setItem("test3", "Hello world!", new Date(2027, 2, 3), "/blog");
|
||||
docCookies.setItem("test4", "Hello world!", "Sun, 06 Nov 2022 21:43:15 GMT");
|
||||
docCookies.setItem("test5", "Hello world!", "Tue, 06 Dec 2022 13:11:07 GMT", "/home");
|
||||
docCookies.setItem("test6", "Hello world!", 150);
|
||||
docCookies.setItem("test7", "Hello world!", 245, "/content");
|
||||
docCookies.setItem("test8", "Hello world!", null, null, "example.com");
|
||||
docCookies.setItem("test9", "Hello world!", null, null, null, true);
|
||||
|
||||
alert(docCookies.keys().join("\n"));
|
||||
alert(docCookies.getItem("test1"));
|
||||
alert(docCookies.getItem("test5"));
|
||||
docCookies.removeItem("test1");
|
||||
docCookies.removeItem("test5", "/home");
|
||||
alert(docCookies.getItem("test1"));
|
||||
alert(docCookies.getItem("test5"));
|
||||
alert(docCookies.getItem("unexistingCookie"));
|
||||
//alert(docCookies.getItem());
|
||||
66
docCookies/docCookies.d.ts
vendored
Normal file
66
docCookies/docCookies.d.ts
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
// Type definitions for docCookies
|
||||
// Project: https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
|
||||
// Definitions by: Jon Egerton <https://github.com/jonegerton>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
interface docCookies {
|
||||
|
||||
/**
|
||||
Create/overwrite a cookie.
|
||||
@param {string} name (required) The name of the cookie to create/overwrite
|
||||
@param {string} value (required) The value of the cookie
|
||||
@param {number} end (optional) The max-age in seconds (e.g. 31536e3 for a year, Infinity for a never-expires cookie). If not specified it will expire at the end of session
|
||||
@param {string} path (optional) E.g., "/", "/mydir"; if not specified, defaults to the current path of the current document location
|
||||
@param {string} domain (optional) E.g., "example.com", ".example.com" (includes all subdomains) or "subdomain.example.com"; if not specified, defaults to the host portion of the current document location
|
||||
@param {boolean} secure (optional) The cookie will be transmitted only over secure protocol as https
|
||||
*/
|
||||
setItem(sKey: string, sValue: string, vEnd?: number, sPath?: string, sDomain?: string, bSecure?: boolean): boolean;
|
||||
|
||||
/**
|
||||
Create/overwrite a cookie.
|
||||
@param {string} name (required) The name of the cookie to create/overwrite
|
||||
@param {string} value (required) The value of the cookie
|
||||
@param {string} end (optional) The expires date in GMTString format. If not specified it will expire at the end of session
|
||||
@param {string} path (optional) E.g., "/", "/mydir"; if not specified, defaults to the current path of the current document location
|
||||
@param {string} domain (optional) E.g., "example.com", ".example.com" (includes all subdomains) or "subdomain.example.com"; if not specified, defaults to the host portion of the current document location
|
||||
@param {boolean} secure (optional) The cookie will be transmitted only over secure protocol as https
|
||||
*/
|
||||
setItem(sKey: string, sValue: string, vEnd?: string, sPath?: string, sDomain?: string, bSecure?: boolean): boolean;
|
||||
|
||||
/**
|
||||
Create/overwrite a cookie.
|
||||
@param {string} name (required) The name of the cookie to create/overwrite
|
||||
@param {string} value (required) The value of the cookie
|
||||
@param {Date} end (optional) The expires date as a Date object. If not specified it will expire at the end of session
|
||||
@param {string} path (optional) E.g., "/", "/mydir"; if not specified, defaults to the current path of the current document location
|
||||
@param {string} domain (optional) E.g., "example.com", ".example.com" (includes all subdomains) or "subdomain.example.com"; if not specified, defaults to the host portion of the current document location
|
||||
@param {boolean} secure (optional) The cookie will be transmitted only over secure protocol as https
|
||||
*/
|
||||
setItem(sKey: string, sValue: string, vEnd?: Date, sPath?: string, sDomain?: string, bSecure?: boolean): boolean;
|
||||
|
||||
/**
|
||||
Read a cookie. If the cookie doesn't exist a null value will be returned.
|
||||
@param {string} name (required) The name of the cookie to read
|
||||
*/
|
||||
getItem(sKey: string): string;
|
||||
|
||||
/**
|
||||
Delete a cookie.
|
||||
@param {string} name (required) The name of the cookie to remove
|
||||
*/
|
||||
removeItem(sKey: string, sPath?: string): boolean;
|
||||
|
||||
/**
|
||||
Check if a cookie exists.
|
||||
@param {string} name (required) The name of the cookie to test
|
||||
*/
|
||||
hasItem(sKey: string): boolean;
|
||||
|
||||
/**
|
||||
Returns an array of all readable cookies from this location.
|
||||
*/
|
||||
keys(): string[];
|
||||
}
|
||||
|
||||
declare var docCookies: docCookies;
|
||||
|
||||
Reference in New Issue
Block a user