Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
shahradelahi committed May 31, 2024
1 parent ce4fd52 commit 8885322
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/driver/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import { HashRecord, StorageDriver } from '@/typings';

type StorageType = 'local' | 'session';

function getStorage(type: StorageType): Storage {
if (typeof window === 'undefined') {
throw new Error('Browser storage not available');
}

return type === 'local' ? localStorage : sessionStorage;
}

export interface BrowserDriverOptions {
initialValue?: HashRecord<string, string>;
}
Expand All @@ -22,7 +14,11 @@ export default class BrowserDriver<Key extends string = string, Value extends st
constructor(type: StorageType, opts: BrowserDriverOptions = {}) {
const { initialValue } = opts;

const storage = getStorage(type);
if (typeof window === 'undefined') {
throw new Error('Browser storage not available');
}

const storage = type === 'local' ? localStorage : sessionStorage;
if (!storage) {
throw new Error('Storage not available');
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { List } from './list';
// -----------

export { default as MemoryDriver } from './driver/memory';
export { default as BrowserDriver } from './driver/browser';

// -----------

Expand Down

0 comments on commit 8885322

Please sign in to comment.