Skip to content

Commit

Permalink
fix: upgrade how dependency works
Browse files Browse the repository at this point in the history
  • Loading branch information
bukinoshita committed Jun 7, 2019
1 parent 273d1af commit 40df75b
Show file tree
Hide file tree
Showing 4 changed files with 1,539 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
language: node_js
node_js:
- '8'
- '9'
- '10'
39 changes: 17 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,42 @@
'use strict'

// Packages
const { join } = require('path')
const { homedir } = require('os')
const storage = require('node-persist')
const { encrypt, decrypt } = require('caesar-encrypt')

class SaveLocal {
constructor(store) {
constructor(store = 'storage') {
const s = `.${store}`

storage.initSync({
storage.init({
dir: join(homedir(), s)
})
}

get(item) {
return storage.getItem(item).then(res => {
if (res) {
return decrypt(res, 20)
}
async get(item) {
const hasItem = await storage.getItem(item)

return false
})
return hasItem && hasItem
}

set({ name, value }) {
return storage.setItem(name, encrypt(value, 20))
set(item) {
const value = encrypt(item.value, 20)

return storage.setItem(item.name, value)
}

remove(name) {
return storage.removeItem(name)
}

list() {
return new Promise(resolve => {
const packages = storage.keys()
const list = []
packages.forEach(async name => {
const value = await this.get(name)
list.push({ name, value })
resolve(list)
})
async list() {
const list = []
await storage.forEach(item => {
const value = decrypt(item.value, 20)
return list.push({ name: item.key, value })
})

return list
}
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"author": "Bu Kinoshita <bukinoshita@gmail.com>",
"license": "MIT",
"scripts": {
"test": "xo --quiet"
"test": "ava",
"lint": "xo --quiet"
},
"keywords": [
"save",
Expand All @@ -21,6 +22,7 @@
"node-persist": "^3.0.0"
},
"devDependencies": {
"ava": "^2.0.0",
"eslint-config-prettier": "4.3.0",
"xo": "0.24.0"
},
Expand Down
Loading

0 comments on commit 40df75b

Please sign in to comment.