Stoor Save

Storage wrapper with support for namespacing, timeouts and multi get/set and remove.

Project README

📦 stoor

package version package downloads standard-readme compliant package license make a pull request

Storage wrapper with support for namespacing, timeouts and multi get/set and remove.

👀 Background

This module is a small wrapper around the local and session storage.

Features

  • Parsing and stringification of values
  • Custom storage adaptor
  • Plugable fallback (defaults to in memory)
  • Namespacing
  • Multi get, set & remove of values
  • Expiring values

Install

⚙️ Install

Install the package locally within you project folder with your package manager:

With npm:

npm install stoor

With yarn:

yarn add stoor

With pnpm:

pnpm add stoor

📖 Usage

Kitchen sink


var things = new Stoor({ namespace: 'things' }) // Namespaced to things and uses local storage
var otherThings = new Stoor({ namespace: 'otherThings', storage: 'session' }) // Namespaced to other things and uses Session storage
things.set('foo', 1)
things.set('bar', 2)
things.set('baz', { foo: 4, baz: 4 })
console.log(things.get('baz')) // {foo: 4, baz: 4}
console.log(otherThings.get('baz')) // null
console.log(things.get(['foo', 'bar'])) // [1, 2]

things.remove(['foo', 'bar'])
console.log(things.get(['foo', 'bar'])) // [null, null]

otherThings.set([['bar', 5], ['foo', 6]]) // Array of key value pairs to multi set
console.log(otherThings.get(['foo', 'bar'])) // [6, 5]

otherThings.set('nana', 1, 5000) // Will expire within 5000 ms.
otherThings.get('nana', 3) // Returns default value if expired.

things.clear()

Custom storage

You can configure any module that conforms to the the localStorage/sessionStorage API to be the fallback or main method of storage.

For example using cookie-session-storage:

new Stoor({fallback: cookieSessionStorage})
new Stoor({storage: cookieSessionStorage})

📚 API

For all configuration options, please see the API docs.

💬 Contributing

Got an idea for a new feature? Found a bug? Contributions are welcome! Please open up an issue or make a pull request.

🪪 License

MIT © Tiaan du Plessis

Open Source Agenda is not affiliated with "Stoor" Project. README Source: tiaanduplessis/stoor
Stars
26
Open Issues
2
Last Commit
1 year ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating