2022-08-30 04:56:11 +00:00
|
|
|
export const safeLocalStorage = () =>
|
|
|
|
isLocalStorage() ? localStorage : undefined
|
|
|
|
export const safeSessionStorage = () =>
|
|
|
|
isSessionStorage() ? sessionStorage : undefined
|
2022-05-26 05:30:03 +00:00
|
|
|
|
|
|
|
const isLocalStorage = () => {
|
|
|
|
try {
|
|
|
|
localStorage.getItem('test')
|
|
|
|
localStorage.setItem('hi', 'mom')
|
|
|
|
return true
|
|
|
|
} catch (e) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 04:56:11 +00:00
|
|
|
|
|
|
|
const isSessionStorage = () => {
|
|
|
|
try {
|
|
|
|
sessionStorage.getItem('test')
|
|
|
|
sessionStorage.setItem('hi', 'mom')
|
|
|
|
return true
|
|
|
|
} catch (e) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|