diff --git a/types/issue-parser/index.d.ts b/types/issue-parser/index.d.ts new file mode 100644 index 0000000000..50f9fa304f --- /dev/null +++ b/types/issue-parser/index.d.ts @@ -0,0 +1,55 @@ +// Type definitions for issue-parser 3.0 +// Project: https://github.com/pvdlg/issue-parser#readme +// Definitions by: Leko +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +declare function issueParser( + authOptions?: issueParser.Options, + extension?: issueParser.Overrides +): issueParser.Parser; + +declare namespace issueParser { + type Parser = (text: string) => Result; + interface Overrides { + actions?: { + [type: string]: ReadonlyArray; + }; + delimiters?: string | ReadonlyArray; + mentionsPrefixes?: string | ReadonlyArray; + issuePrefixes?: string | ReadonlyArray; + hosts?: string | ReadonlyArray; + issueURLSegments?: string | ReadonlyArray; + overrides?: string | ReadonlyArray; + } + type Options = "github" | "gitlab" | "bitbucket" | "waffle" | Overrides; + interface Reference { + raw: string; + slug: string | undefined; + prefix: string | undefined; + issue: string; + } + interface Mention { + raw: string; + prefix: string; + user: string; + } + interface Action { + raw: string; + action: string; + slug: string | undefined; + prefix: string | undefined; + issue: string; + } + interface Actions { + [action: string]: ReadonlyArray; + } + interface Result { + refs: ReadonlyArray; + mentions: ReadonlyArray; + actions: Actions; + allRefs: Array; + } +} + +export = issueParser; diff --git a/types/issue-parser/issue-parser-tests.ts b/types/issue-parser/issue-parser-tests.ts new file mode 100644 index 0000000000..d25f1e06f6 --- /dev/null +++ b/types/issue-parser/issue-parser-tests.ts @@ -0,0 +1,72 @@ +import issueParser = require("issue-parser"); +import { Action } from "issue-parser"; + +// Without options +issueParser(); + +// With predefined options +issueParser("github"); +issueParser("bitbucket"); +issueParser("gitlab"); +issueParser("waffle"); + +// With custom format +issueParser({ + actions: { + fix: ["complete"], + hold: ["holds up"] + }, + issuePrefixes: ["🐛"] +}); + +// Extend existing format +issueParser("github", { + actions: { + parent: ["parent of"], + related: ["related to"] + } +}); + +const parse = issueParser("github"); +const result = parse("#1"); + +// Parse references +result.refs.forEach(ref => { + ref.issue; + ref.slug; + ref.raw; + ref.prefix; +}); + +// Parse closing keywords +result.actions.close.forEach(action => { + action.raw; + action.action; + action.slug; + action.prefix; + action.issue; +}); + +// Parse user mentions +result.mentions.forEach(mention => { + mention.raw; + mention.prefix; + mention.user; +}); + +// allRefs +const isAction = (ref: any): ref is Action => true; +result.allRefs.forEach(ref => { + if (isAction(ref)) { + ref.raw; + ref.action; + ref.slug; + ref.prefix; + ref.issue; + } else { + ref.raw; + ref.slug; + ref.prefix; + ref.issue; + } +}); diff --git a/types/issue-parser/tsconfig.json b/types/issue-parser/tsconfig.json new file mode 100644 index 0000000000..3d9ce3d939 --- /dev/null +++ b/types/issue-parser/tsconfig.json @@ -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", + "issue-parser-tests.ts" + ] +} diff --git a/types/issue-parser/tslint.json b/types/issue-parser/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/issue-parser/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }