Add typings for react-native-shared-group-preferences (#45423)

Co-authored-by: Anthony Campbell <acampbell2@officeworks.com.au>
This commit is contained in:
indented space 2020-06-21 18:13:41 +10:00 committed by GitHub
parent 1e67ae1a43
commit 0d58fcc990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,16 @@
// Type definitions for react-native-shared-group-preferences 1.1
// Project: https://github.com/KjellConnelly/react-native-shared-group-preferences#readme
// Definitions by: Cambo <https://github.com/indentedspace>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface SharedGroupPreferenceOptions {
useAndroidSharedPreferences?: boolean;
}
export namespace SharedGroupPreferences {
function isAppInstalledAndroid(packageName: string): Promise<void>;
function getItem(key: string, appGroup: string, options?: SharedGroupPreferenceOptions): Promise<any>;
function setItem(key: string, value: any, appGroup: string, options?: SharedGroupPreferenceOptions): Promise<void>;
}
export default SharedGroupPreferences;

View File

@ -0,0 +1,24 @@
import SharedGroupPreferences, { SharedGroupPreferenceOptions } from 'react-native-shared-group-preferences';
const isAppInstalledAndroid = async (packageName: string) => {
let appIsInstalled;
try {
await SharedGroupPreferences.isAppInstalledAndroid(packageName);
appIsInstalled = true;
} catch (e) {
appIsInstalled = false;
}
return appIsInstalled;
};
const getItem = async (key: string, appGroup: string, options: SharedGroupPreferenceOptions) => {
const result = await SharedGroupPreferences.getItem(key, appGroup);
return result;
};
const setItem = async (key: string, data: any, appGroup: string, options: SharedGroupPreferenceOptions) => {
await SharedGroupPreferences.setItem(key, data, appGroup);
};
export default { isAppInstalledAndroid, getItem, setItem };

View File

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

View File

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