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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@piclist/store

v3.0.0

Published

A simple and efficient key-value store for piclist, supporting JSON and binary data.

Readme

@piclist/store

npm version License: MIT

A simple and efficient key-value store for PicList, supporting both JSON and binary data storage with built-in compression and metadata management.

✨ Features

  • 🗄️ Dual Storage Options: JSON-based and binary database storage
  • 🔍 Rich Query Interface: Support for filtering, sorting, pagination
  • 📦 Built-in Compression: Zlib adapter for efficient storage
  • 🎯 TypeScript Support: Full type definitions included
  • Async/Await: Modern promise-based API
  • 🔄 Batch Operations: Insert, update, and remove multiple items
  • 📝 Auto Metadata: Automatic timestamps and unique ID generation

📦 Installation

npm install @piclist/store

🚀 Quick Start

DBStore (Binary Database)

Perfect for storing large amounts of structured data with efficient querying capabilities.

import { DBStore } from '@piclist/store'

// Initialize database with collection
const db = new DBStore('data.db', 'images')

// Insert a single item
const result = await db.insert({
  imgUrl: 'https://example.com/image.jpg',
  tags: ['nature', 'landscape'],
  size: 1024
})

console.log(result)
// {
//   id: 'unique-uuid',
//   imgUrl: 'https://example.com/image.jpg',
//   tags: ['nature', 'landscape'],
//   size: 1024,
//   createdAt: 1671234567890,
//   updatedAt: 1671234567890
// }

JSONStore (JSON Configuration)

Ideal for configuration files and simple key-value storage.

import { JSONStore } from '@piclist/store'

// Initialize JSON store
const config = new JSONStore('config.json')

// Set configuration values
config.set('theme', 'dark')
config.set('language', 'en')
config.write() // Persist to disk

// Get configuration
const theme = config.get('theme') // 'dark'

📚 API Reference

DBStore

The main database class providing collection-based document storage.

Constructor

new DBStore(dbPath: string, collectionName: string)
  • dbPath: Path to the database file
  • collectionName: Name of the collection within the database

Methods

.get(filter?: IFilter): Promise<IGetResult<T>>

Retrieve items from the collection with optional filtering.

// Get all items
const all = await db.get()

// Get with filtering and pagination
const filtered = await db.get({
  orderBy: 'desc',  // 'asc' | 'desc' - order by creation time
  limit: 10,        // maximum number of items
  offset: 0         // skip items (for pagination)
})

console.log(filtered)
// { total: 100, data: [...] }
.insert<T>(value: T): Promise<IResult<T>>

Insert a single item into the collection.

const item = await db.insert({
  title: 'My Image',
  url: 'https://example.com/image.jpg'
})
.insertMany<T>(values: T[]): Promise<IResult<T>[]>

Insert multiple items in a single operation.

const items = await db.insertMany([
  { url: 'image1.jpg' },
  { url: 'image2.jpg' },
  { url: 'image3.jpg' }
])
.getById(id: string): Promise<IResult<T> | undefined>

Retrieve a specific item by its ID.

const item = await db.getById('some-uuid')
if (item) {
  console.log(item.url)
}
.updateById(id: string, value: Partial<T>): Promise<boolean>

Update an existing item by ID. Returns true if successful, false if item not found.

const success = await db.updateById('some-uuid', {
  title: 'Updated Title'
})
.updateMany(items: IObject[]): Promise<{ total: number, success: number }>

Update multiple items by their IDs.

const result = await db.updateMany([
  { id: 'id1', title: 'New Title 1' },
  { id: 'id2', title: 'New Title 2' }
])

console.log(result) // { total: 2, success: 2 }
.removeById(id: string): Promise<void>

Remove an item by its ID.

await db.removeById('some-uuid')
.overwrite<T>(values: T[]): Promise<IResult<T>[]>

Replace the entire collection with new data.

const newCollection = await db.overwrite([
  { url: 'new1.jpg' },
  { url: 'new2.jpg' }
])

JSONStore

Simple JSON file-based key-value storage.

Constructor

new JSONStore(filePath: string)

Methods

.get(key: string, defaultValue?: any): any

Get a value by key.

const value = config.get('theme', 'light')
.set(key: string, value: any): void

Set a value for a key.

config.set('theme', 'dark')
.has(key: string): boolean

Check if a key exists.

if (config.has('theme')) {
  // Theme is configured
}
.unset(key: string): void

Remove a key and its value.

config.unset('oldSetting')
.read(flush?: boolean): IJSON

Read data from file (automatically called on access).

.write(): void

Write current data to file.

config.set('newKey', 'newValue')
config.write() // Persist changes

🔧 Advanced Usage

Custom Filtering

// Get recent items
const recent = await db.get({
  orderBy: 'desc',
  limit: 5
})

// Pagination
const page2 = await db.get({
  limit: 20,
  offset: 20
})

Batch Operations

// Bulk insert with error handling
try {
  const results = await db.insertMany(largeDataset)
  console.log(`Inserted ${results.length} items`)
} catch (error) {
  console.error('Bulk insert failed:', error)
}

// Batch updates
const updateResult = await db.updateMany([
  { id: 'id1', status: 'processed' },
  { id: 'id2', status: 'processed' },
  { id: 'id3', status: 'failed' }
])

console.log(`Updated ${updateResult.success}/${updateResult.total} items`)

Configuration Management

// Application settings
const settings = new JSONStore('app-settings.json')

// Default configuration
settings.set('upload.maxSize', 10 * 1024 * 1024) // 10MB
settings.set('upload.allowedTypes', ['jpg', 'png', 'gif'])
settings.set('ui.theme', 'auto')
settings.write()

// Runtime access
const maxSize = settings.get('upload.maxSize')
const theme = settings.get('ui.theme', 'light')

🎯 TypeScript Support

Full TypeScript definitions are included:

interface ImageRecord {
  url: string
  title: string
  tags: string[]
  size: number
}

const db = new DBStore('images.db', 'uploads')
const image = await db.insert<ImageRecord>({
  url: 'https://example.com/photo.jpg',
  title: 'Beautiful Sunset',
  tags: ['sunset', 'nature'],
  size: 2048576
})

// TypeScript knows the shape of `image`
console.log(image.createdAt) // number
console.log(image.tags)      // string[]

📄 License

MIT

Copyright (c) 2025 Kuingsmile