-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
69 lines (66 loc) · 1.78 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
var version = require('./package.json').version;
if (typeof window !== 'undefined') {
module.exports = require('./browser');
} else {
var conf = require('./lib/config');
var cleanup = require('./lib/cleanup');
var path = require('path');
var appDir = path.dirname((require.main && require.main.filename) || '.');
var _file = appDir + conf.vaultFile;
var File = require('./lib/file');
var Memory = require('./lib/memory');
console.log('Vault (' + version + ') File:', _file);
module.exports = {
version: version,
startCleanup: cleanup.start,
stopCleanup: cleanup.stop,
setIntervalLength: cleanup.setIntervalLength,
getIntervalLength: cleanup.getIntervalLength,
File: File.init(_file),
Memory: Memory,
set: function(key, value, config) {
module.exports.remove(key);
if (config && config.expires && config.expires === 'session') {
Memory.set(key, value, config);
} else {
File.set(key, value, config);
}
},
get: function(key) {
var types = [
Memory,
File
];
for (var i = 0; i < types.length; i++) {
var value = types[i].get(key);
if (value !== undefined) {
return value;
}
}
},
list: function(raw) {
console.log('--== Memory ==--');
Memory.list(raw);
console.log('----------------');
console.log('--== File ==--');
File.list(raw);
console.log('----------------');
},
getLists: function() {
return {
Memory: Memory.getList(),
File: File.getList()
};
},
remove: function(key) {
Memory.remove(key);
File.remove(key);
},
clear: function() {
Memory.clear();
File.clear();
}
};
cleanup.start([File, Memory]);
}