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

clientdatastore

v1.0.4

Published

Promise based client/server side storage. Uses IndexedDB/localStorage/heap based on availability

Downloads

13

Readme

Build Status Code Climate

Dependency Status devDependency Status peerDependency Status

clientdatastore

Unified implementation for saving data in browsers. Gracefully degrades from IndexedDB to WebSQL to Heap.

clientdatastore is a fast and simple storage library for JavaScript. It improves the offline experience of your web app by using asynchronous storage (IndexedDB or WebSQL) with a simple API.

clientdatastore uses LocalStorage/Heap in browsers with no IndexedDB or WebSQL support.

To use clientdatastore, just drop a single JavaScript file into your page:

install with npm:

npm install clientdatastore

This module is compatible with browserify and lasso.

Usage Details

var ds = require('clientdatastore');


var selectedDataStore = ds.get();


var resolvedDataStore = ds.get(function() {
    var ua = window.navigator.userAgent.toLowerCase();
    if (ua.indexOf('msie') > -1) {
        return 'heap';
    } else if (ua.indexOf('safari') > -1 && ua.indexOf('chrome') === -1) {
        return 'heap';
    }
    return 'idb';
});


var resolvedDataStore = ds.get('heap');


var database1 = selectedDataStore.init('DB_NAME_1', meta);
database1.insert();

var database2 = selectedDataStore.init('DB_NAME_2', meta);
database2.insert();

selectedDataStore.destroy('DB_NAME_2');

More samples

Assume we need marks of all students in a class

Each student has

  • roll number (unique index)

  • subject1 mark

  • subject2 mark

  • subject3 mark

  • total

Create DB, Object stores, indexes

tableMeta

{
     name: 'marksheet',
     indexes: [
         {
             name: 'rollnumber',
             unique: true
         }
     ]
}

Code Sample

var dataStore = require('clientdatastore');
dataStore.init('students', [tableMeta]);

Insert data

studentData

[
    {
        'rollnumber': 1,
        'sub1': 90,
        'sub2': 99,
        'sub3': 89,
        'total': 278
    },
    {
        'rollnumber': 2,
        'sub1': 91,
        'sub2': 100,
        'sub3': 89,
        'total': 280
    }
]

Code sample

var meta = { name: 'marksheet' }
dataStore.insert(meta, studentData);

Interfaces

init(dbName, metas)

Creates objectStores and indexes.

dbName - name of the database you want to create.

metas - Array that accepts list of ObjectStore(like table) and their indexes.

output - promise

promise resolution: empty

destory(dbName)

dbName - name of the database you want to create.

Deletes the provided database.

getStore(dbName)

metas Sample
[
    {
        name: "marksheet_jan",
        meta: [
    {name:'roll_numb', unique:true}
      ]
    },
    {
        name: "marksheet_feb",
        meta: [
            {name:'roll_numb', unique:true}
            ]
    }
]

insert(meta, data)

insert object(s) to the specified ObjectStore.

meta - Object with ObjectStore name

output - promise

promise resolution: [ids] for inserted records

Sample

meta:

{
    name: 'marksheet_jan'
}

data:

[
    {
        'rollnumber': 1,
        'sub1': 90,
        'sub2': 99,
        'sub3': 89,
        'total': 278
    }
]

select(meta, [filters])

Returns object(s) from the specified ObjectStore, based on the filter(s).

meta - Object with ObjectStore name and index name which will be used if its a non filter selectAll case

filters - {index, [filterData]}

output - promise

promise resolution: Array of objects matching the filters

Sample

meta:

{
    name: 'marksheet_jan'
}

filterData:

{
    index: rollnumber,
    data: [
        1,
        22
    ]
}

Returns records having rollnumber 1 or 22.

update(meta, filterData, data)

Updates object(s) in the specified ObjectStore, based on the filter(s) and provided data. If any property is set to undefined, those properties will be dropped when updating.

meta - Object with ObjectStore name

filter - {index, [filterData]}

data - {}

output - promise

promise resolution: empty

Sample

meta:

{
    name: 'marksheet_jan'
}

filterData:

{
    index: "rollnumber",
    data: [
        1
    ]
}

data:

{
    'rollnumber': 1,
    'sub1': 100,
    'sub2': 100,
    'sub3': 100,
    'total': 300
}

updates record will rollnumber 1 with the provided data.

remove(meta, filterData)

Delete object(s) in the specified ObjectStore, based on the filter(s). Not providing any filter will delete all entries.

meta - Object with ObjectStore name

filter - {index, [filterData]}

output - promise

promise resolution: empty

Sample

meta:

{
    name: 'marksheet_jan'
}

filterData:

{
    index: rollnumber,
    data: [
        1
    ]
}

Removes the record with rollnumber 1.