mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #28401 from tup1tsa/localStorageTypes
Type definitions for local-storage
This commit is contained in:
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// Type definitions for local-storage 1.4
|
||||
// Project: https://github.com/bevacqua/local-storage
|
||||
// Definitions by: Sasha Grin <https://github.com/tup1tsa>
|
||||
// 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;
|
||||
@@ -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);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user