diff --git a/types/local-storage/index.d.ts b/types/local-storage/index.d.ts new file mode 100644 index 0000000000..3452837374 --- /dev/null +++ b/types/local-storage/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for local-storage 1.4 +// Project: https://github.com/bevacqua/local-storage +// Definitions by: Sasha Grin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +type Listener = (newValue: any, oldValue: any, url: string) => any; + +interface Accessor { + /** + * Invokes set if value is present and get otherwise + * https://github.com/bevacqua/local-storage#lskey-value + */ + (key: string, value: any): boolean; + (key: string): any; + + /** + * Internally uses JSON.parse to parse value from storage without try/catch + * https://github.com/bevacqua/local-storage#lsgetkey + */ + get(key: string): any; + + /** + * Internally uses JSON.stringify before saving. + * https://github.com/bevacqua/local-storage#lssetkey-value + */ + set(key: string, value: any): boolean; + + /** https://github.com/bevacqua/local-storage#lsremovekey */ + remove(key: string): boolean; + + /** https://github.com/bevacqua/local-storage#lsclear */ + clear(): boolean; + + /** https://github.com/bevacqua/local-storage#lsonkey-fn */ + on(key: string, callback: Listener): void; + + /** https://github.com/bevacqua/local-storage#lsoffkey-fn */ + off(key: string, callback: Listener): void; +} + +declare const accessor: Accessor; +export = accessor; diff --git a/types/local-storage/local-storage-tests.ts b/types/local-storage/local-storage-tests.ts new file mode 100644 index 0000000000..410c3cac8e --- /dev/null +++ b/types/local-storage/local-storage-tests.ts @@ -0,0 +1,13 @@ +import ls = require('local-storage'); + +ls('foo'); +ls('foo', 'bar'); +ls.get('foo'); +ls.set('foo', 'bar'); +ls.remove('foo'); +ls.clear(); + +const callback = (newValue: any, oldValue: any, url: string) => null; + +ls.on('foo', callback); +ls.off('foo', callback); diff --git a/types/local-storage/tsconfig.json b/types/local-storage/tsconfig.json new file mode 100644 index 0000000000..f046bae993 --- /dev/null +++ b/types/local-storage/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "local-storage-tests.ts" + ] +} diff --git a/types/local-storage/tslint.json b/types/local-storage/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/local-storage/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }