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

simple-basket

v0.6.0

Published

A simple javascript basket for values

Downloads

6

Readme

simple-basket

A simple javascript basket for values.

Store values and objects in an array in memory.

Dependencies

lodash version: ~3.9.3

If you want to use the storage feature included that permits a basket to be saved in browser databases with the localforage package, you'll need:

(the package dist includes a bundle file that ships all these 3 dependencies)

How to use

  • Install with Bower
$ bower install simple-basket
  • Install with npm
$ npm install simple-basket
  • or get the javascript in dist folder: simplebasket.js

Use

Create a basket:

//on browser
var basket = window.simplebasket.create();

//on node
var basket = require('simple-basket').create();

Add items:

//add array
var aitems = [1, 2, 3, 4, 5, {'id': 1, name: 'john'}, {'id': 2, name: 'john'}];
basket.add(aitems);

//add list of items (
basket.add(1, 2, 3, 4, 5, {'id': 1, name: 'john'}, {'id': 2, name: 'john'});

Get items

basket.getall(); //[1, 2, 3, 4, 5, {'id': 1, name: 'john'}, {'id': 2, name: 'john'}]

Find items

basket.find({key: 'id', value: '2'}) //[{'id': 2, name: 'john'}]

basket.find({key: 'name', value: 'john'}) //[{'id': 1, name: 'john'}, {'id': 2, name: 'john'}]

simplebasket Interface

  • create() - Initialize a new Basket
Extending the basket
  • plug() - permits plugging a plugin-wrapper
  • unplug() - unplugg a plugin-wrapper
  • getBasePluginWrapper() - just to get the plugin base object for use as wrapper
  • getBasePlugin() - just to get the plugin base object for use without wrapper (direct call to driver)
  • Basket - get the Basket constructor

Basket Interface

  • add() - Add one or more items to basket
  • set() - Sets the basket cloning from an array of values
  • getClone() - Returns all items in basket (clone)
  • remove() - Remove an item(s) by a reference a key/value pair
  • removeAt() - Remove one item by position
  • removeAll() - Removes all items in the basket (Clear the basket)
  • iterate() - Iterate the basket calling a function for each item
  • count() - Returns the number of items in the basket
  • find() - Find values in basket

The Basket interface is extended with:

  • implement() - allows an instance Basket to implement a driver for the plugin-wrapper interface
  • dispose() - removes from an instance Basket a driver implementation for the plugin-wrapper interface

The package comes with a storage.js wrapper and a localforageDriver.js that permits a basket to be saved in browser databases with the localforage package.

Using the storage wrapper

Example with the localforageDriver

option 1 - using the complete bundle (easy)

Include File: dist/plugins/storage/storage-localforage.js This file include all dependencies needed:

option 2 - install dependencies

bower install localforage#1.2.3

bower install localforage-sessionstoragewrapper#1.0.1

Include the files:

  • dist/plugins/storage/storage.js
  • dist/plugins/storage/drivers/localforageDriver.js
var basket, lfDriver;

basket = window.simplebasket.create();
basket.add({key: 1}, {key: 2}, {key: 3});

window.localforageDriver
  .create(window.localforageDriver.STORAGE.LOCALSTORAGE, {name: 'app', storeName: 'store', key: 'basket'})
  .then(function( value ) {
  
    lfDriver = value;
    basket.implement(basket.ISTORAGE, lfDriver);
    
    //to save the basket
    basket.save()
      .then(function( data ) {
        //basket was saved to storage
      })
      .catch(function( error ) {
        //error
      });
    
    //...
    
    //to load the basket from storage:
    basket.load()
      .then(function( data ) {
        //data loaded from storage to basket
      })
      .catch(function( error ) {
        //error
      });
});

Notes

  • This is a work in progress.

Contribution

  • Contributions and comments are welcome.

Authors

License

Copyright (c) 2015 João Carvalho

Licensed under the MIT License