Add type definitions for issue-parser 3.0

This commit is contained in:
Leko 2018-12-21 19:33:45 +09:00
parent 96f1ee52c6
commit d438f1d013
4 changed files with 151 additions and 0 deletions

55
types/issue-parser/index.d.ts vendored Normal file
View File

@ -0,0 +1,55 @@
// Type definitions for issue-parser 3.0
// Project: https://github.com/pvdlg/issue-parser#readme
// Definitions by: Leko <https://github.com/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<string>;
};
delimiters?: string | ReadonlyArray<string>;
mentionsPrefixes?: string | ReadonlyArray<string>;
issuePrefixes?: string | ReadonlyArray<string>;
hosts?: string | ReadonlyArray<string>;
issueURLSegments?: string | ReadonlyArray<string>;
overrides?: string | ReadonlyArray<string>;
}
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<Action>;
}
interface Result {
refs: ReadonlyArray<Reference>;
mentions: ReadonlyArray<Mention>;
actions: Actions;
allRefs: Array<Reference | Action>;
}
}
export = issueParser;

View File

@ -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;
}
});

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",
"issue-parser-tests.ts"
]
}

View File

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