Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/linusu/fanny-pack
🗄 Fanny Pack is a non-fancy, but very practical, key/value-store
https://github.com/linusu/fanny-pack
Last synced: 12 days ago
JSON representation
🗄 Fanny Pack is a non-fancy, but very practical, key/value-store
- Host: GitHub
- URL: https://github.com/linusu/fanny-pack
- Owner: LinusU
- Created: 2018-07-11T09:15:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-20T14:06:26.000Z (about 6 years ago)
- Last Synced: 2024-10-23T08:26:30.360Z (21 days ago)
- Language: TypeScript
- Size: 62.5 KB
- Stars: 106
- Watchers: 5
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Fanny Pack
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## Platforms
- [`@fanny-pack/browser`](https://github.com/LinusU/fanny-pack/tree/master/packages/browser)
- [`@fanny-pack/browser-extension`](https://github.com/LinusU/fanny-pack/tree/master/packages/browser-extension)
- [`@fanny-pack/memory`](https://github.com/LinusU/fanny-pack/tree/master/packages/memory)
- [`@fanny-pack/node`](https://github.com/LinusU/fanny-pack/tree/master/packages/node)
- [`@fanny-pack/react-native`](https://github.com/LinusU/fanny-pack/tree/master/packages/react-native)## Usage
```js
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'))
//=> trueconsole.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'
```## API
### `.clear(): Promise`
Remove all entries from the Fanny Pack.
### `.delete(key: string): Promise`
Remove a specific entry. If no entry with the given key exists, then this is a no-op.
### `.get(key: string): Promise`
Return the value of a specific entry. If no entry with the given key exists, `undefined` will be returned.
### `.has (key: string): Promise`
Check wether or not an entry with the given key exists.
### `.set (key: string, value: JSONValue): Promise`
Add or update a specific entry.
### `KeyRange`
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.
### `.keys(range?: KeyRange): AsyncIterableIterator`
Returns an asynchrounous iterator over the keys in the Fanny Pack. Specify a `range` to limit which entries to include.
### `.values(range?: KeyRange): AsyncIterableIterator`
Returns an asynchrounous iterator over the values in the Fanny Pack. Specify a `range` to limit which entries to include.
### `.entries(range?: KeyRange): AsyncIterableIterator<[string, JSONValue]>`
Returns an asynchrounous iterator over the entries in the Fanny Pack. Specify a `range` to limit which entries to include.
## Accepting Fanny Packs
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.