@egt-ukraine/storage

Angular wrapper for localStorage, sessionStorage.

Usage no npm install needed!

<script type="module">
  import egtUkraineStorage from 'https://cdn.skypack.dev/@egt-ukraine/storage';
</script>

README

EGT Storage Module

Angular wrapper for localStorage, sessionStorage.

How to use?

Install:

npm i @egt-ukraine/storage or yarn add @egt-ukraine/storage

import { NgModule } from '@angular/core';

import { StorageModule } from '@egt-ukraine/storage';

@NgModule({
  imports: [
    StorageModule.forRoot(),
  ],
  exports: [],
  declarations: [],
})
export class CoreModule {}

Usage:

import { Injectable } from '@angular/core';

import { IWindowStorage, StorageRegistry } from '@egt-ukraine/storage';

@Injectable()
export class SomeService {
  private _storage: IWindowStorage;
  private _storageObjectKey: string = 'my-cool-variable-from-local-storage';
  private _storageType: string = 'local';

  constructor(private _storageRegistry: StorageRegistry) {
    this._storage = this._storageRegistry.getStorage(this._storageType);
  }

  public setSomeValue(someValue: string): void {
    this._storage.set(this._storageObjectKey, someValue);
  }

  public getSomeValue(): string {
    return this._storage.get(this._storageObjectKey);
  }
}