Add types for good-storage (#37888)

* Add types form good-storage

* prettier formatter good-storage code

* fix good-storage code
This commit is contained in:
wkl
2019-08-26 23:16:35 +08:00
committed by Sheetal Nandi
parent 96ba169089
commit 3efcd0397d
4 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import storage = require('good-storage');
// localStorage
storage.set('name', 'value');
storage.get('name', 'defaultValue');
storage.has('name');
storage.remove('name');
storage.clear();
storage.getAll();
storage.forEach(() => {});
// sessionStorage
storage.session.set('name', 'value');
storage.session.get('name', 'defaultValue');
storage.session.has('name');
storage.session.remove('name');
storage.session.clear();
storage.session.getAll();
storage.session.forEach(() => {});

26
types/good-storage/index.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
// Type definitions for good-storage 1.1
// Project: https://github.com/ustbhuangyi/storage
// Definitions by: Wang KaiLing <https://github.com/wkl007>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Storage {
session: Storage;
set(key: string, val?: any): any;
get(key: string, def?: any): any;
has(key: string): boolean;
remove(key: string): void;
clear(): void;
getAll(): any;
forEach(callback: () => void): void;
}
declare const storage: Storage;
export = storage;

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"good-storage-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }