feat(git-branch-is): new type definition for v3.1 (#42811)

- definition files
- test coverage

https://github.com/kevinoid/git-branch-is#api-usage

Thanks!
This commit is contained in:
Gabriela Araujo Britto 2020-03-04 10:00:14 -08:00 committed by GitHub
parent 13d2990c13
commit 5fff1d9bd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 0 deletions

View File

@ -0,0 +1,39 @@
/// <reference types="node" />
import gitBranchIs = require('git-branch-is');
gitBranchIs('master', (err, result) => {
if (err) console.error(err);
else console.log(result ? 'On master' : 'Not on master');
});
gitBranchIs('master').then(
result => {
console.log(result ? 'On master' : 'Not on master');
},
err => {
console.error(err);
},
);
gitBranchIs(branchName => {
return /^master$/.test(branchName);
}).then(
result => {
console.log(result ? 'On master' : 'Not on master');
},
err => {
console.error(err);
},
);
gitBranchIs(branchName => {
return Promise.resolve(branchName === 'master');
}).then(
result => {
console.log(result ? 'On master' : 'Not on master');
},
err => {
console.error(err);
},
);

55
types/git-branch-is/index.d.ts vendored Normal file
View File

@ -0,0 +1,55 @@
// Type definitions for git-branch-is 3.1
// Project: https://github.com/kevinoid/git-branch-is
// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Checks that the current branch of a git repository has a given name
*/
declare function gitBranchIs(branchNameOrTest: BranchNameOrTest, options?: Options): Promise<boolean>;
declare function gitBranchIs(branchNameOrTest: BranchNameOrTest, callback: Callback): void;
declare function gitBranchIs(branchNameOrTest: BranchNameOrTest, options: Options, callback?: Callback): void;
/**
* test function to apply to the branch name
*/
type BranchNameTest = (branchName: string) => boolean | Promise<boolean>;
/**
* Expected name of current branch
* or a test function to apply to the branch name
*/
type BranchNameOrTest = string | BranchNameTest;
/**
* function called with the return value of <code>branchNameOrTest</code> if it is a function,
* or the result of identity checking <code>branchNameOrTest</code> to the
* current branch name
*/
type Callback = (error: Error | null, result?: boolean) => void;
/**
* Options for {@link gitBranchIs}.
*/
interface Options {
/**
* Current working directory where the branch name is
* tested
*/
cwd?: string;
/**
* Extra arguments to pass to git
*/
gitArgs?: string[];
/**
* Path to the repository (i.e.
* <code>--git-dir=</code> option to <code>git</code>).
*/
gitDir?: string;
/**
* Git binary name or path to use (default:
* <code>'git'</code>).
*/
gitPath?: string;
}
export = gitBranchIs;

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",
"git-branch-is-tests.ts"
]
}

View File

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