-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbrowser.js
More file actions
29 lines (25 loc) · 838 Bytes
/
browser.js
File metadata and controls
29 lines (25 loc) · 838 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
29
import { isLocalStorageAvailable } from '@splitsoftware/splitio-commons/src/utils/env/isLocalStorageAvailable';
import { STORAGE_MEMORY } from '@splitsoftware/splitio-commons/src/utils/constants';
const STORAGE_LOCALSTORAGE = 'LOCALSTORAGE';
export function validateStorage(settings) {
let {
log,
storage: {
type,
options = {},
prefix
} = { type: STORAGE_MEMORY },
} = settings;
// If an invalid storage type is provided OR we want to use LOCALSTORAGE and
// it's not available, fallback into MEMORY
if (type !== STORAGE_MEMORY && type !== STORAGE_LOCALSTORAGE ||
type === STORAGE_LOCALSTORAGE && !isLocalStorageAvailable()) {
type = STORAGE_MEMORY;
log.error('Invalid or unavailable storage. Fallback into MEMORY storage');
}
return {
type,
options,
prefix,
};
}