forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-local-storage.d.ts
158 lines (153 loc) · 5.04 KB
/
angular-local-storage.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Type definitions for angular-local-storage v0.1.5
// Project: https://github.com/grevory/angular-local-storage
// Definitions by: Ken Fukuyama <https://github.com/kenfdev>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path='../angularjs/angular.d.ts' />
declare namespace angular.local.storage {
interface ILocalStorageServiceProvider extends angular.IServiceProvider {
/**
* Setter for the prefix
* You should set a prefix to avoid overwriting any local storage variables from the rest of your app
* e.g. localStorageServiceProvider.setPrefix('youAppName');
* With provider you can use config as this:
* myApp.config(function (localStorageServiceProvider) {
* localStorageServiceProvider.prefix = 'yourAppName';
* });
* @param prefix default: ls.<your-key>
*/
setPrefix(prefix: string):ILocalStorageServiceProvider;
/**
* Setter for the storageType
* @param storageType localstorage or sessionStorage. default: localStorage
*/
setStorageType(storageType: string):ILocalStorageServiceProvider;
/**
* Setter for cookie config
* @param exp number of days before cookies expire (0 = does not expire). default: 30
* @param path the web path the cookie represents. default: '/'
*/
setStorageCookie(exp: number, path: string):ILocalStorageServiceProvider;
/**
* Set the cookie domain, since this runs inside a the config() block, only providers and constants can be injected. As a result, $location service can't be used here, use a hardcoded string or window.location.
* No default value
*/
setStorageCookieDomain(domain: string):ILocalStorageServiceProvider;
/**
* Send signals for each of the following actions:
* @param setItem default: true
* @param removeItem default: false
*/
setNotify(setItem: boolean, removeItem: boolean):ILocalStorageServiceProvider;
}
interface ICookie {
/**
* Checks if cookies are enabled in the browser.
* Returns: Boolean
*/
isSupported:boolean;
/**
* Directly adds a value to cookies.
* Note: Typically used as a fallback if local storage is not supported.
* Returns: Boolean
* @param key
* @param val
*/
set(key:string, val:string):boolean;
/**
* Directly adds a value to cookies with an expiration.
* Note: Typically used as a fallback if local storage is not supported.
* Returns: Boolean
* @param key
* @param val
* @param daysToExpiry
*/
set(key:string, val:string, daysToExpiry:number):boolean;
/**
* Directly get a value from a cookie.
* Returns: value from local storage
* @param key
*/
get(key:string):string;
/**
* Remove directly value from a cookie.
* Returns: Boolean
* @param key
*/
remove(key:string):boolean;
/**
* Remove all data for this app from cookie.
*/
clearAll():any;
}
interface ILocalStorageService {
/**
* Checks if the browser support the current storage type(e.g: localStorage, sessionStorage).
* Returns: Boolean
*/
isSupported:boolean;
/**
* Returns: String
*/
getStorageType():string;
/**
* Directly adds a value to local storage.
* If local storage is not supported, use cookies instead.
* Returns: Boolean
* @param key
* @param value
*/
set<T>(key: string, value: T): boolean;
/**
* Directly get a value from local storage.
* If local storage is not supported, use cookies instead.
* Returns: value from local storage
* @param key
*/
get<T>(key: string): T;
/**
* Return array of keys for local storage, ignore keys that not owned.
* Returns: value from local storage
*/
keys(): string[];
/**
* Remove an item from local storage by key.
* If local storage is not supported, use cookies instead.
* Returns: Boolean
* @param key
*/
remove(key: string): boolean;
/**
* Remove all data for this app from local storage.
* If local storage is not supported, use cookies instead.
* Note: Optionally takes a regular expression string and removes matching.
* Returns: Boolean
* @param regularExpression
*/
clearAll(regularExpression?:RegExp):boolean;
/**
* Bind $scope key to localStorageService.
* Usage: localStorageService.bind(scope, property, value[optional], key[optional])
* Returns: deregistration function for this listener.
* @param scope
* @param property
* @param value optional
* @param key The corresponding key used in local storage
*/
bind(scope: angular.IScope, property: string, value?: any, key?: string): Function;
/**
* Return the derive key
* Returns String
* @param key
*/
deriveKey(key:string):string;
/**
* Return localStorageService.length, ignore keys that not owned.
* Returns Number
*/
length():number;
/**
* Deal with browser's cookies directly.
*/
cookie:ICookie;
}
}