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 d86bc88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"scripts": {
"dev": "tsup --watch",
"build": "tsup",
"test": "mocha \"**/*.test.ts\"",
"test": "mocha \"**/*.test.ts\" --retries 2",
"type-check": "tsc --noEmit",
"lint": "pnpm type-check && eslint .",
"lint:fix": "eslint --fix .",
Expand Down
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 d86bc88

Please sign in to comment.