This commit is contained in:
Ian Copp 2018-04-26 15:12:03 -07:00 committed by Wesley Wigham
parent 363fbd9d5f
commit c19e1e8289
4 changed files with 99 additions and 0 deletions

55
types/roll/index.d.ts vendored Normal file
View File

@ -0,0 +1,55 @@
// Type definitions for roll 1.2
// Project: https://github.com/troygoode/node-roll/
// Definitions by: icopp <https://github.com/icopp>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type RollTransformation = RollTransformationKey | [RollTransformationKey, number] | ((results: number[]) => number[]);
type RollTransformationKey = 'sum' | 'add' | 'subtract' | 'multiply' | 'divide' | 'best-of' | 'worst-of';
interface RollObject {
quantity: number;
sides: number;
transformations: RollTransformation[];
toString: () => string;
}
interface RollOutput {
input: RollObject;
calculations: number[];
rolled: number[];
result: number;
}
declare class InvalidInputError extends Error {
name: 'InvalidInputError';
}
declare class Roll {
static InvalidInputError: InvalidInputError;
constructor(seed?: () => number);
/**
* Validate user input
*/
validate(input: string): boolean;
/**
* Parse a string into a roll object
* @throws InvalidInputError
*/
parse(input: string): {
quantity: number;
sides: number;
transformations: RollTransformation[];
toString: () => string;
};
/**
* Roll based on a string or roll object
*/
roll(input: string | RollObject): RollOutput;
}
export = Roll;

20
types/roll/roll-tests.ts Normal file
View File

@ -0,0 +1,20 @@
import Roll = require('roll');
// $ExpectType Roll
const roll = new Roll();
// $ExpectType number
roll.roll('d6').result;
// $ExpectType number
roll.roll({
quantity: 2,
sides: 6,
transformations: [
'sum',
['add', 2]
]
}).result;
// $ExpectType InvalidInputError
Roll.InvalidInputError;

23
types/roll/tsconfig.json Normal file
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",
"roll-tests.ts"
]
}

1
types/roll/tslint.json Normal file
View File

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