From c35d0df691297c22d4d0be3feaf9e0f173b1a71f Mon Sep 17 00:00:00 2001 From: Avi Vahl Date: Mon, 1 Jul 2019 21:16:06 +0300 Subject: [PATCH] Add types/tests for grid-template-parser (#36557) --- .../grid-template-parser-tests.ts | 70 ++++++++++ types/grid-template-parser/index.d.ts | 125 ++++++++++++++++++ types/grid-template-parser/tsconfig.json | 23 ++++ types/grid-template-parser/tslint.json | 1 + 4 files changed, 219 insertions(+) create mode 100644 types/grid-template-parser/grid-template-parser-tests.ts create mode 100644 types/grid-template-parser/index.d.ts create mode 100644 types/grid-template-parser/tsconfig.json create mode 100644 types/grid-template-parser/tslint.json diff --git a/types/grid-template-parser/grid-template-parser-tests.ts b/types/grid-template-parser/grid-template-parser-tests.ts new file mode 100644 index 00000000000000..ff1d89469a83e4 --- /dev/null +++ b/types/grid-template-parser/grid-template-parser-tests.ts @@ -0,0 +1,70 @@ +import { + grid, + template, + area, + rect, + minColumnStart, + maxColumnStart, + minColumnEnd, + maxColumnEnd, + minRowStart, + maxRowStart, + minRowEnd, + maxRowEnd, +} from 'grid-template-parser'; + +const testGrid = grid(` + "a a a b b" + "a a a b b" + ". . c c c" + "d d d d d" +`); + +template({ + width: 5, + height: 4, + areas: { + a: { + column: { start: 1, end: 4, span: 3 }, + row: { start: 1, end: 3, span: 2 }, + }, + b: { + column: { start: 3, end: 6, span: 3 }, + row: { start: 3, end: 5, span: 2 }, + }, + }, +}); + +const a = area({ + x: 0, + y: 0, + width: 3, + height: 2, +}); + +const b = area({ + x: 2, + y: 2, + width: 3, + height: 2, +}); + +template({ + width: 5, + height: 4, + areas: { a, b }, +}); + +rect({ + column: { start: 1, end: 4, span: 3 }, + row: { start: 1, end: 3, span: 2 }, +}); + +minColumnStart(testGrid); +maxColumnStart(testGrid); +minColumnEnd(testGrid); +maxColumnEnd(testGrid); +minRowStart(testGrid); +maxRowStart(testGrid); +minRowEnd(testGrid); +maxRowEnd(testGrid); diff --git a/types/grid-template-parser/index.d.ts b/types/grid-template-parser/index.d.ts new file mode 100644 index 00000000000000..880ce4888b25c3 --- /dev/null +++ b/types/grid-template-parser/index.d.ts @@ -0,0 +1,125 @@ +// Type definitions for grid-template-parser 0.3 +// Project: https://github.com/anthonydugois/grid-template-parser +// Definitions by: Avi Vahl +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +/** + * Parses a grid template. + * + * @param template the grid template to parse. + * @returns an object representation of the grid template. + */ +export function grid(template: string): Grid; + +/** + * Builds a grid template from an object representation. + * + * @param grid the grid to build. + * @returns the equivalent grid template. + */ +export function template(grid: Grid): string; + +/** + * Converts an area into a rect. + * + * @param area the area to convert. + * @returns the equivalent rect. + */ +export function rect(area?: Partial): Rect; + +/** + * Converts a rect into an area. + * + * @param rect the rect to convert. + * @returns The equivalent area. + */ +export function area(rect?: Partial): Area; + +/** + * Finds the min column start of all grid areas. + * + * @param grid the grid to analyze. + * @returns the min column start. + */ +export function minColumnStart(grid: Grid): number; + +/** + * Finds the max column start of all grid areas. + * + * @param grid the grid to analyze. + * @returns the max column start. + */ +export function maxColumnStart(grid: Grid): number; + +/** + * Finds the min column end of all grid areas. + * + * @param grid the grid to analyze. + * @returns the min column end. + */ +export function minColumnEnd(grid: Grid): number; + +/** + * Finds the max column end of all grid areas. + * + * @param grid the grid to analyze. + * @returns the max column end. + */ +export function maxColumnEnd(grid: Grid): number; + +/** + * Finds the min row start of all grid areas. + * + * @param grid the grid to analyze. + * @returns the min row start. + */ +export function minRowStart(grid: Grid): number; + +/** + * Finds the max row start of all grid areas. + * + * @param grid the grid to analyze. + * @returns the max row start. + */ +export function maxRowStart(grid: Grid): number; + +/** + * Finds the min row end of all grid areas. + * + * @param grid the grid to analyze. + * @returns the min row end. + */ +export function minRowEnd(grid: Grid): number; + +/** + * Finds the max row end of all grid areas. + * + * @param grid the grid to analyze. + * @returns the max row end. + */ +export function maxRowEnd(grid: Grid): number; + +export interface Track { + start: number; + end: number; + span: number; +} + +export interface Area { + row: Track; + column: Track; +} + +export interface Rect { + x: number; + y: number; + width: number; + height: number; +} + +export interface Grid { + width: number; + height: number; + areas: { [key: string]: Area }; +} diff --git a/types/grid-template-parser/tsconfig.json b/types/grid-template-parser/tsconfig.json new file mode 100644 index 00000000000000..11a35a60c6d898 --- /dev/null +++ b/types/grid-template-parser/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "grid-template-parser-tests.ts" + ] +} diff --git a/types/grid-template-parser/tslint.json b/types/grid-template-parser/tslint.json new file mode 100644 index 00000000000000..3db14f85eaf7b9 --- /dev/null +++ b/types/grid-template-parser/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }