🤖 Merge PR #49981 Add Type defintions for Babar 0.2 by @Bachmann1234

* adds Babar 0.2

* Grid is a color

* ascii is only valid on color. Not Grid

* This form is prefered for commonjs mods
This commit is contained in:
Matt Bachmann
2020-12-09 12:33:04 -05:00
committed by GitHub
parent c35f8b4011
commit c39c9481fe
4 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import babar = require('babar');
// $ExpectType string
const graph = babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]);
// $ExpectType string
const graphWithCaption = babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]], {caption: "Test"});
// $ExpectType string
const graphWithAllOptions = babar([[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]], {
caption: 'Test',
color: 'green',
grid: 'blue',
width: 80,
height: 15,
xFractions: 20,
yFractions: 10,
minX: 0,
maxX: 100,
minY: 0,
maxY: 100
});
// $ExpectType string
const asciiValidColor = babar([[0, 1], [1, 5]], {color: "ascii"});
// $ExpectError
const invalidPoints = babar([["0", 1], ["1", 5]]);
// $ExpectError
const invalidOptions = babar([[0, 1], [1, 5]], {batman: 1});
// $ExpectError
const invalidOptionType = babar([[0, 1], [1, 5]], {caption: 1});
// $ExpectError
const invalidColor = babar([[0, 1], [1, 5]], {color: "pink"});
// $ExpectError
const asciiNotAllowedOnGrid = babar([[0, 1], [1, 5]], {grid: "ascii"});

23
types/babar/index.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
// Type definitions for babar 0.2
// Project: https://github.com/stephan83/babar#readme
// Definitions by: Matt Bachmann <https://github.com/Bachmann1234>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
type color = 'yellow' | 'cyan' | 'white' | 'magenta' | 'green' | 'red' | 'grey' | 'blue';
interface Options {
caption?: string;
color?: color | 'ascii';
grid?: color;
width?: number;
height?: number;
xFractions?: number;
yFractions?: number;
minX?: number;
maxX?: number;
minY?: number;
maxY?: number;
}
declare function babar(points: ReadonlyArray<[number, number]>, options?: Options): string;
export = babar;

24
types/babar/tsconfig.json Normal file
View File

@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"esModuleInterop": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"babar-tests.ts"
]
}

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

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