forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.cookie.d.ts
106 lines (102 loc) · 4.53 KB
/
jquery.cookie.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Type definitions for jQuery Cookie Plugin 1.4.1
// Project: https://github.com/carhartl/jquery-cookie
// Definitions by: Roy Goode <https://github.com/RoyGoode/>, Ben Lorantfy <https://github.com/BenLorantfy/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path="../jquery/jquery.d.ts" />
interface JQueryCookieOptions {
/**
* Define lifetime of the cookie. Value can be a Number which will be interpreted as days from time of creation or a Date object. If omitted, the cookie becomes a session cookie.
*/
expires?: any;
/**
* Define the path where the cookie is valid. By default the path of the cookie is the path of the page where the cookie was created (standard browser behavior). If you want to make it available for instance across the entire domain use path: '/'. Default: path of page where the cookie was created.
*/
path?: string;
/**
* Define the domain where the cookie is valid. Default: domain of page where the cookie was created.
*/
domain?: string;
/**
* If true, the cookie transmission requires a secure protocol (https). Default: false.
*/
secure?: boolean;
}
//
// The following jsdoc comments are used to add intellisense to editors that support it. Uses snippets
// of documentation from the Github repo when possible.
//
// The ordering here matters. For example, the read function with the converter parameter is purposefully after
// the set function. This is because the intellisense that shows up after you press comma should be the set first,
// since that is more common, then the conversion function if user starts typing a parameter with a function type
interface JQueryCookieStatic {
/**
* By default the cookie value is encoded/decoded when writing/reading, using encodeURIComponent/decodeURIComponent. Bypass this by setting raw to true:
*/
raw?: boolean;
/**
* Turn on automatic storage of JSON objects passed as the cookie value. Assumes JSON.stringify and JSON.parse
*/
json?: boolean;
/**
* Cookie attributes can be set globally by setting properties of the $.cookie.defaults object or individually for each call to $.cookie() by passing a plain object to the options argument. Per-call options override the default options.
*/
defaults?: JQueryCookieOptions;
/**
* Gets an object of cookies as key-value pairs
*/
(): {[key:string]:string};
/**
* Gets a cookie by name
* @param name The name of the cookie to get
*/
(name: string): any;
/**
* Sets a cookie
* @param name The name of the cookie to set
* @param value The value to set the cookie to
*/
(name: string, value: string): void;
/**
* Gets a cookie by name after applying a conversion function to the value
* @param name The name of the cookie to get
* @param converter A conversion function to change the cookie's value to a different representation on the fly
*/
(name: string, converter: (value: string) => any): any;
/**
* Sets a cookie with some options
* @param name The name of the cookie to set
* @param value The value to set the cookie to
* @param options An object of options that change how the cookie is set
*/
(name: string, value: string, options: JQueryCookieOptions): void;
/**
* Sets a cookie using .toString(), or if $.cookie.json is set to true using JSON.stringify()
* @param name The name of the cookie to set
* @param value The value to set the cookie to
*/
(name: string, value: any): void;
/**
* Sets a cookie using .toString(), or if $.cookie.json is set to true using JSON.stringify()
* @param name The name of the cookie to set
* @param value The value to set the cookie to
* @param options An object of options that change how the cookie is set
*/
(name: string, value: any, options: JQueryCookieOptions): void;
}
interface JQueryStatic {
/**
* A simple, lightweight jQuery plugin for reading, writing and deleting cookies.
*/
cookie?: JQueryCookieStatic;
/**
* Deletes a cookie
* @param name Name of cookie to delete
*/
removeCookie(name: string): boolean;
/**
* Deletes a cookie
* @param name Name of cookie to delete
* @param options The same attributes (path, domain) as what the cookie was written with
*/
removeCookie(name: string, options: JQueryCookieOptions): boolean;
}