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

pdatastore

v0.0.5

Published

PDataStore retrieves data from a data-source in an HTMLElement, saves the data into memory and provides quick access to this data. You can therefore also convert stored data to certain HTMLElements

Downloads

3

Readme

PDataStore

#Synopsis PDataStore retrieves data from a data-source in an HTMLElement, saves the data into memory and provides quick access to this data. You can therefore also convert stored data to certain HTMLElements e.g HTMLSelectElement options

PDataStore Implementation

Injecting the data (data sources)

PDataStore will search for an element with the id "p-store" This div should hold all data-sources as an attribute.

<div id="p-store"></div>

Inject data-sources to the store like this:

<div id="p-store" data-books='[{
        "id":"1", 
        "book_name":"PDataStore Book", 
        "author_name":"Paul"
     }]'>
</div>

Note:: PDataStore loads data from its sources, saves it into memory and removes loaded data-sources from p-store.

You can as well pass the url to where PDataStore will fetch the data as the data-source value

<!--Inject the data: blade templates-->
<div id=p-store data-source-books='{{$books}}' 
                data-book-route='{{$book_source_url}}'></div>

Retrieving and Manipulating Data

We will use PDataStore to load the list of books to a HTMLSelectElement

var PDataStore = require('pdatastore');
function Books(){
    var pStore = new PDataStore();
    //so we are looking for all books in data-source-books 
    //whose authors name is equals paul
    var result = pStore.findDataByKeyValue('authors_name', 'paul', 'data-source-books').result;
        
    /**you can as well load the data into an htmlSelectElement.
    *  You only have to pass the parameters;
    *  id : is the key that its value will be the HTMLOptionElement value
    *  authors_name : is the key that its value will be the text of the HTMLOptionElement
    *  books : The input name of HTMLSelectElement
    *  2 : The default value of the HTMLOption
    **/
    pStore.findDataByKeyValue('authors_name', 'paul', 'data-books')
            .toHtmlList('id', 'authors_name', 'books', '2');
}

We can also Load all Data Source At Once into Memory. We advice you to use this mostly when your data-source contains url to fetch the data.

var PDataStore = require('pdatastore');
function Books(){
    //initialize PDataStore and pass a boolean to its contructor.
    //This will automatically load all data to memory on page load
    var pStore = new PDataStore(true);
    
    //or
    
    var pStore = new PDataStore();
    //lets loads all data into memory.. 
    pStore.synchronizeData();
}

More Examples

<div id="p-store" data-source-products='[
    {'id':1,'product_category_id':23, 'product_name':'Samsung S6'},
    {'id':16,'product_category_id':24, 'product_name':'Bournvita'},
    {'id':14,'product_category_id':23, 'product_name':'Blackberry'},
    {'id':4,'product_category_id':25, 'product_name':'Origin'}
    ]'>
</div>
    
<!--form-->
<select name='product_cat'>
    <option value="23">Mobile Devices</option>
    <option value="24">Beverages</option>
    <option value="25">Beer</option>
    <option value="26">Detergent</option>
</select>
    
<select name='products'></select>
var PDataStore = require('pdatastore');
var pStore = new PDataStore(true);
    
var category = document.getElementsByName('product_cat')[0];
if(category!==null && category!==undefined){
    category.addEventListener('change', function(){
        var value = this.options[this.selectedIndex].value;
        pStore.findDataByKeyValue('product_category_id', value, 'data-source-products')
            .toHtmlList('id', 'product_name', 'products', '14');
    });
    
//JQuery Developers
$('input[name=product_cat]').change(function(){
    pStore.findDataByKeyValue('product_category_id', $(this).va(), 'data-source-products')
            .toHtmlList('id', 'product_name', 'products', '14');
});
}

Next Example

Try it Out.

Installation

npm install pdatastore

Tests

open the file pdatastoretest.html in your browser

License

MIT