-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.ts
56 lines (42 loc) · 1.1 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pandora from "./index";
// Set an item
/*
localStorage.setItem("username", "pandora");
*/
pandora.set<string>("username", "pandora");
// Get an item
/*
let value = localStorage.getItem("key");
*/
let value = pandora.get<string>("key");
// Managing default values
/*
let defaultValue = 1;
let count = localStorage.getItem("count") || defaultValue;
*/
let count = pandora.get<number>("count", 1);
// Dealing with objects
/*
let object = { someKey: "value" };
localStorage.setItem("object", JSON.stringify(object));
let fromStorage = JSON.parse(localStorage.getItem("object"));
console.log(fromStorage.someKey); // value
*/
let object = { someKey: "value" };
pandora.set("object", object);
let fromStorage = pandora.get<{ someKey: "string" }>("object");
console.log(fromStorage.someKey); // value;
// Clear items
/*
localStorage.clear()
*/
pandora.clear();
// Persist values
/*
let value = localStorage.getItem("key");
localStorage.clear();
localStorage.setItem("key", value);
*/
pandora.set("key", value, { shouldPersist: true });
pandora.clear();
pandora.get("key") === value; // true