@bi8/am-storage
Version:
AmStorage is a simple framework for saving and loading information from *localStorage*.
65 lines (60 loc) • 2.02 kB
JavaScript
import { __decorate, __metadata } from 'tslib';
import { Injectable, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { isNil } from 'lodash';
import { LogService } from '@bi8/am-logger';
var StorageService = /** @class */ (function () {
function StorageService(logService) {
this.logService = logService;
this.logger = logService.getLogger(this.constructor.name);
this.logger.debug("Hello World");
}
StorageService.prototype.remove = function (key) {
localStorage.removeItem(key);
};
StorageService.prototype.exists = function (key) {
var found = localStorage.getItem(key);
return !isNil(found);
};
StorageService.prototype.get = function (key, defaultValue) {
var found = localStorage.getItem(key);
if (!isNil(found)) {
var wrapper = JSON.parse(found);
return wrapper && wrapper.value ? wrapper.value : defaultValue;
}
else {
return defaultValue;
}
};
StorageService.prototype.set = function (key, value) {
var wrapper = { value: value };
localStorage.setItem(key, JSON.stringify(wrapper));
};
StorageService.ctorParameters = function () { return [
{ type: LogService }
]; };
StorageService = __decorate([
Injectable(),
__metadata("design:paramtypes", [LogService])
], StorageService);
return StorageService;
}());
var AmStorageModule = /** @class */ (function () {
function AmStorageModule() {
}
AmStorageModule = __decorate([
NgModule({
providers: [StorageService],
imports: [
CommonModule
],
declarations: []
})
], AmStorageModule);
return AmStorageModule;
}());
/**
* Generated bundle index. Do not edit.
*/
export { AmStorageModule, StorageService };
//# sourceMappingURL=bi8-am-storage.js.map