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 🙏

© 2024 – Pkg Stats / Ryan Hefner

tiny-localstorage-db

v1.0.3

Published

A tiny localStorage-based database with compression.

Downloads

80

Readme

TinyLocalStorageDB

A lightweight and flexible JavaScript library for managing a local database using the browser's localStorage. It provides functionalities like data compression, batch operations, usage statistics, and a simple query language for advanced data retrieval.

Installation

npm install tiny-localstorage-db

Usage

// Import the TinyLocalStorageDB class
const TinyLocalStorageDB = require('tiny-localstorage-db');

// Create a new instance of TinyLocalStorageDB
const db = new TinyLocalStorageDB();

// Set data
db.set('user1', { name: 'John', age: 30 });

// Get data
const userData = db.get('user1');
console.log(userData); // Output: { name: 'John', age: 30 }

// Remove data
db.remove('user1');

// Batch operations
const dataToSet = [
  { key: 'user1', value: { name: 'John', age: 30 } },
  { key: 'user2', value: { name: 'Jane', age: 25 } },
];
db.batchSet(dataToSet);

const keysToGet = ['user1', 'user2'];
const batchData = db.batchGet(keysToGet);
console.log(batchData);

const keysToRemove = ['user1', 'user2'];
db.batchRemove(keysToRemove);

// Query Language
const queryConditions = [{ key: 'age', operator: 'gt', value: 25 }];
const queryResult = db.selectQuery(queryConditions);
console.log(queryResult);

// Usage Statistics
console.log(db.usageStatistics.getUsageCount('user1'));

// Execute a query using timestamp conditions
const timestampQueryConditions = [
  { key: 'timestamp', operator: 'gt', value: '2023-01-01T00:00:00' },
];
const timestampQueryResult = db.selectQuery(timestampQueryConditions);
console.log(timestampQueryResult);

API Documentation

set(key, value, compress = true) Sets a key-value pair in the database.

key: The key for the data. value: The value to be stored. compress: Optional. If set to true (default), the data will be compressed before storage.

get(key, decompress = true) Retrieves the value associated with the given key from the database.

key: The key to look up. decompress: Optional. If set to true (default), the retrieved data will be decompressed.

remove(key) Removes the key-value pair associated with the given key from the database.

key: The key to remove.

batchSet(dataArray, compress = true) Sets multiple key-value pairs in the database using an array of objects.

dataArray: An array of objects, each containing a key and value. compress: Optional. If set to true (default), the data will be compressed before storage.

batchGet(keysArray, decompress = true) Retrieves values for multiple keys from the database.

keysArray: An array of keys to retrieve. decompress: Optional. If set to true (default), the retrieved data will be decompressed.

batchRemove(keysArray) Removes multiple key-value pairs from the database.

keysArray: An array of keys to remove.

selectQuery(conditions) Executes a SELECT query on the database using the Query Language.

conditions: An array of conditions for the query. Each condition is an object with key, operator, and value.

executeQuery(key, value) Deprecated. Use selectQuery for executing queries.

usageStatistics.getUsageCount(key) Gets the usage count for a specific key in the database.

key: The key to get the usage count for.

License

This project is licensed under the MIT License - see the LICENSE file for details.