-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (35 loc) · 862 Bytes
/
index.js
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
// Packages
const { join } = require('path')
const { homedir } = require('os')
const storage = require('node-persist')
const { encrypt, decrypt } = require('caesar-encrypt')
class SaveLocal {
constructor(store = 'storage') {
this.store = `.${store}`
}
async init() {
await storage.init({
dir: join(homedir(), this.store)
})
}
async get(item) {
const hasItem = await storage.getItem(item)
return hasItem && decrypt(hasItem, 20)
}
set(item) {
const value = encrypt(item.value, 20)
return storage.setItem(item.name, value)
}
remove(name) {
return storage.removeItem(name)
}
async list() {
const list = []
await storage.forEach(item => {
const value = decrypt(item.value, 20)
return list.push({ name: item.key, value })
})
return list
}
}
module.exports = SaveLocal