Skip to content

devlopersabbir/lsc-storage

Repository files navigation

🚀 lsc-storage

A lightweight storage library that makes managing your web storage a breeze! 🌟
Currently supports local storage with plans for session storage and cookie storage in future releases.

npm version License: MITGitHub issuesGitHub stars


Table of Contents


Features

  • Unified API: Simple methods to interact with your storage.
  • TypeScript Support: Enjoy type safety and IntelliSense.
  • Fallback Mechanism: Automatically falls back to an in-memory storage if localStorage is unavailable.
  • Extensible: Easily add support for session storage and cookie storage in future updates.

Installation

Install via npm:

npm install lsc-storage

Usage

Importing the Library

import { lsc } from "lsc-storage";

Basic Examples for lsc-storage

Storing Data

// Store a simple string
lsc.set("username", "john_doe");

// Store an object
lsc.set("user", { name: "John Doe", age: 30 });

Retrieving Data

// Retrieve a string value
const username = lsc.get<string>("username");

// Retrieve an object
const user = lsc.get<{ name: string; age: number }>("user");

Removing Data

// Remove an item by key
lsc.remove("username");

Clearing All Data

// Clear all items from storage
lsc.clear();

Flushing Data

// Flush expired items (or force flush all with true)
lsc.flush();
lsc.flush(true);

API Reference

Method/Function Signature Description Parameters Return Type
set `set(key: string, value: T, localConfig?: Omit<StorageConfig, 'storage'>): void boolean` Stores a value in storage under the specified key. key: string
value: T
localConfig (optional): Configuration object (excluding storage)
get `get(key: string, localConfig?: Omit<StorageConfig, 'storage'>): T null` Retrieves the value associated with the specified key. key: string
localConfig (optional): Configuration object (excluding storage)
remove remove(key: string): void Removes the item associated with the specified key from storage. key: string void
clear clear(): void Clears all items from storage. None void
flush flush(force?: boolean): void Clears expired items from storage. If force is true, clears all items regardless of expiration. force (optional): boolean (defaults to false) void
localMemoryStore localMemoryStore(): Storage Creates an in-memory storage object that implements the Storage interface. Used as a fallback mechanism. None Storage
StorageConfig `{ storage?: Storage; ttl?: number null }` Interface defining configuration options for storage operations. storage (optional): Storage mechanism (e.g., localStorage)
ttl (optional): Time-to-live in milliseconds
KeyValuePair type KeyValuePair<T = unknown> = Record<string, T>; Type representing an object with string keys and values of type T. None Type definition

Development

To set up the development environment:

  1. Clone the repository:
     git clone https://github.com/devlopersabbir/lsc-storage.git
     cd lsc-storage
  2. Install dependencies:
    npm install
  3. Run the development server:
    npm run dev
  4. Run tests:
    npm test
  5. Build the project:
    npm run build

Contributing

Contributions are welcome! 🎉 Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeature).
  3. Commit your changes (git commit -m 'Add YourFeature').
  4. Push to the branch (git push origin feature/YourFeature).
  5. Open a pull request.

For detailed contribution guidelines, refer to the CONTRIBUTING.md file.

License

This project is licensed under the MIT License

Author

Future Enhancements

  • 🔮 Session Storage: Coming soon!
  • 🍪 Cookie Storage: On the roadmap!

About

LSC Storage is means - Local | Session | Cookie Storage

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published