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-fast-secure-storage

v1.2.0

Published

fast and secure storage for iOS and Android

Downloads

186

Readme

react-native-fast-secure-storage

react-native-fast-secure-storage is a fast, secure, and extensible key-value storage solution for React Native applications. This library provides a simple API to securely store sensitive data, leveraging the best practices for data encryption and performance.

Features

  • Fast and efficient key-value storage
  • Secure data encryption
  • Simple asynchronous API
  • Cross-platform support (iOS and Android)
  • Supports both strings and binary data

Installation

npm install react-native-fast-secure-storage

or

yarn add react-native-fast-secure-storage

API

Methods

setItem

Stores an item in the secure storage.

  • key: The key of the item.
  • value: The value of the item.
  • accessible: (Optional) The accessibility level of the item. Default is ACCESSIBLE.WHEN_UNLOCKED.
import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage";

const result = await SecureStorage.setItem("key1", "value1", ACCESSIBLE.WHEN_UNLOCKED)

getItem

Retrieves an item from the secure storage.

  • key: The key of the item to retrieve.
import SecureStorage from "react-native-fast-secure-storage";

const result = await SecureStorage.getItem("key1")

console.log(result); // output: value1

This method throws an error if there is no stored value for this key or the value is empty.

clearStorage

Clears all items from the secure storage.

import SecureStorage from "react-native-fast-secure-storage";

await SecureStorage.clearStorage()

setItems

Stores multiple items in the secure storage.

  • items: An array of items to set.
import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage";
const testItems = [
    {
        key: "key1",
        value: "value1",
        accessibleValue: ACCESSIBLE.WHEN_UNLOCKED
    },
    {
        key: "key2",
        value: "value2",
        accessibleValue: ACCESSIBLE.WHEN_UNLOCKED
    },
];

await SecureStorage.setItems(testItems);

getAllKeys

Retrieves all keys from the secure storage.

import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage";
const testItems = [
    {
        key: "key1",
        value: "value1",
        accessibleValue: ACCESSIBLE.WHEN_UNLOCKED
    },
    {
        key: "key2",
        value: "value2",
        accessibleValue: ACCESSIBLE.WHEN_UNLOCKED
    },
];

await SecureStorage.setItems(testItems);

const keys = SecureStorage.getAllKeys();

console.log(keys); // output: ["ke1", "key2"]

getAllItems

Retrieves all items from the secure storage.

import SecureStorage, { ACCESSIBLE } from "react-native-fast-secure-storage";
const testItems = [
    {
        key: "key1",
        value: "value1",
        accessibleValue: ACCESSIBLE.WHEN_UNLOCKED
    },
    {
        key: "key2",
        value: "value2",
        accessibleValue: ACCESSIBLE.WHEN_UNLOCKED
    },
];

await SecureStorage.setItems(testItems);

const secureStorageItems = SecureStorage.getAllKeys();

console.log(secureStorageItems); // output: [{ key: "key1", value: "value1" }, {key: "key2", value: "value2" }]

removeItem

Removes an item from the secure storage.

  • key: The key of the item to remove.
import SecureStorage from "react-native-fast-secure-storage";

await SecureStorage.setItem("key1", "value1");

await SecureStorage.deleteItem("key1");

try { 
  await SecureStorage.getItem("key1")
} cath(e) {
  console.log(e) // output: value does not exist
}

hasItem

  • key: The key of the item to check.
import SecureStorage from "react-native-fast-secure-storage";

await SecureStorage.setItem("key1", "value1");

const result = await SecureStorage.hasItem("key1");

console.log(result) // output: true

Synchronous Methods

getItemSync

Synchronously retrieves an item from the secure storage.

  • key: The key of the item to retrieve.
import SecureStorage from 'react-native-fast-secure-storage';

const value = secureStorage.getItemSync('key1');
console.log(value); // Output: 'value1'

setItemSync

Stores an item in the secure storage synchronously.

  • key: The key of the item.
  • value: The value of the item.
  • accessible: (Optional) The accessibility level of the item. Default is ACCESSIBLE.WHEN_UNLOCKED.

const setResult = secureStorage.setItemSync('key1', 'value1');
console.log(setResult); // Output: true

hasItemSync

Checks if an item exists in the secure storage synchronously.

  • key: The key of the item to check.

const setResult = secureStorage.setItemSync('key1', 'value1');
const exists = secureStorage.hasItemSync('key1');
console.log(exists); // Output: true

removeItemSync

Removes an item from the secure storage synchronously.

  • key: The key of the item to remove.

const setResult = secureStorage.setItemSync('key1', 'value1');

const removeResult = secureStorage.removeItemSync('key1');

Testing

This library includes a built in mock for Jest. To use it, add the following code to the jest setup file:

jest.mock('react-native-fast-secure-storage', () => require("react-native-fast-secure-storage/jest"));

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

react-native-fast-secure-storage