{"id":4703,"url":"https://github.com/tyshkovskii/typed-async-storage","last_synced_at":"2025-08-04T01:33:07.063Z","repository":{"id":40281736,"uuid":"290073712","full_name":"tyshkovskii/typed-async-storage","owner":"tyshkovskii","description":"Validate your AsyncStorage using PropTypes!","archived":true,"fork":false,"pushed_at":"2024-10-24T05:18:20.000Z","size":249,"stargazers_count":9,"open_issues_count":5,"forks_count":13,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-01T07:43:03.411Z","etag":null,"topics":["asyncstorage","asyncstorage-wrapper","proptype-validators","react","react-native","storage"],"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/tyshkovskii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-25T00:45:29.000Z","updated_at":"2024-10-24T05:20:19.000Z","dependencies_parsed_at":"2024-11-10T03:33:28.654Z","dependency_job_id":"a3aedc15-2c08-4a61-8874-356fe67d9b7a","html_url":"https://github.com/tyshkovskii/typed-async-storage","commit_stats":{"total_commits":49,"total_committers":5,"mean_commits":9.8,"dds":0.326530612244898,"last_synced_commit":"39cb1cbce3a0e169a96a4244113ec2c0ca64a756"},"previous_names":["artxty/typed-async-storage"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyshkovskii%2Ftyped-async-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyshkovskii%2Ftyped-async-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyshkovskii%2Ftyped-async-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyshkovskii%2Ftyped-async-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tyshkovskii","download_url":"https://codeload.github.com/tyshkovskii/typed-async-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228582488,"owners_count":17940587,"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","asyncstorage-wrapper","proptype-validators","react","react-native","storage"],"created_at":"2024-01-05T20:17:20.770Z","updated_at":"2024-12-07T08:30:52.430Z","avatar_url":"https://github.com/tyshkovskii.png","language":"JavaScript","funding_links":[],"categories":["Components"],"sub_categories":["Storage"],"readme":"[![Build](https://img.shields.io/github/workflow/status/artxty/typed-async-storage/Node.js%20CI?style=flat-square)](https://github.com/artxty/typed-async-storage/actions?query=workflow%3A%22Node.js+CI%22)\n\n\u003e [!IMPORTANT]\n\u003e This repo is no longer maintained. Use TypeScript and libraries like [Zod](https://zod.dev/) for better type safety and validation.\n\n# typed-async-storage\n\nA tiny wrapper for [AsyncStorage](https://github.com/react-native-community/async-storage) that allows creating schema-based storage and validation using [PropTypes](https://www.npmjs.com/package/prop-types)  \n\n## Installation\n\n```bash\nnpm install --save typed-async-storage\n```\n\n## Usage\nImport the package along with *AsyncStorage* and *PropTypes*\n```js\nimport createStorage from 'typed-async-storage';\nimport AsyncStorage from '@react-native-community/async-storage';\nimport PropTypes from 'prop-types';\n```\n\n### Simple storage\nTo create a simple storage (single storage) use your old friend *PropTypes* to create a schema\n```js\nconst simpleSchema = {\n  greetingText: PropTypes.string.isRequired,\n  darkMode: PropTypes.bool.isRequired,\n};\n```\n\nCall *createStorage* and pass these required params: storage name, schema, and *AsyncStorage*\n```js\nconst simpleStorage = createStorage({\n  name: 'simpleStorage', // name must be unique for every storage\n  schema: simpleSchema,\n  AsyncStorage,\n});\n```\n\nNow you can interact with your 'simpleStorage' and have *PropTypes* validation out of the box!\n```js\nawait simpleStorage.set('darkMode', true);\nconst isDarkMode = await simpleStorage.get('darkMode');\nconsole.log(isDarkMode); // prints 'true'\n\nawait simpleStorage.set('greetingText', 42);\n// TypeError: Invalid property `greetingText` of type `number` supplied to `simpleStorage`, expected `string`.\n```\n\n### Multiple Storage\nTo deal with sets you have to wrap your schema in PropTypes.objectOf(). **Refer to the below example:**\n```js\n// Or you can use PropTypes.objectOf(PropTypes.shape({ ... }))\nconst usersSchema = PropTypes.objectOf(PropTypes.exact({\n  name: PropTypes.string.isRequired,\n  address: PropTypes.string.isRequired,\n  birthDate: PropTypes.instanceOf(Date).isRequired,\n}));\n\nconst usersStorage = createStorage({\n  name: 'usersStorage',\n  schema: usersSchema,\n  AsyncStorage,\n  isMultiple: true, // pass 'true' to a create multiple storage\n});\n\nawait usersStorage.set({ // pass an object {key: data, ...} of items\n  user1: {\n    name: 'Bob',\n    address: '42 12th Street',\n    birthDate: new Date(2020, 1, 1),\n  },\n  user2: {\n    name: 'Mike',\n    address: '1 Main Street',\n    birthDate: new Date(2019, 1, 1),\n  },\n});\n\n// pass an array of keys you want to get\nawait usersStorage.get(['user1', 'user2']);\n\n```\n\n## Note\nTo make things simple, try to create storages that are as small as possible. For each group of items, create a new storage (users, settings, channels, etc.). Do **not** create a master storage that contains all the data of your application, it is **impossible** to deal with it using this package. Break it down into several smaller storages.\n\n## API\nAPI is built over [AsyncStorage API](https://react-native-community.github.io/async-storage/docs/api)\n### Simple Storage\n```js\n// Sets value for a specific key\nset('myKey1', { a: 1, b: 'text' })\n\n// Gets value for a specific key\nget('myKey1')\n\n// Merges an existing value stored under 'key', with new 'value'\nmerge('myKey1', { b: 'test' }) // Check how it works: https://react-native-community.github.io/async-storage/docs/api#mergeitem\n\n// Removes all data for myKey1\nremove('myKey1')\n\n// Returns all keys for a specific storage\ngetAllKeys()\n\n// Removes all data for all keys in a specific storage\nclear()\n```\n### Multiple Storage\n```js\n// Sets values for specific keys\nset({\n  key1: { a: 1, b: 'string' },\n  key2: { a: 2, b: 'string1' },\n})\n\n// Gets values for specific keys\nget(['key1', 'key2'])\n\n// Multiple merging of existing and new values in a batch\nmerge({\n  key1: { a: 5,},\n  key2: { b: 'str' },\n})\n\n// Removes all data for key1 and key2\nremove(['key1', 'key2'])\n\n// Returns all keys for a specific storage\ngetAllKeys()\n\n// Removes all data for all keys in a specific storage\nclear()\n```\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyshkovskii%2Ftyped-async-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyshkovskii%2Ftyped-async-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyshkovskii%2Ftyped-async-storage/lists"}