Skip to content

Commit

Permalink
support Date in option.expires
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Aug 8, 2024
1 parent fa3ce96 commit 841ba3f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/porridge-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export class PorridgeDB {
};

if (options?.expires && String(options.expires).length) {
newValue[storageKeys.expires] = new Date(options.expires);
newValue[storageKeys.expires] = options.expires instanceof Date
? options.expires
: new Date(options.expires);
}

eventDispatcher(this.eventName, {
Expand Down
4 changes: 3 additions & 1 deletion src/porridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export class Porridge {
};

if (options?.expires && String(options.expires).length) {
newValue[storageKeys.expires] = new Date(options.expires);
newValue[storageKeys.expires] = options.expires instanceof Date
? options.expires
: new Date(options.expires);
}

eventDispatcher(this.eventName, {
Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ export function addCustomEventListener(eventName: string, keyName: string, callb
if (typeof callback === 'function') {
callback({
key: keyName,
value: e.detail.value,
newValue: e.detail.newValue,
oldValue: e.detail.oldValue,
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare namespace WebPorridge {
type StorageOptions = {
expires?: number;
expires?: Date | number;
prop?: string;
};

Expand Down

0 comments on commit 841ba3f

Please sign in to comment.