Add weblock package

This commit is contained in:
Alex Gleason
2024-03-15 12:25:38 -05:00
parent a72e9c1c04
commit 44411fdf29
4 changed files with 8 additions and 18 deletions

View File

@@ -1,15 +0,0 @@
/** Lock a key from being accessed by `localStorage` and `sessionStorage`. */
function lockStorageKey(key: string): void {
const proto = Object.getPrototypeOf(localStorage ?? sessionStorage);
const _getItem = proto.getItem;
proto.getItem = function(_key: string) {
if (_key === key) {
throw new Error(`${_key} is locked`);
} else {
return _getItem.bind(this)(_key);
}
};
}
export { lockStorageKey };