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

yuniqkv

v1.0.1

Published

YuniqKV is a versatile key-value storage library that supports both IndexedDB and LocalStorage with encryption and soft delete capabilities. It is designed to be used in browser environments.

Downloads

11

Readme

YuniqKV

YuniqKV is a versatile key-value storage library that supports both IndexedDB and LocalStorage with encryption and soft delete capabilities. It is designed to be used in browser environments.

Features

  • Multiple Storage Backends: Supports IndexedDB and LocalStorage.
  • Encryption: Secure your data with AES encryption.
  • Soft Delete: Mark items as deleted without permanently removing them.
  • TTL and Expiry: Set time-to-live (TTL) for items.
  • Querying: Advanced querying capabilities with filters, sorting, and pagination.
  • Batch Operations: Perform bulk operations efficiently.
  • Transactions: Support for transactional operations.
  • Event-Driven: Emits events for various operations.

Installation

Install the package via npm:

npm install yuniqkv

Usage

Initialization

import { YuniqKV } from 'yuniqkv';

const kv = new YuniqKV({
  storageType: 'indexeddb', // or 'localstorage'
  databaseName: 'myDatabase',
  encryption: true,
  privateKey: 'my-secret-key',
  autoCleanupInterval: 60000, // 1 minute
  version: 1,
});

await kv.init();

Basic Operations

Set Item

await kv.set('myKey', { name: 'John Doe' });

Get Item

const value = await kv.get<{ name: string }>('myKey');
console.log(value); // { name: 'John Doe' }

Delete Item

await kv.delete('myKey');

Advanced Operations

Set Item with Options

await kv.set('myKey', { name: 'John Doe' }, { ttlSeconds: 3600, tags: ['user'] });

Query Items

const result = await kv.query<{ name: string }>({
  tags: ['user'],
  orderBy: 'createdAt',
  order: 'desc',
  limit: 10,
});

console.log(result.items);

Batch Operations

await kv.setMany([
  { key: 'key1', value: { name: 'Alice' } },
  { key: 'key2', value: { name: 'Bob' } },
]);

const values = await kv.getMany(['key1', 'key2']);
console.log(values);

Transactions

await kv.transaction(async (txn) => {
  await txn.set('key1', { name: 'Alice' });
  await txn.set('key2', { name: 'Bob' });
  const value = await txn.get<{ name: string }>('key1');
  console.log(value);
});

Events

kv.on('set', (key, value, id) => {
  console.log(`Item set: ${key} = ${value}, id = ${id}`);
});

kv.on('delete', (key, id) => {
  console.log(`Item deleted: ${key}, id = ${id}`);
});

Backup and Restore

Backup

const backup = await kv.backup();
console.log(backup);

Restore

await kv.restore(backup);

Optimization

await kv.optimize();

API Reference

YuniqKV

Methods

  • init(): Promise<void>
  • dispose(): void
  • set<T>(key: string, value: T, options?: SetOptions): Promise<number>
  • get<T>(key: string, options?: GetOptions): Promise<T | undefined>
  • delete(key: string, options?: DeleteOptions): Promise<boolean>
  • setMany<T>(items: Array<{ key: string; value: T }>, options?: SetOptions): Promise<number[]>
  • getMany<T>(keys: string[], options?: GetOptions): Promise<(T | undefined)[]>
  • deleteMany(keys: string[], options?: DeleteOptions): Promise<boolean[]>
  • query<T>(options: QueryOptions): Promise<QueryResult<T>>
  • queryKeys(options: QueryOptions): Promise<string[]>
  • queryCount(options: QueryOptions): Promise<number>
  • clear(): Promise<void>
  • clearItems(): Promise<void>
  • getKeys(options?: QueryOptions): Promise<string[]>
  • hasItem(key: string): Promise<boolean>
  • bulk<T>(operations: Array<{ type: 'set' | 'delete'; key: string; value?: T; options?: SetOptions | DeleteOptions }>): Promise<Array<{ success: boolean; id?: number }>>
  • transaction<T>(callback: (transaction: { get: <U>(key: string) => Promise<U | undefined>; set: <U>(key: string, value: U, options?: SetOptions) => Promise<number>; delete: (key: string, options?: DeleteOptions) => Promise<boolean> }) => Promise<T>): Promise<T>
  • batchGet<T>(options: { prefix?: string; suffix?: string; tags?: string[]; batchSize?: number; callback: (batch: Array<{ key: string; value: T }>) => Promise<void> }): Promise<void>
  • watch<T>(key: string, callback: (value: T | undefined) => void): () => void
  • watchPattern<T>(pattern: { prefix?: string; suffix?: string; tags?: string[] }, callback: (changes: Array<{ key: string; value: T | undefined; type: 'set' | 'delete' }>) => void): () => void
  • getFirstItem<T>(options?: { ascending?: boolean }): Promise<{ key: string; value: T } | undefined>
  • isKeyFirst(key: string, ascending?: boolean): Promise<boolean>
  • getExpiredItems(): Promise<Array<{ key: string; expiry: number }>>
  • optimize(): Promise<void>
  • getStats(): Promise<StorageStats>
  • backup(): Promise<string>
  • restore(backup: string): Promise<void>
  • migrate(version: number, migrations: Array<{ version: number; migrate: (data: Map<string, StoreItem>) => Promise<Map<string, StoreItem>> }>): Promise<void>

Types

SetOptions

interface SetOptions {
  ttlSeconds?: number;
  prefix?: string;
  suffix?: string;
  expiry?: Date;
  tags?: string[];
  upsert?: boolean;
  returnOld?: boolean;
}

GetOptions

interface GetOptions {
  defaultValue?: any;
  throwIfNotFound?: boolean;
}

DeleteOptions

interface DeleteOptions {
  force?: boolean;
  soft?: boolean;
}

QueryOptions

interface QueryOptions {
  prefix?: string;
  suffix?: string;
  tags?: string[];
  expiryState?: 'valid' | 'expired' | 'all';
  limit?: number;
  offset?: number;
  orderBy?: 'id' | 'key' | 'createdAt' | 'updatedAt' | 'expiry' | 'deletedAt';
  order?: 'asc' | 'desc';
  includeSoftDeleted?: boolean;
}

QueryResult

interface QueryResult<T = any> {
  items: T[];
  total: number;
  hasMore: boolean;
}

StorageStats

interface StorageStats {
  totalItems: number;
  expiredItems: number;
  softDeletedItems: number;
  averageKeySize: number;
  averageValueSize: number;
  totalSize: number;
  storageUsage: number;
  storageQuota: number;
  compressionRatio: number;
  details: {
    itemsByPrefix: Record<string, number>;
    itemsBySuffix: Record<string, number>;
    itemsByTag: Record<string, number>;
    sizeByPrefix: Record<string, number>;
    sizeBySuffix: Record<string, number>;
    sizeByTag: Record<string, number>;
    ageStats: {
      newest: number;
      oldest: number;
      averageAge: number;
    };
    expiryStats: {
      soonestExpiry: number | null;
      latestExpiry: number | null;
      averageTimeToExpiry: number | null;
    };
    performanceStats: {
      averageReadTime: number;
      averageWriteTime: number;
      estimatedOperationsPerSecond: number;
    };
  };
}

License

MIT License. See LICENSE for more details.