PHPackages                             ingenious/jstorage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ingenious/jstorage

ActiveComponent

ingenious/jstorage
==================

Composer for of andris9/jStorage

091JavaScript

Since Oct 19Pushed 10y ago1 watchersCompare

[ Source](https://github.com/Gimcrack/jStorage)[ Packagist](https://packagist.org/packages/ingenious/jstorage)[ RSS](/packages/ingenious-jstorage/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

NB!
---

[](#nb)

**If you don't need to support older Internet Explorer Versions (IE7 and below), use [simpleStorage](https://github.com/andris9/simpleStorage) instead.**

---

jStorage
========

[](#jstorage)

**jStorage** is a cross-browser key-value store database to store data locally in the browser - jStorage supports all major browsers, both in **desktop** (yes - even Internet Explorer 6) and in **mobile**.

Additionally jStorage is library agnostic, it works well with any other JavaScript library on the same webpage, be it jQuery, Prototype, MooTools or something else. Though you still need to have either a third party library (Prototype, MooTools) or [JSON2](https://github.com/douglascrockford/JSON-js/blob/master/json2.js) on the page to support older IE versions.

jStorage supports storing Strings, Numbers, JavaScript objects, Arrays and even native XML nodes which kind of makes it a JSON storage. jStorage also supports setting TTL values for auto expiring stored keys and - best of all - notifying other tabs/windows when a key has been changed, which makes jStorage also a local PubSub platform for web applications.

jStorage is pretty small, about 7kB when minified, 3kB gzipped.

Function reference
------------------

[](#function-reference)

### set(key, value\[, options\])

[](#setkey-value-options)

```
$.jStorage.set(key, value, options)
```

Saves a value to local storage. key needs to be string otherwise an exception is thrown. value can be any JSONeable value, including objects and arrays or a XML node. Currently XML nodes can't be nested inside other objects: `$.jStorage.set("xml", xml_node)` is OK but `$.jStorage.set("xml", {xml: xml_node})` is not.

Options is an optional options object. Currently only available option is options.TTL which can be used to set the TTL value to the key `$.jStorage.set(key, value, {TTL: 1000})`. NB - if no TTL option value has been set, any currently used TTL value for the key will be removed.

### get(key\[, default\])

[](#getkey-default)

```
value = $.jStorage.get(key)
value = $.jStorage.get(key, "default value")
```

get retrieves the value if key exists, or default if it doesn't. key needs to be string otherwise an exception is thrown. default can be any value.

### deleteKey(key)

[](#deletekeykey)

```
$.jStorage.deleteKey(key)
```

Removes a key from the storage. key needs to be string otherwise an exception is thrown.

### setTTL(key, ttl)

[](#setttlkey-ttl)

```
$.jStorage.set("mykey", "keyvalue");
$.jStorage.setTTL("mykey", 3000); // expires in 3 seconds
```

Sets a TTL (in milliseconds) for an existing key. Use 0 or negative value to clear TTL.

### getTTL(key)

[](#getttlkey)

```
ttl = $.jStorage.getTTL("mykey"); // TTL in milliseconds or 0
Gets remaining TTL (in milliseconds) for a key or 0 if not TTL has been set.
```

### flush()

[](#flush)

```
$.jStorage.flush()
```

Clears the cache.

### index()

[](#index)

```
$.jStorage.index()
```

Returns all the keys currently in use as an array.

```
var index = $.jStorage.index();
console.log(index); // ["key1","key2","key3"]
```

### storageSize()

[](#storagesize)

```
$.jStorage.storageSize()
```

Returns the size of the stored data in bytes

### currentBackend()

[](#currentbackend)

```
$.jStorage.currentBackend()
```

Returns the storage engine currently in use or false if none

### reInit()

[](#reinit)

```
$.jStorage.reInit()
```

Reloads the data from browser storage

### storageAvailable()

[](#storageavailable)

```
$.jStorage.storageAvailable()
```

Returns true if storage is available

### subscribe(channel, callback)

[](#subscribechannel-callback)

```
$.jStorage.subscribe("ch1", function(channel, payload){
    console.log(payload+ " from " + channel);
});
```

Subscribes to a Publish/Subscribe channel (see demo)

### publish(channel, payload)

[](#publishchannel-payload)

```
$.jStorage.publish("ch1", "data");
```

Publishes payload to a Publish/Subscribe channel (see demo)

### listenKeyChange(key, callback)

[](#listenkeychangekey-callback)

```
$.jStorage.listenKeyChange("mykey", function(key, action){
    console.log(key + " has been " + action);
});
```

Listens for updates for selected key. NB! even updates made in other windows/tabs are reflected, so this feature can also be used for some kind of publish/subscribe service.

If you want to listen for any key change, use `"*"` as the key name

```
$.jStorage.listenKeyChange("*", function(key, action){
    console.log(key + " has been " + action);
});
```

### stopListening(key\[, callback\])

[](#stoplisteningkey-callback)

```
$.jStorage.stopListening("mykey"); // cancel all listeners for "mykey" change
```

Stops listening for key change. If callback is set, only the used callback will be cleared, otherwise all listeners will be dropped.

Donate
------

[](#donate)

Support jStorage development

[![Donate to author](https://camo.githubusercontent.com/7b6de155df30b37b25eb5fec52f9213680c3dbf067dfb7d7e2850ac4096c7d05/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f534d2e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DB26KWR2BQX5W)

Features
--------

[](#features)

jStorage supports the following features:

- store and retrieve data from browser storage using any JSON compatible data format (+ native XML nodes)
- set TTL values to stored keys for auto expiring
- publish and subscribe to cross-window/tab events
- listen for key changes (update, delete) from the current or any other browser window
- use any browser since IE6, both in desktop and in mobile

Browser support
---------------

[](#browser-support)

Current availability: jStorage supports all major browsers - Internet Explorer 6+, Firefox 2+, Safari 4+, Chrome 4+, Opera 10.50+

If the browser doesn't support data caching, then no exceptions are raised - jStorage can still be used by the script but nothing is actually stored.

Tests
-----

[](#tests)

See [tests/index.html](http://www.jstorage.info/static/tests/index.html) for unit tests

Docs
----

[](#docs)

Project homepage and docs: [www.jstorage.info](http://www.jstorage.info)

License
-------

[](#license)

[Unlicense](http://unlicense.org/) Since version 0.4.7

**MIT** (versions up to 0.4.6)

[![Bitdeli Badge](https://camo.githubusercontent.com/d6ec396b17b78cc159f848dcb7f5bd55b11a2cfc31badc555507deed85de3085/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f616e64726973392f6a73746f726167652f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/49f8c400b0768dacb071aca3ca234b111e3feba19574ed608d3a96114054f120?d=identicon)[ingenious](/maintainers/ingenious)

---

Top Contributors

[![andris9](https://avatars.githubusercontent.com/u/132242?v=4)](https://github.com/andris9 "andris9 (74 commits)")[![unera](https://avatars.githubusercontent.com/u/538980?v=4)](https://github.com/unera "unera (5 commits)")[![aghouseh](https://avatars.githubusercontent.com/u/967344?v=4)](https://github.com/aghouseh "aghouseh (3 commits)")[![naterkane](https://avatars.githubusercontent.com/u/21930?v=4)](https://github.com/naterkane "naterkane (2 commits)")[![Altaflux](https://avatars.githubusercontent.com/u/4032486?v=4)](https://github.com/Altaflux "Altaflux (2 commits)")[![mattflaschen](https://avatars.githubusercontent.com/u/505874?v=4)](https://github.com/mattflaschen "mattflaschen (2 commits)")[![niyazpk](https://avatars.githubusercontent.com/u/307424?v=4)](https://github.com/niyazpk "niyazpk (2 commits)")[![mente](https://avatars.githubusercontent.com/u/391997?v=4)](https://github.com/mente "mente (1 commits)")[![msb-jeremy](https://avatars.githubusercontent.com/u/18389776?v=4)](https://github.com/msb-jeremy "msb-jeremy (1 commits)")[![punkstar](https://avatars.githubusercontent.com/u/179072?v=4)](https://github.com/punkstar "punkstar (1 commits)")[![pwmckenna](https://avatars.githubusercontent.com/u/295678?v=4)](https://github.com/pwmckenna "pwmckenna (1 commits)")[![simonwjackson](https://avatars.githubusercontent.com/u/189379?v=4)](https://github.com/simonwjackson "simonwjackson (1 commits)")[![stopdropandrew](https://avatars.githubusercontent.com/u/6681?v=4)](https://github.com/stopdropandrew "stopdropandrew (1 commits)")[![yulanggong](https://avatars.githubusercontent.com/u/951769?v=4)](https://github.com/yulanggong "yulanggong (1 commits)")[![alexogar](https://avatars.githubusercontent.com/u/1502209?v=4)](https://github.com/alexogar "alexogar (1 commits)")[![avdg](https://avatars.githubusercontent.com/u/212248?v=4)](https://github.com/avdg "avdg (1 commits)")[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")[![elsigh](https://avatars.githubusercontent.com/u/517210?v=4)](https://github.com/elsigh "elsigh (1 commits)")[![lachezar](https://avatars.githubusercontent.com/u/130336?v=4)](https://github.com/lachezar "lachezar (1 commits)")[![markvantilburg](https://avatars.githubusercontent.com/u/4510245?v=4)](https://github.com/markvantilburg "markvantilburg (1 commits)")

### Embed Badge

![Health badge](/badges/ingenious-jstorage/health.svg)

```
[![Health](https://phpackages.com/badges/ingenious-jstorage/health.svg)](https://phpackages.com/packages/ingenious-jstorage)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
