Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cvan/focalstorage
a Promise-based, localStorage-like wrapper around IndexedDB
https://github.com/cvan/focalstorage
Last synced: 7 days ago
JSON representation
a Promise-based, localStorage-like wrapper around IndexedDB
- Host: GitHub
- URL: https://github.com/cvan/focalstorage
- Owner: cvan
- License: mit
- Created: 2015-06-14T23:57:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-09T12:06:24.000Z (about 8 years ago)
- Last Synced: 2025-01-29T18:02:41.927Z (13 days ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# focalStorage
focalStorage is a Promise-based, localStorage-like wrapper around asynchronous
IndexedDB storage.focalStorage works wherever IndexedDB is supported. localStorage fallback coming soon.
To use focalStorage, just drop a single JavaScript file into your page:
```html
focalStorage.getItem('something', myCallback);
```Download the [latest focalStorage from GitHub](https://github.com/cvan/focalStorage/releases/latest), or install with [npm](https://www.npmjs.org/):
```bash
npm install focalStorage
```focalStorage is compatible with [browserify](http://browserify.org/).
## How to use focalStorage
Because focalStorage uses async storage, it has an async API.
It's otherwise exactly the same as the
[Local Storage API](https://hacks.mozilla.org/2009/06/localstorage/).focalStorage relies on native [ES6 Promises](http://www.promisejs.org/) (polyfilled by Babel, where unsupported).
Don't expect a return value from calls to `focalStorage.getItem()`. Instead,
use Promises:```js
// Synchronous; slower!
var value = JSON.parse(localStorage.getItem('key'));
console.log(value);// Async, fast, and non-blocking!
focalStorage.setItem('key', 'value').then(function (value) {
console.log(value + ' was set!');
}, function (error) {
console.error(error);
});
```### Configuration
You can set database information with the `focalStorage.config` method.
Available options are `driver`, `name`, `version`, and `storeName`.Example:
```js
focalStorage.config({
driver: focalStorage.INDEXEDDB, // Force IndexedDB. Or `focalStorage.INDEXEDDB` for localStorage.
name: 'myApp',
version: 1.0,
storeName: 'keyvaluepairs', // Limit to alphanumeric characters and underscores.
});
```**Note:** you must call `config()` _before_ you interact with your data. This
means calling `config()` before using `getItem()`, `setItem()`, `removeItem()`,
`clear()`, `key()`, `keys()` or `length()`.## Working on focalStorage
You'll need [Node + npm](http://nodejs.org/).
To work on focalStorage, you should start by
[forking it](https://github.com/cvan/focalStorage/fork) and installing its
dependencies. Replace `USERNAME` with your GitHub username and run the
following:```bash
git clone [email protected]:USERNAME/focalStorage.git
cd focalStorage
npm install
```### Building the bundle
Run this command to compile the JavaScript as a standalone module to __`dist/focalStorage.js`__:
npm run build
## Maintainers
Run this command to publish a new tag to GitHub and version to npm:
npm run release
## Licence
This program is free software and is distributed under an
[MIT License](https://github.com/cvan/focalStorage/blob/master/LICENSE).