@kirolakestrike/lakestrike-services
v0.3.0
Published
A collection of reusable Angular services designed to simplify common tasks acrossprojects. It includes utilities for storage management handling API communication in a clean and consistent way. And more
Maintainers
Readme
Lakestrike Services
Description
A collection of reusable Angular services designed to simplify common tasks acrossprojects. It includes utilities for storage management handling API communication in a clean and consistent way. And more
I started this project to build a centralized collection of ready-to-use Angular services that I can easily integrate into new projects. Instead of rewriting the same basic functionality over and over again, this library provides a solid foundation for common tasks.
The goal is to save time, reduce boilerplate, and give Angular developers a straightforward way to handle everyday concerns like storage, session management, and API interactions.
Motivation
There are numerous services i kept rewriting for each project. After a while, i decided to create this library of services. The use for each service is of course dependant on the project.
Quick Start
Install the package
npm install @kirolakestrike/lakestrike-servicesServices
HandleStorageService
This service easily handles several local storage functionality. It will return correct types to eliminate the ne to do type conversions after loading
Available methods
getString(key: string): string | nullgetNumber(key: string): number | nullgetBoolean(key: string): boolean | nullgetJson<T>(key: string): T | nullsetString(key: string, value: string): booleansetNumber(key: string, value: number): booleansetBoolean(key: string, value: boolean): booleansetJson<T>(key: string, value: T): booleanremove(key: string): booleanclear(): boolean
How to use
Import and use the services in your Angular app, we use dependency injection.
import { Component, inject } from '@angular/core';
import { HandleStorageService } from '@kirolakestrike/lakestrike-services';
@Component({
selector: 'app-root',
template: `
<button (click)="save()">Save</button>
<button (click)="load()">Load</button>
`,
})
export class AppComponent {
private storage = inject(HandleStorageService);
}Usage Examples
save(): void {
this.storage.setString('username', 'Kiro');
this.storage.setNumber('pageSize', 25);
this.storage.setBoolean('darkMode', true);
this.storage.setJson('settings', {
language: 'de',
notifications: true,
});
}load(): void {
const username = this.storage.getString('username');
const pageSize = this.storage.getNumber('pageSize');
const darkMode = this.storage.getBoolean('darkMode');
const settings = this.storage.getJson<{
language: string;
notifications: boolean
}>('settings');
console.log({ username, pageSize, darkMode, settings });
} remove(): void {
this.storage.remove('username');
}
clear(): void {
this.storage.clear();
}Notes
- This service is intended for non-sensitive browser storage data.
- Do not store sensitive data like auth tokens or secrets in
localStorage. - All values in
localStorageare stored as strings. - This service handles parsing and conversion for common types.
