Fanny Pack is a non-fancy, but very practical, key/value-store.
- β First class support for multiple platforms
- β Very simple, low-level API
- β Easy to get started with
- β Uses promises and async iterators
@fanny-pack/browser
@fanny-pack/browser-extension
@fanny-pack/memory
@fanny-pack/node
@fanny-pack/react-native
const FannyPack = require('@fanny-pack/memory')
const fp = new FannyPack()
/*** Set Values ***/
await fp.set('b', 'World')
await fp.set('a', 'Hello')
await fp.set('c', 'Linus')
/*** Get Values ***/
console.log(await fp.get('c'))
//=> 'Linus'
console.log(await fp.get('d'))
//=> undefined
/*** Check Presence ***/
console.log(await fp.has('c'))
//=> true
console.log(await fp.has('d'))
//=> false
/*** Iterate Content ***/
for await (const key of fp.keys()) {
console.log(key)
}
//=> 'a', 'b', 'c'
for await (const value of fp.values({ lt: 'c' })) {
console.log(value)
}
//=> 'Hello', 'World'
for await (const key of fp.keys({ gt: 'a', lte: 'c' })) {
console.log(key)
}
//=> 'b', 'c'
Remove all entries from the Fanny Pack.
Remove a specific entry. If no entry with the given key exists, then this is a no-op.
Return the value of a specific entry. If no entry with the given key exists, undefined
will be returned.
Check wether or not an entry with the given key exists.
Add or update a specific entry.
An object containing any or none of the following properties:
-
gt
(greater than),gte
(greater than or equal) define the lower bound of the entries to be fetched and will determine the starting point. Only entries where the key is greater than (or equal to) this option will be included in the range. -
lt
(less than),lte
(less than or equal) define the higher bound of the range to be fetched. Only entries where the key is less than (or equal to) this option will be included in the range.
Returns an asynchrounous iterator over the keys in the Fanny Pack. Specify a range
to limit which entries to include.
Returns an asynchrounous iterator over the values in the Fanny Pack. Specify a range
to limit which entries to include.
Returns an asynchrounous iterator over the entries in the Fanny Pack. Specify a range
to limit which entries to include.
If you have a library that needs to store stuff, accepting a Fanny Pack is the perfect way to do it. That way your library can stay platform independent, and your users can store their data in one place.
All Fanny Packs are versioned and released at the same time. To declare what version your library is compatible with, declare a peerDependency
on @fanny-pack/core
. All Fanny Pack implementations depend on that package, and thus any Fanny Pack the user depends on will have to fall in that range.