-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrations.mjs
43 lines (35 loc) · 911 Bytes
/
migrations.mjs
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
// Consider placing in own module when it gets bigger.
export function migrations() {
let data = JSON.parse(window.localStorage.data);
const finalize = (target) => {
window.localStorage.data = JSON.stringify(data);
window.localStorage.version = target;
// No need to define a noop migration by returning the target arg.
return target;
};
return {
undefined() {
data = {
lists: [],
};
assignUsername();
return "0.0.0";
},
"1.0.0"() {
return "0.0.0";
},
"0.0.0": finalize,
};
}
async function assignUsername() {
// Add a random username if none.
if (!window.localStorage.username) {
const { uniqueNamesGenerator, colors, animals } = await import(
"unique-names-generator"
);
window.localStorage.username = uniqueNamesGenerator({
dictionaries: [colors, animals],
length: 2,
});
}
}