https://github.com/localforage/localforage-setitems
Adds setItems method to localForage.
https://github.com/localforage/localforage-setitems
Last synced: 11 months ago
JSON representation
Adds setItems method to localForage.
- Host: GitHub
- URL: https://github.com/localforage/localforage-setitems
- Owner: localForage
- License: other
- Created: 2015-05-14T04:46:28.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2018-11-05T20:59:57.000Z (over 7 years ago)
- Last Synced: 2024-12-08T23:43:41.533Z (over 1 year ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 19
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
localForage-setItems
====================
[](https://www.npmjs.com/package/localforage-setitems)
Adds setItems method to [localForage](https://github.com/mozilla/localForage).
## Requirements
* [localForage](https://github.com/mozilla/localForage) v1.4.0+
* for earlier versions of localforage, please use the v1.1.x releases
## Installation
`npm i localforage-setitems`
## Importing
### TypeScript
[Include `localforage` with an import statement appropriate for your configuration](https://github.com/localForage/localForage/blob/master/README.md#typescript) and import `localforage-setitems` right after it.
Normally, `localforage-setitems` will extend the prototype of `locaforage` to include the `setItems()` method, but unfortunately the typings can't be updated.
As a result you should use the exported `extendPrototype()` method, which returns the provided localforage instance but with inherited typings that also include the `setItems()` method.
```javascript
import localForage from 'localforage';
// OR based on your configuration:
// import * as localForage from 'localforage';
import { extendPrototype } from 'localforage-setitems';
extendPrototype(localforage);
// Keep using localForage as usual.
```
### Known issues with module bundlers
In some ES6 module bundlers `.setItems()` might not automatically be made available to the `localforage` object on import.
In this case, import the provided `extendPrototype()` method and extend `localforage` manually, as shown in the Typescript section.
## jsperf links
* [default driver order (indexedDB prefered)](https://jsperf.com/localforage-setitems-2017/1)
* [websql (not for firefox)](https://jsperf.com/localforage-setitems-websql-2017b/1)
## API
You can pass an array with the key-value pairs:
```js
var items = [
{ key: 'asdf', value: 'asdf value!' },
{ key: 'asap', value: 'asap value!' },
{ key: 'async', value: 'async value!' }
];
localforage.setItems(items);
```
Or you can pass a object with the keys as properties:
```js
var items = {
asdf: 'asdf value!',
asap: 'asap value!',
async: 'async value!'
};
localforage.setItems(items);
```