npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kss-store

v1.0.0

Published

Different ways of storing data by the same interface

Readme

KssStore - Universal Storage Interface

KssStore provides a uniform interface for different storage mechanisms, allowing you to easily switch between storage types while keeping your application code consistent.

Supported Storage Types

  • [x] localStorage (default, browser)

  • [x] sessionStorage (browser)

  • [x] IndexedDB (browser)

  • [x] MongoDB (server)

  • [x] FileSystem (server)

  • [ ] MySQL (server)

  • [ ] SQLite (server)

  • [ ] PostgreSQL (server)

  • [ ] Redis (server)

Installation

npm install kss-store

For optional database drivers:

# For MongoDB (already included as a dependency)
# For MySQL
npm install mysql2
# For PostgreSQL
npm install pg
# For Redis
npm install redis

Basic Usage

import { KssStore } from 'kss-store';

// Create a storage instance with the desired type
const storage = new KssStore({
  type: 'localStorage', // Default storage type
  options: {
    // Options specific to the storage type
    prefix: 'myapp' // Optional key prefix for localStorage/sessionStorage
  }
});

// Use the storage API
await storage.set('user', { id: 1, name: 'John' });
const user = await storage.get('user');
console.log(user); // { id: 1, name: 'John' }

const allKeys = await storage.keys();
console.log(allKeys); // ['user']

await storage.remove('user');
console.log(await storage.get('user')); // null

await storage.clear(); // Clear all stored items

Storage-Specific Configuration

Web Storage (localStorage / sessionStorage)

Both localStorage and sessionStorage are implemented using a unified WebStorage adapter with identical API - only the storage mechanism differs:

// Using localStorage
const localStorage = new KssStore({
  type: 'localStorage',
  options: {
    prefix: 'myapp' // Optional prefix for keys
  }
});

// Using sessionStorage
const sessionStorage = new KssStore({
  type: 'sessionStorage',
  options: {
    prefix: 'myapp' // Optional prefix for keys
  }
});

// Direct access to storage implementations
import { WebStorageStore, LocalStorageStore, SessionStorageStore } from 'kss-store';

// Unified adapter that can be configured for either localStorage or sessionStorage
const webStorage = new WebStorageStore({ 
  storageType: 'localStorage', // or 'sessionStorage'
  prefix: 'myapp'
});

// Aliases for backward compatibility
const localStorage = new LocalStorageStore({ prefix: 'myapp' });
const sessionStorage = new SessionStorageStore({ prefix: 'myapp' });

IndexedDB

const storage = new KssStore({
  type: 'IndexedDB',
  options: {
    dbName: 'myAppDB', // Database name, default: 'kss-store'
    storeName: 'myData', // Store name, default: 'kss-data'
    version: 1 // Database version, default: 1
  }
});

MongoDB

const storage = new KssStore({
  type: 'MongoDB',
  options: {
    connectionString: 'mongodb://localhost:27017',
    database: 'mydb',
    collection: 'kss_store' // default: 'kss_store'
  }
});

File System (Node.js)

const storage = new KssStore({
  type: 'FileSystem',
  options: {
    path: './data' // Storage directory, default: process.cwd() + '/.kss-store'
  }
});

API

All storage implementations support the following async methods:

  • get(key: string): Promise<any> - Retrieve a value
  • set(key: string, value: any): Promise<void> - Store a value
  • remove(key: string): Promise<void> - Remove a value
  • clear(): Promise<void> - Clear all values
  • keys(): Promise<string[]> - Get all keys

Development

Running Tests

The project uses Vitest for testing. Each storage implementation has its own test suite.

# Install dependencies
npm install

# Run all tests
npm test

# Run tests in watch mode during development
npm run test:watch

# Run tests with coverage report
npm run test:coverage

Test environments are set up automatically:

  • Browser storage (localStorage, sessionStorage) uses DOM mocks
  • IndexedDB uses the fake-indexeddb library
  • MongoDB uses mongodb-memory-server for in-memory testing
  • FileSystem creates temporary directories for testing

Publishing to npm

The package includes scripts to simplify the publishing process:

# Before publishing, you should:
# 1. Update version in package.json
# 2. Ensure tests pass and build succeeds

# Perform a dry run to check what would be published
npm run release:dry

# Publish a new version to npm
npm run release

# Publish a beta version
npm run release:beta

For first-time publishers:

  1. Create an npm account if you don't have one: npm adduser
  2. Login to npm: npm login
  3. Update repository info in package.json
  4. Set the package version (for first release use 1.0.0)
  5. Run npm run release

Implementing a New Storage Adapter

To add a new storage adapter:

  1. Create a new file in src/ named after your storage type
  2. Implement the IStore interface
  3. Add your storage type to the StorageType type in interface.ts
  4. Create tests in tests/ to verify your implementation

License

MIT