All Projects → marcuswestin → Store.js

marcuswestin / Store.js

Licence: mit
Cross-browser storage for all use cases, used across the web.

Programming Languages

javascript
184084 projects - #8 most used programming language
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to Store.js

Depot.js
📦 depot.js is a storage library with a simple API
Stars: ✭ 247 (-98.19%)
Mutual labels:  serialization, storage, localstorage
Vue Warehouse
A Cross-browser storage for Vue.js and Nuxt.js, with plugins support and easy extensibility based on Store.js.
Stars: ✭ 161 (-98.82%)
Mutual labels:  storage, localstorage, cross-browser
Binaryprefs
Rapidly fast and lightweight re-implementation of SharedPreferences which stores each preference in files separately, performs disk operations via NIO with memory mapped byte buffers and works IPC (between processes). Written from scratch.
Stars: ✭ 484 (-96.46%)
Mutual labels:  serialization, storage
Vuex Persistedstate
💾 Persist and rehydrate your Vuex state between page reloads.
Stars: ✭ 5,561 (-59.28%)
Mutual labels:  storage, localstorage
Vlf
A Vue plugin from localForage.vue-localForage or vlf
Stars: ✭ 99 (-99.28%)
Mutual labels:  storage, localstorage
Hprose
HPROSE is short for High Performance Remote Object Service Engine. It's a serialize and RPC library, the serialize library of hprose is faster, smaller and more powerful than msgpack, the RPC library is faster, easier and more powerful than thrift.
Stars: ✭ 348 (-97.45%)
Mutual labels:  serialization, cross-browser
Localforage
💾 Offline storage, improved. Wraps IndexedDB, WebSQL, or localStorage using a simple but powerful API.
Stars: ✭ 19,840 (+45.28%)
Mutual labels:  storage, localstorage
Recoil Persist
Package for recoil state manager to persist and rehydrate store
Stars: ✭ 66 (-99.52%)
Mutual labels:  storage, localstorage
ddrive
A lightweight cloud storage system using discord as storage device written in nodejs
Stars: ✭ 25 (-99.82%)
Mutual labels:  storage, localstorage
Vuex Localstorage
Persist Vuex state with expires by localStorage or some else storage.
Stars: ✭ 129 (-99.06%)
Mutual labels:  storage, localstorage
Store
A better way to use localStorage and sessionStorage
Stars: ✭ 1,646 (-87.95%)
Mutual labels:  storage, localstorage
Hprose Js
Hprose is a cross-language RPC. This project is Hprose 2.0 RPC for JavaScript
Stars: ✭ 133 (-99.03%)
Mutual labels:  serialization, cross-browser
Angular Locker
🗄️ A simple & configurable abstraction for local/session storage in angular js projects
Stars: ✭ 318 (-97.67%)
Mutual labels:  storage, localstorage
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (-78.31%)
Mutual labels:  storage, localstorage
Vue Ls
💥 Vue plugin for work with local storage, session storage and memory storage from Vue context
Stars: ✭ 468 (-96.57%)
Mutual labels:  storage, localstorage
nativestor
NativeStor provide kubernetes local storage which is light weight and high performance
Stars: ✭ 20 (-99.85%)
Mutual labels:  storage, localstorage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-99.93%)
Mutual labels:  storage, localstorage
persistence
💾 Persistence provides a pretty easy API to handle Storage's implementations.
Stars: ✭ 18 (-99.87%)
Mutual labels:  storage, localstorage
vue-web-storage
Vue.js plugin for local storage and session storage (1.8 kb min+gz) 💾
Stars: ✭ 85 (-99.38%)
Mutual labels:  storage, localstorage
Flatdata
Write-once, read-many, minimal overhead binary structured file format.
Stars: ✭ 121 (-99.11%)
Mutual labels:  serialization, storage

Store.js

Cross-browser storage for all use cases, used across the web.

Circle CI npm version npm

Store.js has been around since 2010 (first commit, v1 release). It is used in production on tens of thousands of websites, such as cnn.com, dailymotion.com, & many more.

Store.js provides basic key/value storage functionality (get/set/remove/each) as well as a rich set of plug-in storages and extra functionality.

  1. Basic Usage
  2. Supported Browsers
  3. Plugins
  4. Builds
  5. Storages

Basic Usage

All you need to know to get started:

API

store.js exposes a simple API for cross-browser local storage:

// Store current user
store.set('user', { name:'Marcus' })

// Get current user
store.get('user')

// Remove current user
store.remove('user')

// Clear all keys
store.clearAll()

// Loop over all stored values
store.each(function(value, key) {
	console.log(key, '==', value)
})

Installation

Using npm:

npm i store
// Example store.js usage with npm
var store = require('store')
store.set('user', { name:'Marcus' })
store.get('user').name == 'Marcus'

Using script tag (first download one of the builds):

<!-- Example store.js usage with script tag -->
<script src="path/to/my/store.legacy.min.js"></script>
<script>
store.set('user', { name:'Marcus' })
store.get('user').name == 'Marcus'
</script>

Supported Browsers

All of them, pretty much :)

To support all browsers (including IE 6, IE 7, Firefox 4, etc.), use require('store') (alias for require('store/dist/store.legacy')) or store.legacy.min.js.

To save some kilobytes but still support all modern browsers, use require('store/dist/store.modern') or store.modern.min.js instead.

List of supported browsers

Plugins

Plugins provide additional common functionality that some users might need:

List of all Plugins

Using Plugins

With npm:

// Example plugin usage:
var expirePlugin = require('store/plugins/expire')
store.addPlugin(expirePlugin)

If you're using script tags, you can either use store.everything.min.js (which has all plugins built-in), or clone this repo to add or modify a build and run make build.

Write your own plugin

A store.js plugin is a function that returns an object that gets added to the store. If any of the plugin functions overrides existing functions, the plugin function can still call the original function using the first argument (super_fn).

// Example plugin that stores a version history of every value
var versionHistoryPlugin = function() {
	var historyStore = this.namespace('history')
	return {
		set: function(super_fn, key, value) {
			var history = historyStore.get(key) || []
			history.push(value)
			historyStore.set(key, history)
			return super_fn()
		},
		getHistory: function(key) {
			return historyStore.get(key)
		}
	}
}
store.addPlugin(versionHistoryPlugin)
store.set('foo', 'bar 1')
store.set('foo', 'bar 2')
store.getHistory('foo') == ['bar 1', 'bar 2']

Let me know if you need more info on writing plugins. For the moment I recommend taking a look at the current plugins. Good example plugins are plugins/defaults, plugins/expire and plugins/events.

Builds

Choose which build is right for you!

List of default builds

Make your own Build

If you're using npm you can create your own build:

// Example custom build usage:
var engine = require('store/src/store-engine')
var storages = [
	require('store/storages/localStorage'),
	require('store/storages/cookieStorage')
]
var plugins = [
	require('store/plugins/defaults'),
	require('store/plugins/expire')
]
var store = engine.createStore(storages, plugins)
store.set('foo', 'bar', new Date().getTime() + 3000) // Using expire plugin to expire in 3 seconds

Storages

Store.js will pick the best available storage, and automatically falls back to the first available storage that works:

List of all Storages

Storages limits

Each storage has different limits, restrictions and overflow behavior on different browser. For example, Android has has a 4.57M localStorage limit in 4.0, a 2.49M limit in 4.1, and a 4.98M limit in 4.2... Yeah.

To simplify things we provide these recommendations to ensure cross browser behavior:

Storage Targets Recommendations More info
all All browsers Store < 1 million characters (Except Safari Private mode)
all All & Private mode Store < 32 thousand characters (Including Safari Private mode)
localStorage Modern browsers Max 2mb (~1M chars) limits, android
sessionStorage Modern browsers Max 5mb (~2M chars) limits
cookieStorage Safari Private mode Max 4kb (~2K chars) limits
userDataStorage IE5, IE6 & IE7 Max 64kb (~32K chars) limits
globalStorage Firefox 2-5 Max 5mb (~2M chars) limits
memoryStorage All browsers, fallback Does not persist across pages!

Write your own Storage

Chances are you won't ever need another storage. But if you do...

See storages/ for examples. Two good examples are memoryStorage and localStorage.

Basically, you just need an object that looks like this:

// Example custom storage
var storage = {
	name: 'myStorage',
	read: function(key) { ... },
	write: function(key, value) { ... },
	each: function(fn) { ... },
	remove: function(key) { ... },
	clearAll: function() { ... }
}
var store = require('store').createStore(storage)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].