From 9c21f9547129a748aa9d3102af8cec20984a32d0 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 26 Aug 2018 11:58:05 +0300 Subject: [PATCH 1/3] Type definitions for local-storage --- types/local-storage/index.d.ts | 42 ++++++++++++++++++++++ types/local-storage/local-storage-tests.ts | 13 +++++++ types/local-storage/tsconfig.json | 23 ++++++++++++ types/local-storage/tslint.json | 1 + 4 files changed, 79 insertions(+) create mode 100644 types/local-storage/index.d.ts create mode 100644 types/local-storage/local-storage-tests.ts create mode 100644 types/local-storage/tsconfig.json create mode 100644 types/local-storage/tslint.json diff --git a/types/local-storage/index.d.ts b/types/local-storage/index.d.ts new file mode 100644 index 0000000000..9c5a6d0a9b --- /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 default 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..89431cba8a --- /dev/null +++ b/types/local-storage/local-storage-tests.ts @@ -0,0 +1,13 @@ +import ls from '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" } From d7f6616c581d2d3496343ee663efbeff7d17d6bb Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Aug 2018 12:42:55 +0300 Subject: [PATCH 2/3] remove default export --- types/local-storage/index.d.ts | 2 +- types/local-storage/local-storage-tests.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/local-storage/index.d.ts b/types/local-storage/index.d.ts index 9c5a6d0a9b..3452837374 100644 --- a/types/local-storage/index.d.ts +++ b/types/local-storage/index.d.ts @@ -39,4 +39,4 @@ interface Accessor { } declare const accessor: Accessor; -export default accessor; +export = accessor; diff --git a/types/local-storage/local-storage-tests.ts b/types/local-storage/local-storage-tests.ts index 89431cba8a..98d273e70b 100644 --- a/types/local-storage/local-storage-tests.ts +++ b/types/local-storage/local-storage-tests.ts @@ -1,4 +1,4 @@ -import ls from 'local-storage'; +import * as ls from 'local-storage'; ls('foo'); ls('foo', 'bar'); From 2c1b92e91dc8c7eef88ff2b1455d1a41e51c1230 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 30 Aug 2018 11:11:46 +0300 Subject: [PATCH 3/3] import require instead of es6 import --- types/local-storage/local-storage-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/local-storage/local-storage-tests.ts b/types/local-storage/local-storage-tests.ts index 98d273e70b..410c3cac8e 100644 --- a/types/local-storage/local-storage-tests.ts +++ b/types/local-storage/local-storage-tests.ts @@ -1,4 +1,4 @@ -import * as ls from 'local-storage'; +import ls = require('local-storage'); ls('foo'); ls('foo', 'bar');