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

react-native-general-storage

v1.0.5

Published

The wrapper of AsyncStorage to support multi-level key and key prefix.

Downloads

9

Readme

react-native-general-storage

npm version Build Status

中文说明

It is the wrapper of AsyncStorage to support multi-level key and key prefix.

Install

Install by Yarn:

yarn add react-native-general-storage

Install by NPM:

npm install --save react-native-general-storage

note

import {AsyncStorage} from 'react-native' will deprecated in RN Higher version. it move to react-native-community/async-storage

install dependencies see react-native-community/async-storage detail

Usage

Import the module in the file:

import AsyncStorage from 'react-native-general-storage';

Keys Structure

You can use an array of string as a key. Or a string is also valid, and will be converted to an array.

The array of string means the levels of key, such as:

key1 = ['App', 'UserInfo'];
key2 = ['App', 'UserSetting'];

Prefix

You can set the common prefix to added into key automatically. In application, we usually used two prefix:

const commonPart = '__common__';
const userPart = '__user__';

// When app start, we set the common prefix
AsyncStorage.setPrefix(commonPart, commonPart);

// When user login, we set user prefix as default prefix
const userId = '12345';
AsyncStorage.setPrefix(userPart, userId, true);

// When user logout, we unset user prefix and remove default prefix
AsyncStorage.setPrefix(userPart, null);

setPrefix function has three parameters:

  • key: Key prefix used as identifier when you call interface.
  • value: Prefix value used in the storage key. If it is null or undefined, the prefix will be deleted.
  • isDefault: Set as default key, only valid when value is not null or undefined.

Seperator

Default seperator used in storage key. The default value is '$'. You can modify it globally:

AsyncStorage.defaultSeperator = '#';

Storage Key

The key stored in React Native AsyncStorage is composed by prefix, keys and seperator:

storageKey = [...prefix, ...keys].join(seperator);

Interface

  • set: (keys, content, prefix) => Promise<void>
  • get: (keys, prefix) => Promise<object>
  • remove: (keys, prefix) => Promise<void>
  • merge: (keys, content, prefix) => Promise<void>
  • clear: (keys, prefix) => Promise<void>
  • getKeys: (keys, prefix) => Promise<{string: object}>
  • multiGet: (keys, prefix) => Promise<object[]>
  • multiSet: (keys, values, prefix) => Promise<void>
  • multiRemove: (keys, prefix) => Promise<void>

Parameters:

  • keys is a string or an array of string, you can see Keys Structure.
  • prefix is prefix key. Use default prefix if it is undefined.
  • content is an object, an array, a string or a number.

clear and getKeys:

They are manipulate a set of keys, which has same prefix.

If one key is ['App', 'UserInfo'] and another is ['App', 'UserSetting'], and both is 'userPart' prefix. When clear(['App'], userPart), they will be clear. Or getKeys(['App'], userPart), they will be returned in promise.