Skip to content

Commit

Permalink
patch: only parse string when necessary in .get()
Browse files Browse the repository at this point in the history
This may seem weird, but it's possible for certain backends to return objects for this.
  • Loading branch information
Pkmmte committed Dec 16, 2022
1 parent e5df286 commit cb3b56a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ export class Stashy {
public get<T>(key: string, options?: StashyOptions): T {
this._log('trace', `get(${key}) with options:`, options);
const encodedValue = this._backend(options).getString(key, options);
const value = encodedValue ? JSON.parse(encodedValue) : null;
let value = null;
if (typeof encodedValue === 'string') {
value = encodedValue ? JSON.parse(encodedValue) : null;
} else if (encodedValue) {
value = encodedValue;
}
this._log('debug', `get(${key}) value is:`, value);
return value ?? options?.default;
};
Expand Down

0 comments on commit cb3b56a

Please sign in to comment.