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

@itpolsri/simple-webstorage

v1.0.1

Published

Asynchronous Lightweight utilities that can make easier to write and read application storage in client browser.

Downloads

17

Readme

Async Simple Web Storage

Lightweight utilities that can make easier to write and read application storage in client browser. Inspired by Sutan gading's simple web storage, one of our team member

it's a asynchronous API using Promise

Support :

  • Local Storage
  • Cookie Storage
  • Session Storage

How using this package

1. Use Package with NPM

$ npm i @itpolsri/simple-webstorage

All API import

import SimpleWebStorage from '@itpolsri/simple-webstorage'

const storage = SimpleWebStorage()

// empty the third parameter to store data permanently (only affected in local)
storage
  .asyncLocal
  .set('key', 'value') 
  .then(r=> /*do what you want to do..*/)
storage
  .asyncCookie
  .set('key', 'value', 5)
  .then(r=> /*do what you want to do..*/)
storage
  .asyncSession
  .set('key', 'value', 5)
  .then(r=> /*do what you want to do..*/)

// we support setBulk too :), if you want to set data all at once
storage
  .asyncLocal
  .setBulk([
    {
      key:'a',
      value:'hello'
    },
    {
      key:'b',
      value:'world'
    }
  ])
  .then(r=> /*do what you want to do*/)
  // resolved value = [{key:'a',value:'hello'} , {key:'b',value:'world'}]

Partial API import

// # for local storage
import { 
  get as getLocalStorage, 
  set as setLocalStorage ,
  setBulk as setBulkLocalStorage
} from '@itpolsri/simple-webstorage/src/local'


setLocalStorage('key', {
  name: 'you',
  skill: [
    'angry',
    'crying'
  ]
})
  .then(r=> /*do what you want to do..*/) 

setBulkLocalStorage([
  {
    key:'a',
    value:'override this value'
  },
  {
    key:'b',
    value:'this one too'
  }
])
.then(r=> /*do what you want to do..*/)

// { name: 'you', skill: ['angry', 'crying'] }
getLocalStorage('key')
  .then(r=> /*do what you want to do..*/)
or you can import partial API like this :
// # for cookie storage
import CookieStorage from '@itpolsri/simple-webstorage/lib/cookie'

// # for local storage
// import LocalStorage from 'simple-webstorage/lib/local'

// # for session storage
// import SessionStorage from 'simple-webstorage/lib/session'

const cookie = CookieStorage()

cookie
  .set('remembered', true)
  .then(r=> /*do what you want to do..*/)
cookie
  .set('forgotten', true)
  .then(r=> /*do what you want to do..*/)


cookie
  .get('remembered')
  .then(r=> /*do what you want to do..*/)

// ['remembered', 'forgotten'] # list all keys. returns array
cookie
  .keys()
  .then(r=> /*do what you want to do..*/)

2. All in minified js

<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/polyfill.js"></script>
<script type="text/javascript" src="https://unpkg.com/@itpolsri/[email protected]/lib/bundle/simple-webstorage.min.js"></script>
<script type="text/javascript">
  var storage = SimpleWebStorage();

  storage
    .asyncLocal
    .set('key', 'value');
    .then(r=> /*do what you want to do..*/)
  storage
    .asyncCookie
    .set('key', 'value', 5);
    .then(r=> /*do what you want to do..*/)
  storage
    .asyncSession
    .set('key', 'value', 5);
    .then(r=> /*do what you want to do..*/)
</script>

API Details

| Storage | Method | Parameters | |-----------|-------------|---------------------------------------------------------------------------------------------| | asyncLocal | set | key (type: String), value (type: any, default: 0), expiryInMinutes (type: Number, default: null) | | asyncCookie or asyncSession or asyncLocal | get | key (type: String) | | asyncCookie or asyncSession | set | key (type: String), value (type: any, default: 0), expiryInMinutes (type: Number, default: 5) | | asyncCookie or asyncSession or asyncLocal | remove | key (type: String) | | asyncCookie or asyncSession or asyncLocal | keys | none | | asyncCookie or asyncSession or asyncLocal | clear | none |


Copyright © 2019 by IT-Polsri, soon will be IT-Us 🙂