tiny-updater
Version:
A small update notifier for NPM packages, useful for CLI apps.
35 lines (34 loc) • 970 B
JavaScript
/* IMPORT */
import IonStore from 'ionstore';
import Utils from './utils.js';
/* MAIN */
class Store {
constructor() {
/* VARIABLES */
this.store = new IonStore('tiny-updater');
/* API */
this.get = (name) => {
try {
const recordRaw = this.store.get(name);
if (!recordRaw)
return;
const record = JSON.parse(recordRaw);
if (!Utils.isNumber(record.timestampFetch))
return;
if (!Utils.isNumber(record.timestampNotification))
return;
if (!Utils.isString(record.version))
return;
return record;
}
catch {
return;
}
};
this.set = (name, record) => {
this.store.set(name, JSON.stringify(record));
};
}
}
/* EXPORT */
export default new Store();