Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-storage

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-storage - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

6

__tests__/basic-function-test.js

@@ -8,3 +8,4 @@ jest.dontMock('../storage.js');

size: SIZE,
defaultExpires: DEFAULTEXPIRES
defaultExpires: DEFAULTEXPIRES,
storageBackend: window.localStorage
});

@@ -14,4 +15,3 @@ let asyncStorage = new Storage({

defaultExpires: DEFAULTEXPIRES,
storageBackend: window.asyncStorage,
isPromise: true
storageBackend: window.asyncStorage
});

@@ -18,0 +18,0 @@ let stores = { localStorage, asyncStorage };

@@ -8,6 +8,7 @@ /**

let storage = new Storage();
let localStorage = new Storage();
let localStorage = new Storage({
storageBackend: window.localStorage
});
let asyncStorage = new Storage({
storageBackend: window.asyncStorage,
isPromise: true
storageBackend: window.asyncStorage
});

@@ -14,0 +15,0 @@ let stores = { localStorage, asyncStorage };

{
"name": "react-native-storage",
"version": "0.1.2",
"version": "0.1.3",
"description": "A local storage wrapper for both react-native(AsyncStorage) and browser(localStorage). Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.",

@@ -5,0 +5,0 @@ "main": "storage.js",

@@ -19,5 +19,2 @@ # react-native-storage [![Build Status](https://travis-ci.org/sunnylqm/react-native-storage.svg)](https://travis-ci.org/sunnylqm/react-native-storage) [![npm version](https://badge.fury.io/js/react-native-storage.svg)](http://badge.fury.io/js/react-native-storage)

// ...
externals: {
"react-native": {} // 这一行是必须的!否则会报错。
},
module: {

@@ -58,7 +55,14 @@ loaders: [

```javascript
import { AsyncStorage } from 'react-native';
var storage = new Storage({
// 最大容量,默认值1000条数据循环存储
size: 1000,
size: 1000,
// 存储引擎:对于RN使用AsyncStorage,对于web使用window.localStorage
// 如果不指定则数据只会保存在内存中,重启后即丢失
storageBackend: AsyncStorage,
// 数据过期时间,默认一整天(1000 * 3600 * 24秒),设为null则永不过期
// 数据过期时间,默认一整天(1000 * 3600 * 24 毫秒),设为null则永不过期
defaultExpires: 1000 * 3600 * 24,

@@ -71,3 +75,3 @@

// 则会调用相应的sync同步方法,无缝返回最新数据。
sync : {
sync: {
// 同步方法的具体说明会在后文提到

@@ -152,3 +156,3 @@ }

storage.load({
key: 'user'
key: 'user',
id: '1001'

@@ -186,3 +190,3 @@ }).then(ret => {

storage.remove({
key: 'user'
key: 'user',
id: '1001'

@@ -272,2 +276,5 @@ });

#### 0.1.3
1. 现在需要在初始化时指定存储引擎(AsyncStorage或window.localStorage),否则数据不会持久保存。
#### 0.1.2

@@ -274,0 +281,0 @@ 1. 现在load方法找不到数据时,会正确抛出Error对象而非undefined。

@@ -20,5 +20,2 @@ # react-native-storage [![Build Status](https://travis-ci.org/sunnylqm/react-native-storage.svg)](https://travis-ci.org/sunnylqm/react-native-storage) [![npm version](https://badge.fury.io/js/react-native-storage.svg)](http://badge.fury.io/js/react-native-storage)

// ...
externals: {
"react-native": {} // This line is required! Otherwise an error would be thrown.
},
module: {

@@ -61,5 +58,11 @@ loaders: [

```js
import { AsyncStorage } from 'react-native';
var storage = new Storage({
// maximum capacity, default 1000
size: 1000,
size: 1000,
// Use AsyncStorage for RN, or window.localStorage for web.
// If not set, data would be lost after reload.
storageBackend: AsyncStorage,

@@ -95,3 +98,3 @@ // expire time, default 1 day(1000 * 3600 * 24 milliseconds).

// Something more unique, and constantly being used.
// They are perminently stored unless you remove.
// They are permanently stored unless you remove.
storage.save({

@@ -190,3 +193,3 @@ key: 'loginState', // Note: Do not use underscore("_") in key!

storage.remove({
key: 'user'
key: 'user',
id: '1001'

@@ -284,2 +287,5 @@ });

#### 0.1.3
1. Now you need to specify storageBackend(AsyncStorage or window.localStorage), otherwise the data would not be persisted.
#### 0.1.2

@@ -286,0 +292,0 @@ 1. Now when load() failed to find data, it will throw an Error with message instead of undefined.

/*
* local storage(web/react native) wrapper
* sunnylqm 2016-06-28
* version 0.1.2
* sunnylqm 2016-08-19
* version 0.1.3
*/

@@ -17,24 +17,18 @@

me._s = options.storageBackend || null;
me.isPromise = options.isPromise || true;
me._innerVersion = 11;
me.cache = {};
if(!me._s) {
if(typeof window !== 'undefined' && window.localStorage) {
try {
// avoid key conflict
window.localStorage.setItem('__react_native_storage_test', 'test');
me._s = window.localStorage;
me.isPromise = false;
}
catch(e) {
console.warn(e);
delete me._s;
throw e;
}
if (me._s && me._s.setItem) {
try {
var promiseTest = me._s.setItem('__react_native_storage_test', 'test');
me.isPromise = (promiseTest && promiseTest.then) ? true : false;
}
else {
me._s = require('react-native').AsyncStorage;
catch (e) {
console.warn(e);
delete me._s;
throw e;
}
} else {
console.warn(`Data would be lost after reload cause there is no storageBackend specified!
\nEither use localStorage(for web) or AsyncStorage(for React Native) as a storageBackend.`)
}

@@ -41,0 +35,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc