UNPKG

@osaedasia/oresume

Version:

A user-friendly library for generating complete Single Page Applications (SPAs)

2 lines (1 loc) 611 B
import{LocalStorage as e}from"@osaedasia/std";import{StorageDataNotFoundError as t,InvalidStorageKeyError as s}from"../domain/exceptions/Store.js";class r{_key;constructor(e,t){this._assertKeyIsValid(e),this._key=e,this.save(t)}static fromKey(t){const s=e.getItem(t);return null===s?null:new r(t,s)}getData(){const s=e.getItem(this._key);if(null===s)throw new t(`Could not retrieved persisted data for ${this._key}.`);return s}save(t){e.setItem(this._key,t)}remove(){e.removeItem(this._key)}_assertKeyIsValid(e){if(!e||e.trim().length<=0)throw new s(`The key provided is not valid: ${e}.`)}}export{r as Store};