-
Notifications
You must be signed in to change notification settings - Fork 49
/
cookie.ios.js
34 lines (29 loc) · 1.05 KB
/
cookie.ios.js
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
import { NativeModules } from 'react-native';
const CookieManager = NativeModules.RNCookieManager;
export default {
get(url:String, name?: String): Promise<Object|String> {
return CookieManager.getCookie(url).then((cookie: Object): Object => {
if (name && cookie) {
return cookie[name] || null;
} else {
return cookie ? cookie : null;
}
});
},
set(url:String, name: String, value: any, options?: Object = {}): Promise {
const opts = Object.assign(options);
for (let key in opts) {
if (opts.hasOwnProperty(key)) {
if (key === 'expires') {
opts.expires = +opts.expires / 1000;
} else {
opts[key] = opts[key] + '';
}
}
}
return CookieManager.setCookie(url, name + '', value + '', opts);
},
clear(url?: String): Promise {
return url ? CookieManager.clearCookieFromURL(url) : CookieManager.clearCookies();
}
};