@anshul28/storage-core-hrms
v1.0.9
Published
storage-core-hrms
Readme
storage-core-hrms
A type-safe, extensible TypeScript browser storage service designed with an adapter pattern, built-in AES encryption, and RxJS observable support. It defaults to sessionStorage out of the box.FeaturesAdapter Architecture: Easily switch between sessionStorage and localStorage.Built-in AES Encryption: Secure sensitive information using crypto-js.Reactive Events: Listen to storage changes reactively using rxjs observables.Type Safety: Fully typed models, options, and interfaces.Dual Formats: Ships with both CommonJS (.js) and ESM (.mjs) bundles with built-in declaration files (.d.ts).Installationbashnpm install @anshul28/storage-core-hrms Use code with caution.Quick Start1. Basic Initialization (Defaults to Session Storage)typescriptimport { StorageService } from '@anshul28/storage-core-hrms';
// Initializes with SessionStorageAdapter by default const storageService = new StorageService();
// Set a value storageService.set('username', 'anshul_dev');
// Get a value const user = storageService.get('username'); // 'anshul_dev' Use code with caution.2. Switching to Local Storagetypescriptimport { StorageService, LocalStorageAdapter } from '@anshul28/storage-core-hrms';
const persistentStorage = new StorageService({ adapter: new LocalStorageAdapter() });
persistentStorage.set('remember_me', true); Use code with caution.3. Using Encrypted StorageLeverage the aes-encryption.service by passing encryption configurations to your storage service options.typescriptimport { StorageService, AesEncryptionService } from '@anshul28/storage-core-hrms';
const secureStorage = new StorageService({ encryption: new AesEncryptionService({ secretKey: 'your-secure-key' }) });
// Automatically encrypts before saving and decrypts on retrieval
secureStorage.set('secureToken', 'secret-jwt-string');
Use code with caution.4. Listening to Storage Events via Observablestypescript// Subscribe to change streams reactively
storageService.watch('username').subscribe((event) => {
console.log(Key ${event.key} changed from ${event.oldValue} to ${event.newValue});
});
Use code with caution.Directory Architecture ReferenceThe package layout maps directly to clean architecture principles:textsrc/
├── adapters/ # Storage engines (session, local, custom interfaces)
├── encryption/ # AES-encryption implementations
├── models/ # Storage events, items, and option interfaces
├── observables/ # RxJS reactive stream utilities
├── services/ # Core StorageService orchestrator
└── utils/ # Internal helper modules
Use code with caution.Developmentbash# Start tsup in watch mode
npm run dev
Build production bundles (ESM/CJS)
npm run build Use code with caution.LicenseISC
