UNPKG

@alwatr/local-storage

Version:

A modern, simple, and robust solution for managing versioned JSON objects in the browser's `localStorage`. This package provides a clean, class-based API with a factory function to ensure your application's data persistence is safe, maintainable, and futu

29 lines (26 loc) 860 B
import {LocalStorageProvider} from './local-storage.provider.js'; import type {LocalStorageProviderConfig} from './type.js'; /** * Factory function to create a new LocalStorageProvider. * * @param config - The configuration for the provider. * @returns An instance of LocalStorageProvider. * * @example * ```typescript * const userSettings = createLocalStorageProvider({ * name: 'user-settings', * schemaVersion: 1 * }); * * // Write new settings * userSettings.write({ theme: 'dark', notifications: false }); * * // Read the current settings * const currentSettings = userSettings.read(); * console.log(currentSettings); // { theme: 'dark', notifications: false } * ``` */ export function createLocalStorageProvider<T>(config: LocalStorageProviderConfig<T>): LocalStorageProvider<T> { return new LocalStorageProvider<T>(config); }