Merge pull request #31318 from BendingBender/subsume

Add types for subsume v2
This commit is contained in:
Jesse Trinity
2018-12-13 15:42:54 -08:00
committed by GitHub
7 changed files with 95 additions and 4 deletions
+7 -1
View File
@@ -1,4 +1,4 @@
// Type definitions for subsume 1.0
// Type definitions for subsume 2.0
// Project: https://github.com/sindresorhus/subsume#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -7,6 +7,7 @@ export = Subsume;
declare class Subsume {
static parse(text: string, id: string): Subsume.ParseResult;
static parseAll(text: string, ids?: string[]): Subsume.ParseResults;
id: string;
prefix: string;
@@ -23,4 +24,9 @@ declare namespace Subsume {
data?: string;
rest: string;
}
interface ParseResults {
data: Map<string, string>;
rest: string;
}
}
+10 -2
View File
@@ -18,5 +18,13 @@ res; // $ExpectType ParseResult
res.data; // $ExpectType string | undefined
res.rest; // $ExpectType string
const input = 'some@@[7febcd0b3806fbc48c01d7cea4ed1219]@@🦄##[7febcd0b3806fbc48c01d7cea4ed1219]## random text';
Subsume.parse(text, '7febcd0b3806fbc48c01d7cea4ed1219'); // $ExpectType ParseResult
const input =
'some@@[7febcd0b3806fbc48c01d7cea4ed1219]@@🦄##[7febcd0b3806fbc48c01d7cea4ed1219]## random text';
Subsume.parse(input, '7febcd0b3806fbc48c01d7cea4ed1219'); // $ExpectType ParseResult
const input2 =
'some@@[7febcd0b3806fbc48c01d7cea4ed1219]@@🦄##[7febcd0b3806fbc48c01d7cea4ed1219]## ' +
'random@@[7febcd0b3806fbc48c01d7cea4ed1218]@@🦄##[7febcd0b3806fbc48c01d7cea4ed1218]## ' +
'text@@[7febcd0b3806fbc48c01d7cea4ed1217]@@🦄##[7febcd0b3806fbc48c01d7cea4ed1217]##';
Subsume.parseAll(input2); // $ExpectType ParseResults
Subsume.parseAll(input2, ['7febcd0b3806fbc48c01d7cea4ed1219']); // $ExpectType ParseResults
+1 -1
View File
@@ -20,4 +20,4 @@
"index.d.ts",
"subsume-tests.ts"
]
}
}
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for subsume 1.0
// Project: https://github.com/sindresorhus/subsume#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = Subsume;
declare class Subsume {
static parse(text: string, id: string): Subsume.ParseResult;
id: string;
prefix: string;
postfix: string;
regex: RegExp;
constructor(id?: string);
compose(text: string): string;
parse(text: string): Subsume.ParseResult;
}
declare namespace Subsume {
interface ParseResult {
data?: string;
rest: string;
}
}
+22
View File
@@ -0,0 +1,22 @@
import Subsume = require('subsume');
const subsume = new Subsume();
new Subsume('foo');
subsume.id; // $ExpectType string
subsume.prefix; // $ExpectType string
subsume.postfix; // $ExpectType string
subsume.regex; // $ExpectType RegExp
const text = subsume.compose('🦄');
text; // $ExpectType string
const output = `some${text} random text`;
const res = subsume.parse(output);
res; // $ExpectType ParseResult
res.data; // $ExpectType string | undefined
res.rest; // $ExpectType string
const input = 'some@@[7febcd0b3806fbc48c01d7cea4ed1219]@@🦄##[7febcd0b3806fbc48c01d7cea4ed1219]## random text';
Subsume.parse(text, '7febcd0b3806fbc48c01d7cea4ed1219'); // $ExpectType ParseResult
+28
View File
@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"paths": {
"subsume": [
"subsume/v1"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"subsume-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }