Merge pull request #1661 from 3x14159265/localForage

added typing of mozilla localForage library
This commit is contained in:
Bart van der Schoor
2014-02-22 19:30:18 +01:00
3 changed files with 61 additions and 0 deletions
+1
View File
@@ -181,6 +181,7 @@ List of Definitions
* [Levelup](https://github.com/rvagg/node-levelup) (by [Bret Little](https://github.com/blittle))
* [linq.js](http://linqjs.codeplex.com/) (by [Marcin Najder](https://github.com/marcinnajder))
* [Livestamp.js](https://github.com/mattbradley/livestampjs) (by [Vincent Bortone](https://github.com/vbortone))
* [localForage](https://github.com/mozilla/localForage) (by [david pichsenmeister](https://github.com/3x14159265))
* [Lodash](http://lodash.com/) (by [Brian Zengel](https://github.com/bczengel))
* [Logg](https://github.com/dpup/node-logg) (by [Bret Little](https://github.com/blittle))
* [Marked](https://github.com/chjj/marked) (by [William Orr](https://github.com/worr))
+34
View File
@@ -0,0 +1,34 @@
/// <reference path="localForage.d.ts" />
declare var localForage: lf.ILocalForage<string>
declare var callback: lf.ICallback<string>
declare var promise: lf.IPromise<string>
() => {
localForage.clear()
localForage.length
localForage.key(0)
localForage.getItem("key", (str: string) => {
var newStr: string = str
})
localForage.getItem("key").then((str: string) => {
var newStr: string = str
})
localForage.setItem("key", "value", (str: string) => {
var newStr: string = str
})
localForage.setItem("key", "value").then((str: string) => {
var newStr: string = str
})
localForage.removeItem("key", (str: string) => {
var newStr: string = str
})
localForage.removeItem("key").then((str: string) => {
var newStr: string = str
})
promise.then(callback)
}
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for Mozilla's localForage
// Project: https://github.com/mozilla/localforage
// Definitions by: david pichsenmeister <https://github.com/3x14159265>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module lf {
interface ILocalForage<T> {
clear(): void
key(index: number): T
length: number
getItem(key: string, callback: ICallback<T>): void
getItem(key: string): IPromise<T>
setItem(key: string, value: T, callback: ICallback<T>): void
setItem(key: string, value: T): IPromise<T>
removeItem(key: string, callback: ICallback<T>): void
removeItem(key: string): IPromise<T>
}
interface ICallback<T> {
(data: T): void
}
interface IPromise<T> {
then(callback: ICallback<T>): void
}
}