-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exports creation function instead of actual object
added test using mocha and chai added code styling using standardjs
- Loading branch information
Showing
5 changed files
with
3,337 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,35 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var Store = require('electron-store'); | ||
var store = new Store({}); | ||
|
||
exports.default = { | ||
var createElectronStorage = function createElectronStorage() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
electronStoreOpts = _ref.electronStoreOpts; | ||
|
||
var store = new Store(electronStoreOpts || {}); | ||
|
||
console.log(store); | ||
|
||
return { | ||
getItem: function getItem(key) { | ||
return new Promise(function (resolve) { | ||
resolve(store.get(key)); | ||
}); | ||
return new Promise(function (resolve) { | ||
resolve(store.get(key)); | ||
}); | ||
}, | ||
setItem: function setItem(key, item) { | ||
return new Promise(function (resolve) { | ||
resolve(store.set(key, item)); | ||
}); | ||
return new Promise(function (resolve) { | ||
resolve(store.set(key, item)); | ||
}); | ||
}, | ||
removeItem: function removeItem(key) { | ||
return new Promise(function (resolve) { | ||
resolve(store.delete(key)); | ||
}); | ||
return new Promise(function (resolve) { | ||
resolve(store.delete(key)); | ||
}); | ||
} | ||
}; | ||
}; | ||
}; | ||
|
||
exports.default = createElectronStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
const Store = require('electron-store'); | ||
const store = new Store({}); | ||
const Store = require('electron-store') | ||
|
||
export default { | ||
const createElectronStorage = ({electronStoreOpts} = {}) => { | ||
const store = new Store(electronStoreOpts || {}) | ||
|
||
return { | ||
getItem: (key) => { | ||
return new Promise((resolve) => { | ||
resolve(store.get(key)); | ||
}); | ||
return new Promise((resolve) => { | ||
resolve(store.get(key)) | ||
}) | ||
}, | ||
setItem: (key, item) => { | ||
return new Promise((resolve) => { | ||
resolve(store.set(key, item)); | ||
}); | ||
return new Promise((resolve) => { | ||
resolve(store.set(key, item)) | ||
}) | ||
}, | ||
removeItem: (key) => { | ||
return new Promise((resolve) => { | ||
resolve(store.delete(key)); | ||
}); | ||
}, | ||
}; | ||
return new Promise((resolve) => { | ||
resolve(store.delete(key)) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
export default createElectronStorage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const createElectronStorage = require('../lib').default | ||
const assert = require('chai').assert | ||
|
||
describe('Initialisation', function () { | ||
it('no args', function () { | ||
const storage = createElectronStorage() | ||
assert.isObject(storage, 'created storage is not an object') | ||
}) | ||
|
||
describe('args', function () { | ||
it('encryptionKey', function () { | ||
const storage = createElectronStorage({ | ||
electronStoreOpts: { | ||
encryptionKey: 'a' | ||
} | ||
}) | ||
assert.isObject(storage, 'created storage is not an object') | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Functions', function () { | ||
const storage = createElectronStorage() | ||
|
||
it('setItem', function () { | ||
return storage.setItem('key', 'value') | ||
}) | ||
|
||
it('getItem', function (done) { | ||
storage.getItem('key') | ||
.then(function (value) { | ||
assert.equal(value, 'value') | ||
done() | ||
}) | ||
}) | ||
|
||
it('removeItem', function (done) { | ||
storage.removeItem('key') | ||
.then(storage.getItem('key')) | ||
.then(function (value) { | ||
assert.isUndefined(value) | ||
done() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.