ng2-webstorage
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,5 +7,5 @@ import {LocalStorageService, SessionStorageService} from './services'; | ||
export const NG2_WEBSTORAGES = [ | ||
export const NG2_WEBSTORAGE = [ | ||
SessionStorageService, | ||
LocalStorageService | ||
]; |
@@ -15,3 +15,3 @@ import {STORAGE} from '../enums/storage'; | ||
static emit(sType:STORAGE, sKey:string, value:string):void { | ||
static emit(sType:STORAGE, sKey:string, value:any):void { | ||
let oKey = this.genObserverKey(sType, sKey); | ||
@@ -18,0 +18,0 @@ if(oKey in this.observers) this.observers[oKey].emit(value); |
@@ -19,3 +19,3 @@ import {beforeEachProviders, describe, inject, injectAsync, it} from '@angular/core/testing'; | ||
WebStorageHelper.store(STORAGE.session, 'webStorage:session:key', value); | ||
expect(sessionStorage.getItem('webStorage:session:key')).toEqual(value) | ||
expect(sessionStorage.getItem('webStorage:session:key')).toEqual(JSON.stringify(value)) | ||
@@ -29,3 +29,3 @@ }); | ||
WebStorageHelper.store(STORAGE.local, 'webStorage:local:key', value); | ||
expect(localStorage.getItem('webStorage:local:key')).toEqual(value) | ||
expect(localStorage.getItem('webStorage:local:key')).toEqual(JSON.stringify(value)) | ||
@@ -61,3 +61,3 @@ }); | ||
let value = 'value', key = 'webStorage:local:key2'; | ||
localStorage.setItem(key, value); | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
expect(WebStorageHelper.retrieve(STORAGE.local, key)).toEqual(value); | ||
@@ -70,3 +70,3 @@ | ||
let value = 'value', key = 'webStorage:session:key2'; | ||
sessionStorage.setItem(key, value); | ||
sessionStorage.setItem(key, JSON.stringify(value)); | ||
expect(WebStorageHelper.retrieve(STORAGE.session, key)).toEqual(value); | ||
@@ -79,3 +79,3 @@ | ||
let value = 'value', key = 'webStorage:session:key2'; | ||
sessionStorage.setItem(key, 'other value'); | ||
sessionStorage.setItem(key, JSON.stringify('other value')); | ||
expect(WebStorageHelper.retrieve(STORAGE.session, key)).toEqual(value); | ||
@@ -82,0 +82,0 @@ |
@@ -10,4 +10,4 @@ import {IWebStorage} from '../interfaces/webStorage'; | ||
static store(sType:STORAGE, sKey:string, value:string):void { | ||
this.getWStorage(sType).setItem(sKey, value); | ||
static store(sType:STORAGE, sKey:string, value:any):void { | ||
this.getWStorage(sType).setItem(sKey, JSON.stringify(value)); | ||
this.cached[sType][sKey] = value; | ||
@@ -20,3 +20,11 @@ StorageObserverHelper.emit(sType, sKey, value); | ||
return this.cached[sType][sKey]; | ||
return this.cached[sType][sKey] = this.getWStorage(sType).getItem(sKey); | ||
let data = null; | ||
try { | ||
data = JSON.parse(this.getWStorage(sType).getItem(sKey)); | ||
} catch(err) { | ||
console.error(`invalid value for ${sKey}`); | ||
} | ||
return this.cached[sType][sKey] = data; | ||
} | ||
@@ -23,0 +31,0 @@ |
@@ -5,6 +5,6 @@ import {EventEmitter} from '@angular/core'; | ||
export interface IStorage { | ||
store(key:string, value:string):void; | ||
retrieve(key:string):string; | ||
store(key:string, value:any):void; | ||
retrieve(key:string):any; | ||
clear(key?:string):void; | ||
observe(key:string): EventEmitter; | ||
} |
@@ -14,3 +14,3 @@ import {EventEmitter} from '@angular/core'; | ||
public store(raw:string, value:string):void { | ||
public store(raw:string, value:any):void { | ||
let sKey = KeyStorageHelper.genKey(raw); | ||
@@ -20,3 +20,3 @@ WebStorageHelper.store(this.sType, sKey, value); | ||
public retrieve(raw:string):string { | ||
public retrieve(raw:string):any { | ||
let sKey = KeyStorageHelper.genKey(raw); | ||
@@ -23,0 +23,0 @@ return WebStorageHelper.retrieve(this.sType, sKey); |
{ | ||
"name": "ng2-webstorage", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "angular2 webstorage manager", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
28794
28
467
1
293