Skip to content

Commit 01f92c8

Browse files
initial commit
0 parents  commit 01f92c8

17 files changed

+3053
-0
lines changed

Diff for: .editorconfig

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# http://editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 4
12+
13+
# We recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true
18+
19+
[*.md]
20+
trim_trailing_whitespace = false
21+
22+
[*.yml]
23+
indent_size = 2

Diff for: .eslintrc.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": ["standard", "prettier"],
4+
"plugins": ["prettier"],
5+
"rules": {
6+
"prettier/prettier": "error"
7+
},
8+
"env": {
9+
"jasmine": true
10+
}
11+
}

Diff for: .prettierrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 4,
4+
"useTabs": false,
5+
"semi": false,
6+
"singleQuote": true,
7+
"trailingComma": "es5",
8+
"bracketSpacing": true,
9+
"jsxBracketSameLine": true
10+
}

Diff for: .travis.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
sudo: false
2+
addons:
3+
sauce_connect: true
4+
env:
5+
global:
6+
- SAUCE_USERNAME=adriano-di-giovanni
7+
- SAUCE_ACCESS_KEY=f3dcb078-9d3d-4e06-a589-bcf1d24ec646"
8+
- TRAVIS_NODE_VERSION="4.3"
9+
matrix:
10+
include:
11+
- env: PLATFORM=ios-9.3
12+
os: osx
13+
osx_image: xcode7.3
14+
language: node_js
15+
node_js: '4.3'
16+
- env: PLATFORM=ios-10.0
17+
os: osx
18+
osx_image: xcode7.3
19+
language: node_js
20+
node_js: '4.3'
21+
- env: PLATFORM=android-4.4
22+
os: linux
23+
language: android
24+
jdk: oraclejdk8
25+
android:
26+
components:
27+
- tools
28+
- build-tools-26.0.2
29+
- env: PLATFORM=android-5.1
30+
os: linux
31+
language: android
32+
jdk: oraclejdk8
33+
android:
34+
components:
35+
- tools
36+
- build-tools-26.0.2
37+
- env: PLATFORM=android-6.0
38+
os: linux
39+
language: android
40+
jdk: oraclejdk8
41+
android:
42+
components:
43+
- tools
44+
- build-tools-26.0.2
45+
- env: PLATFORM=android-7.0
46+
os: linux
47+
language: android
48+
jdk: oraclejdk8
49+
android:
50+
components:
51+
- tools
52+
- build-tools-26.0.2
53+
54+
before_install:
55+
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install ${TRAVIS_NODE_VERSION}
56+
- node --version
57+
- if [[ "$PLATFORM" =~ android ]]; then gradle --version; fi
58+
- if [[ "$PLATFORM" =~ ios ]]; then npm install -g ios-deploy; fi
59+
- if [[ "$PLATFORM" =~ android ]]; then echo y | android update sdk -u --filter android-22,android-23,android-24,android-25,android-26; fi
60+
- git clone https://github.com/apache/cordova-paramedic /tmp/paramedic && pushd /tmp/paramedic && npm install && popd
61+
- npm install -g cordova
62+
63+
install:
64+
npm install
65+
66+
script:
67+
- node /tmp/paramedic/main.js --config pr/${PLATFORM} --plugin $(pwd) --shouldUseSauce --buildName cordova-plugin-shared-preferences-${TRAVIS_JOB_NUMBER}

Diff for: README.hbs

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Shared preferences for Cordova
2+
3+
[![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)
4+
5+
This 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.
6+
7+
This 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.
8+
9+
### Highlights
10+
11+
* save and retrieve key-value pairs of any Javascript data type using JSON serialization and parsing with `.put()` and `.get()`;
12+
* also save and retrieve key-value pairs of booleans, numbers and strings mapping to native data types with `.putBoolean()`, `.getBoolean()`, `.putNumber()`, `.getNumber()`, `.putString()`, `.getString()`;
13+
* fallback to user-defined default value if the key doesn't exist;
14+
* manage multiple sets of preferences;
15+
* well-tested cross-browser implementation.
16+
17+
Please, refer to [Installation](#installation), [Usage](#usage) and [API reference](#api_reference) sections for more information.
18+
19+
## Supported platforms
20+
21+
* Android
22+
* iOS
23+
24+
## Installation <a name="installation"></a>
25+
26+
```bash
27+
npm install cordova-plugin-awesome-shared-preferences
28+
```
29+
30+
## Usage <a name="usage"></a>
31+
32+
Invoke `SharedPreferences.getInstance()` to retrieve the instance for the default set of preferences:
33+
34+
```javascript
35+
var sharedPreferences = window.plugins.SharedPreferences.getInstance()
36+
```
37+
38+
You can manage than one set of preferences. Invoke `SharePreferences.getInstance(name)` to retrieve an instance for a specific set:
39+
40+
```javascripts
41+
var sharedPreferences = window.plugins.SharedPreferences.getInstance('settings')
42+
```
43+
44+
Set a new preference using `.put()`:
45+
46+
```javascript
47+
var key = 'fruits'
48+
var value = ['Apple', 'Banana']
49+
var successCallback = function() {
50+
console.log('OK')
51+
}
52+
var errorCallback = function(err) {
53+
console.error(err)
54+
}
55+
56+
sharedPreferences.put(key, value, successCallback, errorCallback)
57+
```
58+
59+
Retrieve a value from the preferences using `.get()`:
60+
61+
```javascript
62+
var key = 'fruits'
63+
var successCallback = function(value) {
64+
console.log(value)
65+
}
66+
var errorCallback = function(err) {
67+
console.log(err)
68+
}
69+
70+
sharedPreferences.get(key, successCallback, errorCallback)
71+
```
72+
73+
If the key doesn't exist, the `errorCallback` will be invoked. You can override this behavior providing a default value:
74+
75+
```javascript
76+
var key = 'animals' // the key doesn't exist
77+
var defaultValue = 'Dog'
78+
var successCallback = function(value) {
79+
console.log(value) // Dog
80+
}
81+
var errorCallback = function(err) {
82+
console.error(err)
83+
}
84+
85+
sharedPreferences.get(key, defaultValue, successCallback, errorCallback)
86+
```
87+
88+
Delete a key-value pair from the preferences using `.del()`:
89+
90+
```javascript
91+
var key = 'fruits'
92+
var successCallback = function() {
93+
console.log('OK')
94+
}
95+
var errorCallback = function(err) {
96+
console.error(err)
97+
}
98+
99+
sharedPreferences.del(key, successCallback, errorCallback)
100+
```
101+
102+
## API reference <a name="api_reference"></a>
103+
104+
{{#module name="SharedPreferences"}}
105+
{{>body~}}
106+
{{>member-index~}}
107+
{{>separator~}}
108+
{{>members~}}
109+
{{/module}}
110+
111+
## License
112+
113+
This project is licensed under the MIT license.

0 commit comments

Comments
 (0)