From 33735286ede08b854b666e01b25bd9586f8b0352 Mon Sep 17 00:00:00 2001 From: david pichsenmeister Date: Tue, 4 Feb 2014 15:14:35 +0100 Subject: [PATCH 1/2] added typing of mozilla localForage library --- localForage/localForage.d.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 localForage/localForage.d.ts diff --git a/localForage/localForage.d.ts b/localForage/localForage.d.ts new file mode 100644 index 0000000000..71ccaba3c2 --- /dev/null +++ b/localForage/localForage.d.ts @@ -0,0 +1,26 @@ +// Type definitions for Mozilla's localForage +// Project: https://github.com/mozilla/localforage +// Definitions by: david pichsenmeister +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module lf { + interface ILocalForage { + clear(): void + key(index: number): T + length: number + getItem(key: string, callback: ICallback) + getItem(key: string): IPromise + setItem(key: string, value: T, callback: ICallback) + setItem(key: string, value: T): IPromise + removeItem(key: string, callback: ICallback) + removeItem(key: string): IPromise + } + + interface ICallback { + (data: T): void + } + + interface IPromise { + then(callback: ICallback): void + } +} \ No newline at end of file From 699ad8ec9f041b12d923b9f76df6b89fcd0a3377 Mon Sep 17 00:00:00 2001 From: david pichsenmeister Date: Fri, 21 Feb 2014 15:03:21 +0100 Subject: [PATCH 2/2] added tests --- README.md | 1 + localForage/localForage-tests.ts | 34 ++++++++++++++++++++++++++++++++ localForage/localForage.d.ts | 6 +++--- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 localForage/localForage-tests.ts diff --git a/README.md b/README.md index ab4a8cdaef..2095f510bf 100755 --- a/README.md +++ b/README.md @@ -178,6 +178,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)) diff --git a/localForage/localForage-tests.ts b/localForage/localForage-tests.ts new file mode 100644 index 0000000000..f1a416dcf7 --- /dev/null +++ b/localForage/localForage-tests.ts @@ -0,0 +1,34 @@ +/// + +declare var localForage: lf.ILocalForage +declare var callback: lf.ICallback +declare var promise: lf.IPromise + +() => { + 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) +} diff --git a/localForage/localForage.d.ts b/localForage/localForage.d.ts index 71ccaba3c2..c3d0371d00 100644 --- a/localForage/localForage.d.ts +++ b/localForage/localForage.d.ts @@ -8,11 +8,11 @@ declare module lf { clear(): void key(index: number): T length: number - getItem(key: string, callback: ICallback) + getItem(key: string, callback: ICallback): void getItem(key: string): IPromise - setItem(key: string, value: T, callback: ICallback) + setItem(key: string, value: T, callback: ICallback): void setItem(key: string, value: T): IPromise - removeItem(key: string, callback: ICallback) + removeItem(key: string, callback: ICallback): void removeItem(key: string): IPromise }