File size: 532 Bytes
bc20498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Read a value from `sessionStorage`
 * @param {string} key
 * @param {(value: string) => any} parse
 */
export function get(key, parse = JSON.parse) {
	try {
		return parse(sessionStorage[key]);
	} catch {
		// do nothing
	}
}

/**
 * Write a value to `sessionStorage`
 * @param {string} key
 * @param {any} value
 * @param {(value: any) => string} stringify
 */
export function set(key, value, stringify = JSON.stringify) {
	const data = stringify(value);
	try {
		sessionStorage[key] = data;
	} catch {
		// do nothing
	}
}