From 9a673597f08dd19b6d1159f4b609ba063a934029 Mon Sep 17 00:00:00 2001 From: Jon Egerton Date: Mon, 19 Aug 2013 23:16:48 +0100 Subject: [PATCH 1/3] Add new definitions for docCookies Definitions for Mozilla document.cookies wrapper --- docCookies/docCookies-tests.ts | 27 ++++++++++++++ docCookies/docCookies.d.ts | 66 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 docCookies/docCookies-tests.ts create mode 100644 docCookies/docCookies.d.ts diff --git a/docCookies/docCookies-tests.ts b/docCookies/docCookies-tests.ts new file mode 100644 index 000000000..f81346b9e --- /dev/null +++ b/docCookies/docCookies-tests.ts @@ -0,0 +1,27 @@ +// Type definitions for docCookies +// Project: https://developer.mozilla.org/en-US/docs/Web/API/document.cookie +// Definitions by: Jon Egerton +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +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()); \ No newline at end of file diff --git a/docCookies/docCookies.d.ts b/docCookies/docCookies.d.ts new file mode 100644 index 000000000..e7ecf1424 --- /dev/null +++ b/docCookies/docCookies.d.ts @@ -0,0 +1,66 @@ +// Type definitions for docCookies +// Project: https://developer.mozilla.org/en-US/docs/Web/API/document.cookie +// Definitions by: Jon Egerton +// 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; + From 7494a3d55683859d46ec75535364dc536608a0e0 Mon Sep 17 00:00:00 2001 From: Jon Egerton Date: Wed, 21 Aug 2013 00:08:34 +0100 Subject: [PATCH 2/3] Resolve syntax issue with route overloads Resolve issue with route overloads by removing the route overload that returns void in favour of those that return Application (this matches the library code) --- sammyjs/sammyjs.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/sammyjs/sammyjs.d.ts b/sammyjs/sammyjs.d.ts index 34404d136..40fdab667 100644 --- a/sammyjs/sammyjs.d.ts +++ b/sammyjs/sammyjs.d.ts @@ -81,7 +81,6 @@ declare module Sammy { $element(selector?: string): JQuery; after(callback: Function): Application; any(verb: string, path: string, callback: Function): void; - route(verb: string, path: string, callback: Function): void; around(callback: Function): Application; before(options: any, callback: Function): Application; bind(name: string, callback: Function): Application; From 34496a8c8f28a47b167f9ab9249065781d6ef010 Mon Sep 17 00:00:00 2001 From: Jon Egerton Date: Wed, 21 Aug 2013 00:21:44 +0100 Subject: [PATCH 3/3] Revert "Resolve syntax issue with route overloads" This reverts commit 7494a3d55683859d46ec75535364dc536608a0e0. --- sammyjs/sammyjs.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/sammyjs/sammyjs.d.ts b/sammyjs/sammyjs.d.ts index 40fdab667..34404d136 100644 --- a/sammyjs/sammyjs.d.ts +++ b/sammyjs/sammyjs.d.ts @@ -81,6 +81,7 @@ declare module Sammy { $element(selector?: string): JQuery; after(callback: Function): Application; any(verb: string, path: string, callback: Function): void; + route(verb: string, path: string, callback: Function): void; around(callback: Function): Application; before(options: any, callback: Function): Application; bind(name: string, callback: Function): Application;