Skip to content

Commit

Permalink
UPDATE localForage type definitions (DefinitelyTyped#11702)
Browse files Browse the repository at this point in the history
  • Loading branch information
RecuencoJones authored and mhegazy committed Oct 4, 2016
1 parent e77a0d9 commit 2a5f017
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 40 deletions.
85 changes: 53 additions & 32 deletions localForage/localForage-tests.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,86 @@
/// <reference path="localForage.d.ts" />

declare var localForage: LocalForage;
declare let localForage: LocalForage;

() => {
namespace LocalForageTest {
localForage.clear((err: any) => {
var newError: any = err;
let newError: any = err;
});

localForage.iterate((str: string, key: string, num: number) => {
var newStr: string = str;
var newKey: string = key;
var newNum: number = num;
let newStr: string = str;
let newKey: string = key;
let newNum: number = num;
});

localForage.length((err: any, num: number) => {
var newError: any = err;
var newNumber: number = num;
let newError: any = err;
let newNumber: number = num;
});

localForage.key(0, (err: any, value: string) => {
var newError: any = err;
var newValue: string = value;
let newError: any = err;
let newValue: string = value;
});

localForage.keys((err: any, keys: Array<string>) => {
var newError: any = err;
var newArray: Array<string> = keys;
let newError: any = err;
let newArray: Array<string> = keys;
});

localForage.getItem("key",(err: any, str: string) => {
var newError: any = err;
var newStr: string = str
let newError: any = err;
let newStr: string = str
});

localForage.getItem<string>("key").then((str: string) => {
var newStr: string = str;
let newStr: string = str;
});

localForage.setItem("key", "value",(err: any, str: string) => {
var newError: any = err;
var newStr: string = str
let newError: any = err;
let newStr: string = str
});

localForage.setItem("key", "value").then((str: string) => {
var newStr: string = str;
let newStr: string = str;
});

localForage.removeItem("key",(err: any) => {
var newError: any = err;
let newError: any = err;
});

localForage.removeItem("key").then(() => {
});

var config = localForage.config({
name: "testyo",
driver: localForage.LOCALSTORAGE
});

var store = localForage.createInstance({
name: "da instance",
driver: localForage.LOCALSTORAGE
});
}

{
let config: boolean;

config = localForage.config({
name: "testyo",
driver: localForage.LOCALSTORAGE
});
}

{
let store: LocalForage;

store = localForage.createInstance({
name: "da instance",
driver: localForage.LOCALSTORAGE
});
}

{
let testSerializer: LocalForageSerializer;

localForage.getSerializer()
.then((serializer: LocalForageSerializer) => {
testSerializer = serializer;
});

localForage.getSerializer((serializer: LocalForageSerializer) => {
testSerializer = serializer;
});
}
}
30 changes: 22 additions & 8 deletions localForage/localForage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ interface LocalForageDriver {
setItem(key: string, value: any, callback: (err: any, value: any) => void): void;
}

interface LocalForageSerializer {
serialize<T>(value: T | ArrayBuffer | Blob, callback: (value: string, error: any) => {}): void;

deserialize<T>(value: string): T | ArrayBuffer | Blob;

stringToBuffer(serializedString: string): ArrayBuffer;

bufferToString(buffer: ArrayBuffer): string;
}

interface LocalForage {
LOCALSTORAGE: string;
WEBSQL: string;
Expand All @@ -50,6 +60,12 @@ interface LocalForage {
* @param {ILocalForageConfig} options?
*/
config(options: LocalForageOptions): boolean;

/**
* Create a new instance of localForage to point to a different store.
* All the configuration options used by config are supported.
* @param {LocalForageOptions} options
*/
createInstance(options: LocalForageOptions): LocalForage;

driver(): string;
Expand All @@ -62,6 +78,11 @@ interface LocalForage {
defineDriver(driver: LocalForageDriver): Promise<void>;
defineDriver(driver: LocalForageDriver, callback: () => void, errorCallback: (error: any) => void): void;

getSerializer(): Promise<LocalForageSerializer>;
getSerializer(callback: (serializer: LocalForageSerializer) => void): void;

supports(driverName: string): boolean;

getItem<T>(key: string): Promise<T>;
getItem<T>(key: string, callback: (err: any, value: T) => void): void;

Expand All @@ -86,16 +107,9 @@ interface LocalForage {
iterate(iteratee: (value: any, key: string, iterationNumber: number) => any): Promise<any>;
iterate(iteratee: (value: any, key: string, iterationNumber: number) => any,
callback: (err: any, result: any) => void): void;

/**
* Create a new instance of localForage to point to a different store.
* All the configuration options used by config are supported.
* @param {LocalForageOptions} options
*/
createInstance(options: LocalForageOptions): LocalForage;
}

declare module "localforage" {
var localforage: LocalForage;
let localforage: LocalForage;
export = localforage;
}

0 comments on commit 2a5f017

Please sign in to comment.