diff --git a/types/git-branch-is/git-branch-is-tests.ts b/types/git-branch-is/git-branch-is-tests.ts new file mode 100644 index 0000000000..4fe8fb1b31 --- /dev/null +++ b/types/git-branch-is/git-branch-is-tests.ts @@ -0,0 +1,39 @@ +/// + +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); + }, +); diff --git a/types/git-branch-is/index.d.ts b/types/git-branch-is/index.d.ts new file mode 100644 index 0000000000..abb6bb1714 --- /dev/null +++ b/types/git-branch-is/index.d.ts @@ -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) +// 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; +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; + +/** + * 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 branchNameOrTest if it is a function, + * or the result of identity checking branchNameOrTest 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. + * --git-dir= option to git). + */ + gitDir?: string; + /** + * Git binary name or path to use (default: + * 'git'). + */ + gitPath?: string; +} + +export = gitBranchIs; diff --git a/types/git-branch-is/tsconfig.json b/types/git-branch-is/tsconfig.json new file mode 100644 index 0000000000..35c667e9f0 --- /dev/null +++ b/types/git-branch-is/tsconfig.json @@ -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" + ] +} diff --git a/types/git-branch-is/tslint.json b/types/git-branch-is/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/git-branch-is/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }