mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-11-08 23:25:51 +01:00
37 lines
650 B
JavaScript
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();
|