{"id":21524192,"url":"https://github.com/gxsshallot/react-native-general-storage","last_synced_at":"2025-04-09T23:03:19.762Z","repository":{"id":57337203,"uuid":"146959686","full_name":"gxsshallot/react-native-general-storage","owner":"gxsshallot","description":"The wrapper of AsyncStorage to support multi-level key and key prefix.","archived":false,"fork":false,"pushed_at":"2019-09-24T06:03:36.000Z","size":27,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T10:21:47.347Z","etag":null,"topics":["asyncstorage","multi-level","react-native"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gxsshallot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-01T02:12:05.000Z","updated_at":"2020-08-20T22:02:47.000Z","dependencies_parsed_at":"2022-09-10T02:53:13.101Z","dependency_job_id":null,"html_url":"https://github.com/gxsshallot/react-native-general-storage","commit_stats":null,"previous_names":["gaoxiaosong/react-native-general-storage"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gxsshallot%2Freact-native-general-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gxsshallot%2Freact-native-general-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gxsshallot%2Freact-native-general-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gxsshallot%2Freact-native-general-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gxsshallot","download_url":"https://codeload.github.com/gxsshallot/react-native-general-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226114525,"owners_count":17575650,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncstorage","multi-level","react-native"],"created_at":"2024-11-24T01:21:27.484Z","updated_at":"2024-11-24T01:21:27.986Z","avatar_url":"https://github.com/gxsshallot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-general-storage\n\n[![npm version](https://img.shields.io/npm/v/react-native-general-storage.svg?style=flat)](https://www.npmjs.com/package/react-native-general-storage)\n[![Build Status](https://travis-ci.org/gaoxiaosong/react-native-general-storage.svg?branch=master)](https://travis-ci.org/gaoxiaosong/react-native-general-storage)\n\n[中文说明](https://www.jianshu.com/p/43c2f39992b4)\n\nIt is the wrapper of `AsyncStorage` to support multi-level key and key prefix.\n\n## Install\n\nInstall by Yarn:\n\n```shell\nyarn add react-native-general-storage\n```\n\nInstall by NPM:\n\n```shell\nnpm install --save react-native-general-storage\n```\n## note\n\n  `import {AsyncStorage} from 'react-native'` will deprecated in RN Higher version. it move to [react-native-community/async-storage](https://github.com/react-native-community/async-storage)\n  \n   install dependencies see `react-native-community/async-storage` detail\n   \n\n## Usage\n\nImport the module in the file:\n\n```javascript\nimport AsyncStorage from 'react-native-general-storage';\n```\n\n### Keys Structure\n\nYou can use an array of string as a key. Or a string is also valid, and will be converted to an array.\n\nThe array of string means the levels of key, such as:\n\n```javascript\nkey1 = ['App', 'UserInfo'];\nkey2 = ['App', 'UserSetting'];\n```\n\n### Prefix\n\nYou can set the common prefix to added into key automatically. In application, we usually used two prefix:\n\n```javascript\nconst commonPart = '__common__';\nconst userPart = '__user__';\n\n// When app start, we set the common prefix\nAsyncStorage.setPrefix(commonPart, commonPart);\n\n// When user login, we set user prefix as default prefix\nconst userId = '12345';\nAsyncStorage.setPrefix(userPart, userId, true);\n\n// When user logout, we unset user prefix and remove default prefix\nAsyncStorage.setPrefix(userPart, null);\n```\n\n`setPrefix` function has three parameters:\n\n* key: Key prefix used as identifier when you call interface.\n* value: Prefix value used in the storage key. If it is null or undefined, the prefix will be deleted.\n* isDefault: Set as default key, only valid when value is not null or undefined.\n\n### Seperator\n\nDefault seperator used in storage key. The default value is `'$'`. You can modify it globally:\n\n```javascript\nAsyncStorage.defaultSeperator = '#';\n```\n\n### Storage Key\n\nThe key stored in React Native `AsyncStorage` is composed by prefix, keys and seperator:\n\n```javascript\nstorageKey = [...prefix, ...keys].join(seperator);\n```\n\n### Interface\n\n* set: `(keys, content, prefix) =\u003e Promise\u003cvoid\u003e`\n* get: `(keys, prefix) =\u003e Promise\u003cobject\u003e`\n* remove: `(keys, prefix) =\u003e Promise\u003cvoid\u003e`\n* merge: `(keys, content, prefix) =\u003e Promise\u003cvoid\u003e`\n* clear: `(keys, prefix) =\u003e Promise\u003cvoid\u003e`\n* getKeys: `(keys, prefix) =\u003e Promise\u003c{string: object}\u003e`\n* multiGet: `(keys, prefix) =\u003e Promise\u003cobject[]\u003e`\n* multiSet: `(keys, values, prefix) =\u003e Promise\u003cvoid\u003e`\n* multiRemove: `(keys, prefix) =\u003e Promise\u003cvoid\u003e`\n\nParameters:\n\n* `keys` is a string or an array of string, you can see `Keys Structure`.\n* `prefix` is prefix key. Use default prefix if it is undefined.\n* `content` is an object, an array, a string or a number.\n\n**clear** and **getKeys**:\n\nThey are manipulate a set of keys, which has same prefix.\n\nIf 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.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgxsshallot%2Freact-native-general-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgxsshallot%2Freact-native-general-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgxsshallot%2Freact-native-general-storage/lists"}