0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-23 22:27:34 -05:00
verdaccio/lib/local-list.js

37 lines
701 B
JavaScript
Raw Normal View History

2014-05-07 10:10:59 -05:00
var fs = require('fs')
, listFilePath = './local-list.json';
2014-05-06 17:40:21 -05:00
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();
}
},
2014-05-08 16:48:15 -05:00
remove: function(name) {
2014-05-06 17:40:21 -05:00
var i = this.list.indexOf(name);
if(i != -1) {
this.list.splice(i, 1);
}
this.sync();
},
get: function() {
return this.list;
},
sync: function() {
fs.writeFileSync(listFilePath, JSON.stringify(this.list)); //Uses sync to prevent ugly race condition
2014-05-06 17:40:21 -05:00
}
};
module.exports = new LocalList();