forked from DefinitelyTyped/DefinitelyTyped
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
151 lines (146 loc) · 6.51 KB
/
index.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
import * as angular from "angular";
export type ILocalStorageServiceProvider = angular.local.storage.ILocalStorageServiceProvider;
export type ILocalStorageService = angular.local.storage.ILocalStorageService;
export type ICookie = angular.local.storage.ICookie;
declare module "angular" {
namespace local.storage {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ILocalStorageServiceProvider extends 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
* localstorage or sessionStorage. default: localStorage
*/
setStorageType(storageType: string): ILocalStorageServiceProvider;
/**
* If localStorage is not supported, the library will default to cookies instead. This behavior can be disabled
* default: true
*/
setDefaultToCookie(shouldDefault: boolean): 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: '/'
* @param secure to store cookies as secure. default: false
*/
setStorageCookie(exp: number, path: string, secure: boolean): 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;
}
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ICookie {
/**
* Checks if cookies are enabled in the browser.
* Returns: Boolean
*/
readonly isSupported: boolean;
/**
* Directly adds a value to cookies.
* Note: Typically used as a fallback if local storage is not supported.
*/
set(key: string, val: string, daysToExpiry?: number): boolean;
/**
* Directly get a value from a cookie.
*/
get(key: string): string;
/**
* Remove directly value from a cookie.
*/
remove(key: string): boolean;
/**
* Remove all data for this app from cookie.
*/
clearAll(): any;
}
type StorageType = "localStorage" | "sessionStorage";
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ILocalStorageService {
/**
* Change the local storage prefix during execution
*/
changePrefix(newPrefix: string): void;
/**
* 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.
*/
set(key: string, value: any, storageType?: StorageType): boolean;
/**
* Directly get a value from local storage.
* If local storage is not supported, use cookies instead.
* Returns: value from local storage
*/
get(key: string, storageType?: StorageType): any;
/**
* Return array of keys for local storage, ignore keys that not owned.
* Returns: value from local storage
*/
keys(storageType?: StorageType): string[];
/**
* Remove a list of items from the local storage by their given keys.
* The last item in the variable argument list can optionally be the StorageType.
* Which specifies whether to remove from the session storage or the local storage.
* If the last argument is not a valid storage type it is considered to be a key,
* and localStorage is used by default .
* If local storage is not supported, use cookies instead.
* Returns: Boolean
* @param key
*/
remove(...args: 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.
*/
clearAll(regularExpression?: RegExp, storageType?: StorageType): boolean;
/**
* Bind $scope key to localStorageService.
* Usage: localStorageService.bind(scope, property, value[optional], key[optional])
* Returns: deregistration function for this listener.
*/
bind(scope: IScope, property: string, value?: any, key?: string, storageType?: StorageType): () => void;
/**
* Return the derive key
*/
deriveKey(key: string): string;
/**
* Return localStorageService.length, ignore keys that not owned.
*/
length(storageType?: StorageType): number;
/**
* Deal with browser's cookies directly.
*/
cookie: ICookie;
}
}
}