* @function writeToStore * @description * A universal write function for localStorage and sessionStorage. * @param {object} request - the storage request object * @param {string} request.target - a string determines which storage to use * @param {string} request.action - a string determines the
(request: StorageRequest)
| 11 | * @param {string} request.value - the value of a storage item |
| 12 | */ |
| 13 | function writeToStore(request: StorageRequest): void { |
| 14 | const {target = 'local', action = 'setItem'} = request; |
| 15 | const key: string | undefined = (request as any).key; |
| 16 | const value: any = (request as any).value; |
| 17 | // Determine the storage target. |
| 18 | const storage: any = target === `local` ? localStorage : sessionStorage; |
| 19 | |
| 20 | // Execute the storage action and pass arguments if they were defined. |
| 21 | storage[action](key, value); |
| 22 | } |
| 23 | |
| 24 | export default writeToStore; |
no outgoing calls
no test coverage detected