-> externally, we are using the same API as localForage,
with the exception of the dropInstance interface, which, while
still available, has been split out into three distinct calls.
Also, are using .then
instead of the callback approach, and
always catch an error.
Of note are the extensions to the generic interface:
- mergeItem (with a number of merge strategies available)
- getKeyValue
- deleteItemKey
- hasKey
- hasKeyValue
Note: Even if undefined is saved, null will be returned by getItem(). This is due to a limitation in localStorage, and for compatibility reasons localForage cannot store the value undefined.
Usage Options:
- Exactly the same interface as localForage
- With a currying function applied to the result
- Modify the value returned (with or without curry)
- Define error suppression
Methods
# static createInstance(name) → {boolean}
This will return the entire object. If you just want to know if it worked, do this:
const driver = !!forage.createInstance({ name: 'Test' })
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
# static createInstance(name) → {boolean}
This will return the entire object. If you just want to know if it worked, do this:
const driver = !!forage.createInstance({ name: 'Test' })
Parameters:
Name | Type | Description |
---|---|---|
name |
string |
# static getItem(key, logger, returner, before, store) → {Promise.<(object|string|*)>}
get the object of a specific row if it exists. @
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
logger |
string | |
returner |
number | |
before |
boolean | |
store |
string |
# static getItem(key, logger, returner, before, store) → {Promise.<(object|string|*)>}
get the object of a specific row if it exists. @
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
logger |
string | |
returner |
number | |
before |
boolean | |
store |
string |
# static getKeyValue(key, value, curry, logger, returner) → {Promise.<(object|string|*)>}
get the value of a specific key in a row if it exists.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
value |
string | |
curry |
function | |
logger |
string | |
returner |
number | string |
# static getKeyValue(key, value, curry, logger, returner) → {Promise.<(object|string|*)>}
get the value of a specific key in a row if it exists.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
value |
string | |
curry |
function | |
logger |
string | |
returner |
number | string |
# static mergeItem(key, value, type, restArgs) → {Promise.<(object|string|*)>}
Merging data shouldn't be hard, so that logic is in here. There are so many ways to do it though, that the caller can define merge strategy. This is a "prebuilt" Curry.
See https://ramdajs.com/docs/ for the exact features we are using.
The default is to use the deepWithKey
approach.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
value |
string | object | array | |
type |
string | |
restArgs |
function | string | number | |
curry |
function | |
logger |
string | |
returner |
number |
# static mergeItem(key, value, type, restArgs) → {Promise.<(object|string|*)>}
Merging data shouldn't be hard, so that logic is in here. There are so many ways to do it though, that the caller can define merge strategy. This is a "prebuilt" Curry.
See https://ramdajs.com/docs/ for the exact features we are using.
The default is to use the deepWithKey
approach.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
value |
string | object | array | |
type |
string | |
restArgs |
function | string | number | |
curry |
function | |
logger |
string | |
returner |
number |
# static setItem(key, value, restArgs) → {Promise.<(object|string|*)>}
set an row if it exists, completely overwrite it if it does not exist.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
value |
string | |
restArgs |
function | string | number | |
curry |
function | |
logger |
string | |
returner |
number |
# static setItem(restArgs) → {Promise.<string>}
Parameters:
Name | Type | Description |
---|---|---|
restArgs |
function | string | number | |
index |
number | |
curry |
function | |
logger |
string | |
returner |
number |
# static setItem(key, value, restArgs) → {Promise.<(object|string|*)>}
set an row if it exists, completely overwrite it if it does not exist.
Parameters:
Name | Type | Description |
---|---|---|
key |
string | |
value |
string | |
restArgs |
function | string | number | |
curry |
function | |
logger |
string | |
returner |
number |
# static setItem(restArgs) → {Promise.<string>}
Parameters:
Name | Type | Description |
---|---|---|
restArgs |
function | string | number | |
index |
number | |
curry |
function | |
logger |
string | |
returner |
number |