1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-08 23:25:51 +01:00
verdaccio/lib/local-list.js
2014-05-07 10:10:59 -05:00

37 lines
650 B
JavaScript

var fs = require('fs')
, listFilePath = './local-list.json';
var LocalList = function() {
if(fs.existsSync(listFilePath)) {
this.list = JSON.parse(fs.readFileSync(listFilePath, 'utf8'));
}
else {
this.list = [];
}
};
LocalList.prototype = {
add: function(name) {
if(this.list.indexOf(name) == -1) {
this.list.push(name);
this.sync();
}
},
remove: function() {
var i = this.list.indexOf(name);
if(i != -1) {
this.list.splice(i, 1);
}
this.sync();
},
get: function() {
return this.list;
},
sync: function() {
fs.writeFile(listFilePath, JSON.stringify(this.list));
}
};
module.exports = new LocalList();