npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

async-storage-adapter

v1.0.4

Published

Utility wrapper builded on top of @react-native-async-storage/async-storage to interact with AsyncStorage in React Native projects.

Downloads

5

Readme

Async Storage Adapter

npm version GitHub license Maintenance

Utility wrapper builded on top of @react-native-async-storage/async-storage to interact with AsyncStorage in React Native projects.

New version of async storage adapter library. Check on npm and github.

🎉 Version 1.0.x is live 🎉

Check out for changes in the CHANGELOG:

Changelog

Supporting the project

Maintaining a project takes time. To help allocate time, you can Buy Me a Coffee 😉

Contents

  1. Install;
  2. Get Started;
  3. Functions;
  4. Examples;

Install

Inside your project run on terminal:

npm install async-storage-adapter --save

or

yarn add async-storage-adapter

Then link the package on React Native 0.60+:

npx pod-install

Instead on React Native <= 0.59:

react-native link @react-native-async-storage/async-storage

The only one dependency that will be installed is @react-native-async-storage/async-storage.

Get Started

Import the package on your project file. First of all you need to declare a global key name to store your data.

/**
 * Class constructor accept one single required parameter, the `GlobalKeyName`.
 */

// CommonJS Module
const AsyncStorageAdapter = require("async-storage-adapter");

const { getData } = new AsyncStorageAdapter("@MyAppName");

// ES6 Module
import AsyncStorageAdapter from "async-storage-adapter";

const { getData } = new AsyncStorageAdapter("@MyAppName");

Functions

Following the list of all avaiable functions. All functions return a <Promise> so need to be called inside async/await block:

| Name | Parameters | Description | Return | |--------------------|:-------------------------------|:--------------------------------------------------------------------------------|:------------------:| | clearAll | -- | Clear all data from async storage. | success<Boolean> | | getAllData | -- | Get all data from async storage. | data<Object> | | getAllKeys | -- | Get array of all keys from async storage. | keys<Array> | | getData | key<String> | Get single key data from async storage. | data<Any> | | getMultipleData | key<Array<String>> | Get multiple keys data from async storage. | data<Object> | | removeData | key<String> | Remove single key data from async storage. | success<Boolean> | | removeMultipleData | key<Array<String>> | Remove multiple keys data from async storage. | success<Boolean> | | storeData | key<String>, value<Object> | Store single { key: value } object. | success<Boolean> | | storeMultipleData | datas<Object<Any>> | Take an object with multiple { key: value } pairing to save in async storage. | success<Boolean> |

Examples Usage

Following an example with all functions using ES6 Module syntax:

import AsyncStorageAdapter from "async-storage-adapter";

// Declare functions from `AsyncStorageAdapter`;
// Using `@MyAppName` as GlobalKeyName parameter.
const {
  clearAll,
  getAllData,
  getAllKeys,
  getData,
  getMultipleData,
  removeData,
  removeMultipleData,
  storeData,
  storeMultipleData
} = new AsyncStorageAdapter("@MyAppName");

/**
 * !IMPORTANT All functions return a `<Promise>` so need to be called inside `async/await` block
 */

// Clear all data in AsyncStorage
(async () => {
  try {
    // No need to pass parameters
    const isClear = await clearAll(); // Return Boolean value
  } catch (err) {
    throw err;
  }
})();

// Retrieve all data in AsyncStorage
(async () => {
  try {
    // No need to pass parameters
    const keys = await getAllData(); // Object with all data stored
  } catch (err) {
    throw err;
  }
})();

// Retrieve all keys in AsyncStorage
(async () => {
  try {
    // No need to pass parameters
    const datas = await getAllKeys(); // Array with all keys stored
  } catch (err) {
    throw err;
  }
})();

// Retrieve single key data in AsyncStorage
(async () => {
  try {
    // Pass `key` name as string
    const data = await getData("MY_KEY_NAME"); // Any data stored with specified key
  } catch (err) {
    throw err;
  }
})();

// Retrieve multiple keys data in AsyncStorage
(async () => {
  try {
    // Pass `keys` array with names as strings
    const datas = await getMultipleData(["MY_KEY_NAME_1", "MY_KEY_NAME_2", "..."]); // Any data stored with specified keys
  } catch (err) {
    throw err;
  }
})();

// Delete single key data in AsyncStorage
(async () => {
  try {
    // Pass `key` name as string
    const isDeleted = await removeData("MY_KEY_NAME"); // Return Boolean value
  } catch (err) {
    throw err;
  }
})();

// Delete multiple keys data in AsyncStorage
(async () => {
  try {
    // Pass `keys` array with names as strings
    const isDeleted = await removeMultipleData(["MY_KEY_NAME_1", "MY_KEY_NAME_2", "..."]); // Return Boolean value
  } catch (err) {
    throw err;
  }
})();

// Store single key data in AsyncStorage
(async () => {
  try {
    // Pass `key` name as string
    // Pass `value` as `<Any>` type, e.g. an `<Object>` like `{ key: value }`
    const isStored = await storeData("MY_KEY_NAME", { key: value }); // Return Boolean value
  } catch (err) {
    throw err;
  }
})();

// Store multiple keys data in AsyncStorage
(async () => {
  try {
    // Pass `object` value like `{ key: value }`. `key` will be the saved `key` name and `value` the saved `value`
    const isStored = await storeMultipleData({ key: value }); // Return Boolean value
  } catch (err) {
    throw err;
  }
})();