forked from skillrecordings/egghead-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookies.ts
More file actions
28 lines (26 loc) · 678 Bytes
/
cookies.ts
File metadata and controls
28 lines (26 loc) · 678 Bytes
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
import cookies from 'js-cookie'
import {isString} from 'lodash'
const cookieUtil = {
set(name: string, value: any, options: any = {}) {
const use_secure_cookie = window.location.protocol === 'https:'
cookies.set(name, isString(value) ? value : JSON.stringify(value), {
secure: use_secure_cookie,
path: '/',
expires: 365,
...options,
})
return cookies.get(name)
},
get(name: string) {
const value = cookies.get(name) as string
try {
return JSON.parse(value)
} catch (e) {
return value
}
},
remove(name: string, options: any = {}) {
cookies.remove(name, options)
},
}
export default cookieUtil