ray-rn-storage v1.0.1
ray-rn-storage
author
ilex.h
dependencies:
- "react-native": "^0.48.1"
useage
import Store from 'ray-rn-storage';
// normal
Store.getItem('token').then(value => value);
// async/await
async function getAuthData(){
const token = await Store.getItem('token');
return token;
}
apis
name | params | return | description |
---|---|---|---|
getItem | (key: string, cb?: Callback ) | Promise | 根据key获取数据 |
setItem | (key: string, value: string, cb?: Callback ) | Promise | 设置key-value |
removeItem | (key: string, cb?: Callback ) | Promise | 移除数据 |
getAllKeys | (cb?: Callback ) | Promise | 获取所有的key |
clear | - | Promise | 清除所有 |
multiGet | (keys: Array<string> ) | Promise<Array<[string, ?string]>> | 获取多个数据 |
mergeItem | (key: string ) | Promise | 合并建数据 |
flushGetRequests | - | void | -- |
multiSet | (kvPairs: Array<[string, string]> ) | Promise | 批量设置 |
multiRemove | (keys: Array<string> ) | Promise | 批量删除 |
multiMerge | (kvPairs: Array<[string, string]> ) | Promise | 批量合并 |
rstore
a wrapper around RN's AsyncStorage
use
import RStore from 'ray-rn-storage/lib/rstore';
RStore.get('token').then(v => v);
RStore.get(['token', 'apikey']).then(v => v);
...
apis
- get(key)
Get a one or more value for a key or array of keys from AsyncStorage
Parameters
key: String | Array
, A key or array of keys
Returns: Promise
- save(key, value)
Save a key value pair or a series of key value pairs to AsyncStorage.
Parameters
key: String | Array
, The key or an array of key/value pairs
value: Any
, The value to save
Returns: Promise
- update(key, value)
Updates the value in the store for a given key in AsyncStorage. If the value is a string it will be replaced. If the value is an object it will be deep merged.
Parameters
key: String
, The key
value: Value
, The value to update with
Returns: Promise
- delete(key)
Delete the value for a given key in AsyncStorage.
Parameters
key: String | Array
, The key or an array of keys to be deleted
Returns: Promise
- keys()
Get all keys in AsyncStorage.
Returns: Promise
, A promise which when it resolves gets passed the saved keys in AsyncStorage.
- push(key, value)
Push a value onto an array stored in AsyncStorage by key or create a new array in AsyncStorage for a key if it's not yet defined.
Parameters
key: String
, They key
value: Any
, The value to push onto the array
Returns: Promise
License
MIT