{"id":19945652,"url":"https://github.com/adriano-di-giovanni/cordova-plugin-shared-preferences","last_synced_at":"2025-05-03T16:32:27.423Z","repository":{"id":57207886,"uuid":"119396035","full_name":"adriano-di-giovanni/cordova-plugin-shared-preferences","owner":"adriano-di-giovanni","description":"Shared preferences for Cordova. Save and retrieve persistent key-value pairs of any Javascript data type.","archived":false,"fork":false,"pushed_at":"2019-07-26T15:14:52.000Z","size":17,"stargazers_count":9,"open_issues_count":2,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-08T04:20:59.984Z","etag":null,"topics":["cordova","cordova-android","cordova-android-plugin","cordova-ios","cordova-ios-plugin","cordova-plugin","shared-preferences"],"latest_commit_sha":null,"homepage":null,"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/adriano-di-giovanni.png","metadata":{"files":{"readme":"README.hbs","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-01-29T14:49:43.000Z","updated_at":"2022-04-21T19:00:00.000Z","dependencies_parsed_at":"2022-09-11T05:02:30.637Z","dependency_job_id":null,"html_url":"https://github.com/adriano-di-giovanni/cordova-plugin-shared-preferences","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriano-di-giovanni%2Fcordova-plugin-shared-preferences","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriano-di-giovanni%2Fcordova-plugin-shared-preferences/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriano-di-giovanni%2Fcordova-plugin-shared-preferences/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adriano-di-giovanni%2Fcordova-plugin-shared-preferences/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adriano-di-giovanni","download_url":"https://codeload.github.com/adriano-di-giovanni/cordova-plugin-shared-preferences/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224368293,"owners_count":17299671,"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":["cordova","cordova-android","cordova-android-plugin","cordova-ios","cordova-ios-plugin","cordova-plugin","shared-preferences"],"created_at":"2024-11-13T00:26:24.516Z","updated_at":"2024-11-13T00:26:25.234Z","avatar_url":"https://github.com/adriano-di-giovanni.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shared preferences for Cordova\n\n[![Build Status](https://travis-ci.org/adriano-di-giovanni/cordova-plugin-shared-preferences.svg?branch=master)](https://travis-ci.org/adriano-di-giovanni/cordova-plugin-shared-preferences)\n\nThis plugin provides the ability to save and retrieve persistent key-value pairs of any Javascript data type. You can use this plugin to save any data: arrays, booleans, numbers, strings and objects. This data will persist across user sessions.\n\nThis plugin uses [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences.html) on Android and [NSUserDefaults](https://developer.apple.com/documentation/foundation/nsuserdefaults?language=objc) on iOS.\n\n### Highlights\n\n* save and retrieve key-value pairs of any Javascript data type using JSON serialization and parsing with `.put()` and `.get()`;\n* also save and retrieve key-value pairs of booleans, numbers and strings mapping to native data types with `.putBoolean()`, `.getBoolean()`, `.putNumber()`, `.getNumber()`, `.putString()`, `.getString()`;\n* fallback to user-defined default value if the key doesn't exist;\n* manage multiple sets of preferences;\n* well-tested cross-browser implementation.\n\nPlease, refer to [Installation](#installation), [Usage](#usage) and [API reference](#api_reference) sections for more information.\n\n## Supported platforms\n\n* Android\n* iOS\n\n## Installation \u003ca name=\"installation\"\u003e\u003c/a\u003e\n\n```bash\nnpm install cordova-plugin-awesome-shared-preferences\n```\n\n## Usage \u003ca name=\"usage\"\u003e\u003c/a\u003e\n\nInvoke `SharedPreferences.getInstance()` to retrieve the instance for the default set of preferences:\n\n```javascript\nvar sharedPreferences = window.plugins.SharedPreferences.getInstance()\n```\n\nYou can manage multiple sets of preferences. Invoke `SharePreferences.getInstance(name)` to retrieve an instance for a specific set:\n\n```javascripts\nvar sharedPreferences = window.plugins.SharedPreferences.getInstance('settings')\n```\n\nSet a new preference using `.put()`:\n\n```javascript\nvar key = 'fruits'\nvar value = ['Apple', 'Banana']\nvar successCallback = function() {\n    console.log('OK')\n}\nvar errorCallback = function(err) {\n    console.error(err)\n}\n\nsharedPreferences.put(key, value, successCallback, errorCallback)\n```\n\nRetrieve a value from the preferences using `.get()`:\n\n```javascript\nvar key = 'fruits'\nvar successCallback = function(value) {\n    console.log(value)\n}\nvar errorCallback = function(err) {\n    console.log(err)\n}\n\nsharedPreferences.get(key, successCallback, errorCallback)\n```\n\nIf the key doesn't exist, the `errorCallback` will be invoked. You can override this behavior providing a default value:\n\n```javascript\nvar key = 'animals' // the key doesn't exist\nvar defaultValue = 'Dog'\nvar successCallback = function(value) {\n    console.log(value) // Dog\n}\nvar errorCallback = function(err) {\n    console.error(err)\n}\n\nsharedPreferences.get(key, defaultValue, successCallback, errorCallback)\n```\n\nDelete a key-value pair from the preferences using `.del()`:\n\n```javascript\nvar key = 'fruits'\nvar successCallback = function() {\n    console.log('OK')\n}\nvar errorCallback = function(err) {\n    console.error(err)\n}\n\nsharedPreferences.del(key, successCallback, errorCallback)\n```\n\n## API reference \u003ca name=\"api_reference\"\u003e\u003c/a\u003e\n\n{{#module name=\"SharedPreferences\"}}\n{{\u003ebody~}}\n{{\u003emember-index~}}\n{{\u003eseparator~}}\n{{\u003emembers~}}\n{{/module}}\n\n## License\n\nThis project is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadriano-di-giovanni%2Fcordova-plugin-shared-preferences","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadriano-di-giovanni%2Fcordova-plugin-shared-preferences","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadriano-di-giovanni%2Fcordova-plugin-shared-preferences/lists"}