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

instancebox

v1.0.13

Published

Save instances in local/session storage and bring them back to live

Downloads

15

Readme

instanceBox

What: You want to store javascript instances in the browser
Why: I dont care
How: this module aims to offer a solution

Important

This is a draft module, does not work when the instance references other objects within. Looks like it is not easy to have that but I'm working on that.

build and run test

  • yarn
  • yarn build
  • yarn serve // runs on http://localhost:9999
  • yarn test // runs 2 basic cypress tests

what to expect

In page one.html:

// a constructor is available
function Person(name, age){
    this.name = name;
    this.age = age;
    
    // not yet
    // this.doc = new Doc(this.name. this.age)
}
Person.prototype.sayHello = function () {
    return 'Hi, my name is ' + this.name;
};

// we create a instance
var me  = new Person('Federico', 42);

// now we would like to save it (local storage is the default one)
instanceBox.set('thisIsMe', me);

That's it, now we are free to navigate to another page and fully retrieve the instance. Let`s go for instance at page two.html.
We`ll be able to retrieve the instance simply using the get method passing the right key:

var me = instanceBox.get('thisIsMe');
console.log(me.sayHello()) // ---> Hi, my name is Federico

What about sessionStorage ?

To chance storage is enough to call the two functions:

  • instanceBox.useSessionStorage()
  • instanceBox.useLocalStorage()

before saving / retrieving from the target storage.


something more

instanceBox offers the following methods:

  • useLocalStorage()
    sets localStorage as container
    returns: void

  • useSessionStorage()
    sets sessionStorage as container
    returns: void

  • set(key <string>, instance <object instance>)
    saves the given instance using the key provided
    returns: true OR Exception

  • get(key <string>)
    attempts to retrieve the instance that has been saved with the given key
    returns: Object OR null

  • remove(key <string>)
    if found removes the instance saved using the passed key
    returns: void

  • clear()
    completely cleans out the container
    returns: void

  • length()
    returns the number of elements saved
    returns: Number

  • getSize(key <string>)
    returns the size in bytes of the instance saved using the given key
    returns: Number OR null