-
Notifications
You must be signed in to change notification settings - Fork 278
/
local-storage.js
executable file
·37 lines (34 loc) · 1.06 KB
/
local-storage.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
'use strict';
var LocalStorageO = require('node-localstorage').LocalStorage;
var path = require('path');
var os = require('os');
var temp = path.normalize(path.join(os.tmpdir(), '/.local_storage_'));
var DEFAULT_STORAGE_PATH = temp;
var LocalStorage = {
setId: function setId(id) {
if (id === undefined) {
throw new Error('vorpal.localStorage() requires a unique key to be passed in.');
}
if (!this._localStorage) {
this._localStorage = new LocalStorageO(DEFAULT_STORAGE_PATH + id);
}
},
validate: function validate() {
if (this._localStorage === undefined) {
throw new Error('Vorpal.localStorage() was not initialized before writing data.');
}
},
getItem: function getItem(key, value) {
this.validate();
return this._localStorage.getItem(key, value);
},
setItem: function setItem(key, value) {
this.validate();
return this._localStorage.setItem(key, value);
},
removeItem: function removeItem(key) {
this.validate();
return this._localStorage.removeItem(key);
}
};
module.exports = LocalStorage;