mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add type definitions for issue-parser 3.0
This commit is contained in:
parent
96f1ee52c6
commit
d438f1d013
55
types/issue-parser/index.d.ts
vendored
Normal file
55
types/issue-parser/index.d.ts
vendored
Normal 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;
|
||||
72
types/issue-parser/issue-parser-tests.ts
Normal file
72
types/issue-parser/issue-parser-tests.ts
Normal 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;
|
||||
}
|
||||
});
|
||||
23
types/issue-parser/tsconfig.json
Normal file
23
types/issue-parser/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/issue-parser/tslint.json
Normal file
1
types/issue-parser/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user