@audiowalk/sdk
Advanced tools
Comparing version 1.3.0 to 1.3.1
export * from "./player/player-controller"; | ||
export * from "./storage/local-storage"; | ||
export * from "./story/story-controller"; | ||
//# sourceMappingURL=index.d.ts.map |
export * from "./player/player-controller"; | ||
export * from "./storage/local-storage"; | ||
export * from "./story/story-controller"; |
@@ -82,5 +82,5 @@ import { BehaviorSubject, combineLatest, map, Subject } from "rxjs"; | ||
this.playerElement.src = file; | ||
const position = await this.localStorage.get(`progress-${this.playerElement.src}`); | ||
const position = await this.localStorage.get(`progress-${this.playerElement.src}`, (value) => typeof value === "number"); | ||
if (position && this.options.autoSave) | ||
this.playerElement.currentTime = parseFloat(position); | ||
this.playerElement.currentTime = position; | ||
if (this.options.playOnInit) | ||
@@ -87,0 +87,0 @@ await this.playerElement.play(); |
@@ -7,6 +7,7 @@ export interface LocalStorageOptions { | ||
constructor(options?: Partial<LocalStorageOptions>); | ||
get(key: string): Promise<string | null>; | ||
get<T = unknown>(key: string, validate?: (value: unknown) => value is T): Promise<T | null>; | ||
set(key: string, value: any): Promise<void>; | ||
private parseData; | ||
private getPrefixedKey; | ||
} | ||
//# sourceMappingURL=local-storage.d.ts.map |
@@ -6,8 +6,31 @@ export class LocalStorage { | ||
} | ||
async get(key) { | ||
return window.localStorage.getItem(this.getPrefixedKey(key)); | ||
async get(key, validate) { | ||
const data = window.localStorage.getItem(this.getPrefixedKey(key)); | ||
if (data === null) | ||
return null; | ||
const value = this.parseData(data); | ||
if (typeof validate === "function") { | ||
if (validate(value)) { | ||
return this.parseData(data); | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
else { | ||
return value; | ||
} | ||
} | ||
async set(key, value) { | ||
return window.localStorage.setItem(this.getPrefixedKey(key), value); | ||
const data = JSON.stringify(value); | ||
return window.localStorage.setItem(this.getPrefixedKey(key), data); | ||
} | ||
parseData(data) { | ||
try { | ||
return JSON.parse(data); | ||
} | ||
catch (e) { | ||
return data; | ||
} | ||
} | ||
getPrefixedKey(key) { | ||
@@ -14,0 +37,0 @@ const keyParts = ["audiowalk"]; |
{ | ||
"name": "@audiowalk/sdk", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"repository": { | ||
@@ -15,4 +15,5 @@ "type": "git", | ||
"scripts": { | ||
"dev": "tsc -w", | ||
"dev": "npm run build:watch", | ||
"build": "tsc", | ||
"build:watch": "tsc -w", | ||
"prepublishOnly": "npm run build", | ||
@@ -19,0 +20,0 @@ "release:patch": "git switch master && npm version patch && git switch release && git merge master --ff-only && git push --follow-tags && git switch master && git push", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
18212
13
351