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

zdatastorebase

v1.0.0

Published

A cross between a database and a data store.

Downloads

2

Readme

ZDataStoreBase

A cross between a database and a data store.

Install

npm install --save zdatastorebase

Or

yarn add zdatastorebase

Usage

// JavaScript
const Store = require('zdatastorebase').Store
const MultiStore = require('zdatastorebase').MultiStore
const Base = require('zdatastorebase').Base

// TypeScript
import {Store, MultiStore, Base} from 'zdatastorebase'

const store = new Store()
const multiStore = new MultiStore()
const base = new Base()

store.setData('key', {innerKey: 'value'})
store.getData('key') // {innerKey: 'value'}

multiStore.insertStore('storeName')
multiStore.insert('key', {innerKey: 'value'}, 'storeName')
multiStore.getStore('storeName') // {data: {key: {innerKey: 'value'}}, getData: Function, setData: Function}
multiStore.get('key', 'storeName') // {innerKey: 'value'}
multiStore.update('key', {innerKeyOne: 'value1', innerKeyTwo: 2}, 'storeName')
multiStore.drop('key', 'storeName')
multiStore.dropStore('storeName')

base.execute({
  action: 'add',
  store: 'storeName'
})
base.execute({
  action: 'set',
  store: 'storeName',
  data: {key: {innerKey: 'value'}}
})
base.execute({
  action: 'get',
  store: 'storeName',
  where: {
    innerKey: 'value'
  },
  condition: '==='
}) // {innerKey: 'value'}
base.execute({
  action: 'delete',
  store: 'storeName',
  where: {
    innerKey: 1
  },
  condition: '!=='
})
base.execute({
  action: 'drop',
  store: 'storeName'
})

Types

Data

{
  [key: string]: T
}

Query

export type Query = {
  store: string
  action: 'get' | 'set' | 'drop' | 'add' | 'delete'
  data?: Data<any>
  where?: Data<any>
  key?: string
  condition?: '===' | '!==' | '<' | '>' | '<=' | '>=' | '!exist' | 'exists'
}

actions

  • get - if key is set then return the value of key else returns the values in store where the conditions are met
  • set - stores the value of data as key
  • drop - deletes store
  • add - creates store
  • delete - if key is set then deletes the value of key else deletes the values in store where the conditions are met

conditions

where and condition are used together to perform logic.

When an action requires where and condition, where is an object with keys and values, condition is the condition that must be met for the action to apply.

Every key/value pair in store is checked against each key/value pair in where with condition.

The conditions are:

  • '===' - equals
  • '!==' - not equal
  • '<' - less than
  • '>' - greater than
  • '<=' - less than or equal to
  • '>=' - greater than or equal to
  • '!exist' - key does not exist - value does not matter in this case
  • 'exists' - key exists - value does not matter in this case

Logic

When using a query object in Base.execute(), the fuction will throw an error if the query does not meet the following logic:

if (action === 'get') {
  key - if set then where and condition can't be defined
  data must not be defined
  where must be defined
  condition must be defined
}

if (action === 'set') {
  key must be set
  data must not be defined
  where must not be defined
  condition must not be defined
}

if (action === 'drop') {
  data must not be defined
  where must not be defined
  condition must not be defined
}

if (action === 'add') {
  data must not be defined
  where must not be defined
  condition must not be defined
}

if (action === 'delete') {
  key - if set then where and condition can't be defined
  data must not be defined
  where must be defined
  condition must be defined
}

Classes

Store

Properties

  • data: Data<any>

Methods

  • getData(key: string): any
  • setData(key: string, value: any): void

MultiStore

Properties

  • stores: Data<Store>

Methods

  • drop(key: string, store: string): void
  • dropStore(store: string): void
  • get(key: string, store: string): any
  • getStore(store: string): Store
  • insert(key: string, value: Data<any>, store: string): void
  • insertStore(store: string): void
  • update(key: string, value: Data<any>, store: string): void

Base

Extends

MultiStore

Properties

  • stores: MultiStore

Methods

  • execute(query: Query): object - returns nothing unless query.action equals 'get' then returns Data