Skip to main content
current (v21)

Installation and Configuration

Installation

Install the package via npm:

npm install @ng-catbee/storage

Configuration (Optional)

Standalone Apps

import { ApplicationConfig } from '@angular/core';
import { provideCatbeeStorage } from '@ng-catbee/storage';

export const appConfig: ApplicationConfig = {
providers: [
provideCatbeeStorage({
common: {
encoding: 'default' // 'default', 'base64', 'custom'
},
localStorage: {
encoding: 'base64' // Override for localStorage only
},
sessionStorage: {
encoding: 'custom',
customEncode: (value: string) => btoa(value),
customDecode: (value: string) => atob(value)
}
})
]
};

Module-based Apps

import { NgModule } from '@angular/core';
import { CatbeeStorageModule } from '@ng-catbee/storage';

@NgModule({
imports: [
CatbeeStorageModule.forRoot({
common: {
encoding: 'default'
},
localStorage: {
encoding: 'base64'
}
})
]
})
export class AppModule { }

Configuration Options

Encoding Strategies

StrategyDescription
defaultNo encoding - stores values as-is
base64Base64 encoding for obfuscation
customProvide your own encode/decode functions

Custom Encoding

provideCatbeeStorage({
localStorage: {
encoding: 'custom',
customEncode: (value: string) => {
// Your custom encoding logic
return `encrypted_${btoa(value)}`;
},
customDecode: (value: string) => {
// Your custom decoding logic
return atob(value.replace('encrypted_', ''));
}
}
})

Zero Configuration

The library works without configuration. Just inject the services:

import { Component, inject } from '@angular/core';
import { CatbeeLocalStorageService, CatbeeSessionStorageService } from '@ng-catbee/storage';

@Component({
selector: 'app-root',
standalone: true,
template: `...`
})
export class AppComponent {
private localStorage = inject(CatbeeLocalStorageService);
private sessionStorage = inject(CatbeeSessionStorageService);

saveData() {
this.localStorage.set('key', 'value');
this.sessionStorage.set('tempKey', 'tempValue');
}
}

SSR Compatibility

The library gracefully handles server-side rendering. All storage operations are no-ops on the server and work normally in the browser.

Next Steps