Skip to content
Permalink
Browse files

Initial import

  • Loading branch information...
mlynch committed Sep 23, 2016
1 parent f18f2cd commit 58e40b20ee50ff005785c41765453c4955a1a8c8
Showing with 208 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +4 −0 .npmignore
  3. +21 −0 LICENSE
  4. +39 −0 package.json
  5. +3 −0 src/index.ts
  6. +112 −0 src/storage.ts
  7. +20 −0 tsconfig.json
  8. +7 −0 typings.json
@@ -0,0 +1,2 @@
node_modules
dist
@@ -0,0 +1,4 @@
gulpfile.js
src
tsconfig.json
tslint.json
21 LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Ionic

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,39 @@
{
"name": "ionic-storage",
"version": "1.0.0",
"description": "Ionic Storage utility",
"main": "dist/es5/index.js",
"typings": "dist/es5/index.d.ts",
"scripts": {
"tsc": "tsc",
"build": "npm run tsc"
},
"repository": {
"type": "git",
"url": "git+https://github.com/driftyco/ionic-storage.git"
},
"keywords": [
"ionic",
"angular",
"localforage",
"cordova",
"hybrid"
],
"author": "Max Lynch <max@ionic.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/driftyco/ionic-storage/issues"
},
"homepage": "https://github.com/driftyco/ionic-storage#readme",
"dependencies": {
"@angular/core": "^2.0.0",
"localforage": "^1.4.2",
"rxjs": "5.0.0-beta.12"
},
"devDependencies": {
"tslint": "^3.10.2",
"tslint-ionic-rules": "*",
"typescript": "^2.0.2",
"typings": "^1.3.3"
}
}
@@ -0,0 +1,3 @@
import { Storage } from './storage';

export { Storage };
@@ -0,0 +1,112 @@
import { Injectable } from '@angular/core';

//import LocalForage = require('localforage');
//import * as LocalForage from 'localforage';
import * as LocalForage from 'localforage';

//declare var LocalForage;

//import * as CordovaSQLiteDriver from 'localforage-cordovasqlitedriver';

//console.log('Loaded CordovaSQLiteDriver', CordovaSQLiteDriver);


/**
* Storage is an easy way to store key/value pairs and other complicated
* data in a way that uses a variety of storage engines underneath. Currently,
* Storage uses localforage underneath to abstract away the various storage
* engines while still providing a simple API.
*
* When running natively, Storage will prioritize using SQLite, as it's one of
* the most stable and widely used file-based databases, and avoids some of the
* pitfalls of things like localstorage that the OS can decide to clear out in
* low disk-space situations.
*
* When running in the web or as a Progressive Web App, Storage will attempt to use
* IndexedDB, WebSQL, and localstorage, in that order.
*/
@Injectable()
export class Storage {
_db: any;

constructor() {
// TODO: Remove this once we figure out our proper build
if(LocalForage['default']) {
this._db = LocalForage['default'];
} else {
this._db = LocalForage;
}

this._db.config({
name : '_ionicstorage',
storeName : '_ionickv'
});

//var sqliteDriver = CordovaSQLiteDriver['default'];

this._db.setDriver([
//ggsqliteDriver._driver,
this._db.INDEXEDDB,
this._db.WEBSQL,
this._db.LOCALSTORAGE
])
}

/**
* Get the value assocated with the given key.
* @return Promise that resolves with the value
*/
get(key: string): Promise<any> {
return this._db.getItem(key);
}

/**
* Set the value for the given key.
* @param key the key to identify this value
* @param value the value for this key
* @return Promise that resolves when the value is set
*/
set(key: string, value: any) {
return this._db.setItem(key, value);
}

/**
* Remove any value associated with this key.
* @param key the key to identify this value
* @return Promise that resolves when the value is removed
*/
remove(key: string) {
return this._db.removeItem(key);
}

/**
* Clear the entire key value store. WARNING: HOT!
* @return Promise that resolves when the kv store is cleared
*/
clear() {
return this._db.clear();
}

/**
* @return the number of keys stored.
*/
length() {
return this._db.length();
}

/**
* @return the keys in the store.
*/
keys() {
return this._db.keys();
}

/**
* Iterate through each key,value pair.
* @param iteratorCallback a callback of the form (value, key, iterationNumber)
*/
forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any) {
return this._db.iterate(iteratorCallback);
}

}
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"allowJs": false,
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"noImplicitReturns": true,
"removeComments": false,
"sourceMap": true,
"outDir": "dist/es5",
"target": "es5"
},
"files": [
"src/index.ts"
]
}
@@ -0,0 +1,7 @@
{
"name": "@ionic/cloud-angular",
"dependencies": {},
"globalDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504"
}
}

0 comments on commit 58e40b2

Please sign in to comment.
You can’t perform that action at this time.