Denis 346b78aee1 first commit пре 2 година
..
dist 346b78aee1 first commit пре 2 година
examples 346b78aee1 first commit пре 2 година
lib 346b78aee1 first commit пре 2 година
typing-tests 346b78aee1 first commit пре 2 година
typings 346b78aee1 first commit пре 2 година
.babelrc 346b78aee1 first commit пре 2 година
.eslintrc 346b78aee1 first commit пре 2 година
.jscsrc 346b78aee1 first commit пре 2 година
.jshintrc 346b78aee1 first commit пре 2 година
.npmignore 346b78aee1 first commit пре 2 година
.travis.yml 346b78aee1 first commit пре 2 година
LICENSE 346b78aee1 first commit пре 2 година
README.md 346b78aee1 first commit пре 2 година
bower.json 346b78aee1 first commit пре 2 година
package.json 346b78aee1 first commit пре 2 година
rollup.config.es6.js 346b78aee1 first commit пре 2 година
rollup.config.js 346b78aee1 first commit пре 2 година
rollup.config.test.js 346b78aee1 first commit пре 2 година
rollup.config.umd.js 346b78aee1 first commit пре 2 година

README.md

localForage-setItems

npm
Adds setItems method to localForage.

Requirements

  • 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 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.

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

API

You can pass an array with the key-value pairs:

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:

var items = {
  asdf: 'asdf value!',
  asap: 'asap value!',
  async: 'async value!'
};
localforage.setItems(items);