https://github.com/tiaanduplessis/react-native-modest-storage
💾 A modest wrapper around the AsyncStorage API
https://github.com/tiaanduplessis/react-native-modest-storage
asyncstorage asyncstorage-wrapper modest react-native
Last synced: 10 months ago
JSON representation
💾 A modest wrapper around the AsyncStorage API
- Host: GitHub
- URL: https://github.com/tiaanduplessis/react-native-modest-storage
- Owner: tiaanduplessis
- License: mit
- Created: 2017-02-28T13:21:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T05:58:11.000Z (over 3 years ago)
- Last Synced: 2025-05-24T20:16:21.685Z (about 1 year ago)
- Topics: asyncstorage, asyncstorage-wrapper, modest, react-native
- Language: JavaScript
- Size: 1.84 MB
- Stars: 22
- Watchers: 1
- Forks: 5
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 💾 react-native-modest-storage 💾
[](https://npmjs.org/package/react-native-modest-storage)
[](https://npmjs.org/package/react-native-modest-storage)
[](https://github.com/RichardLitt/standard-readme)
[](https://npmjs.org/package/react-native-modest-storage)
[](http://makeapullrequest.com)
> A modest wrapper around the AsyncStorage API
## Table of Contents
- [About](#about)
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [Contribute](#contribute)
- [License](#License)
## About
This module is just a modest wrapper around [React Native](https://facebook.github.io/react-native/)'s [AsyncStorage](https://facebook.github.io/react-native/docs/asyncstorage.html) API. It's purpose is to provide a cleaner API for persisting data.
## Install
This project uses [node](https://nodejs.org) and [npm](https://www.npmjs.com).
```sh
$ npm install react-native-modest-storage
$ # OR
$ yarn add react-native-modest-storage
```
## Usage
```js
import storage from 'react-native-modest-storage'
async function doStuff() {
await storage.set('aKey', { Hello: 'World'})
await storage.set('otherKey', 5)
await storage.get('aKey').then(console.log) // {Hello: "World"}
await storage.keys().then(console.log) // ['otherKey', 'aKey']
await storage.update('aKey', {Hello: 'is it me your looking for.'})
await storage.get('aKey').then(console.log) // {Hello: "is it me your looking for."}
await storage.remove('otherKey')
await storage.get('otherKey').then(console.log) // null
await storage.set([['key1', {foo: 'bar'}], ['key2', 'baz'], ['test', {obj: 9}]])
await storage.get('key1').then(console.log) // {foo: "bar"}
await storage.get('test').then(console.log)
await storage.clear()
}
doStuff()
```
## API
#### Table of Contents
- [get](#get)
- [Parameters](#parameters)
- [Examples](#examples)
- [set](#set)
- [Parameters](#parameters-1)
- [update](#update)
- [Parameters](#parameters-2)
- [remove](#remove)
- [Parameters](#parameters-3)
- [Examples](#examples-1)
- [clear](#clear)
- [keys](#keys)
### get
Retreive value from AsyncStorage based on key.
Wrapper around getItem & multiGet.
#### Parameters
- `key`
- `def` **Any** Default value
#### Examples
```javascript
storage.get('foo').then(console.log).catch(console.error)
```
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** value of key
### set
Persist a value to AsyncStorage.
Wrapper around setItem & multiSet.
#### Parameters
- `key`
- `value` **Any** to persist
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
### update
Update key with value by merging.
Wrapper around mergeItem & multiMerge.
#### Parameters
- `key`
- `value` **any** to update
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
### remove
Remove a key from AsyncStorage.
Wrapper around removeItem & multiRemove.
#### Parameters
- `key`
#### Examples
```javascript
storage.remove(key).then(console.log).catch(console.error)
```
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
### clear
Erase all AsyncStorage data.
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
### keys
Retreive all the keys stored in AsyncStorage of application.
Wrapper around getAllKeys
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
## Contribute
1. Fork it and create your feature branch: git checkout -b my-new-feature
2. Commit your changes: git commit -am 'Add some feature'
3. Push to the branch: git push origin my-new-feature
4. Submit a pull request
## License
MIT