1.0.1 • Published 1 year ago

ray-rn-storage v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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

nameparamsreturndescription
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

1.0.1

1 year ago

1.0.0

1 year ago