From 763a15fa60b835ff44cc8f2b4bbb412cede8a428 Mon Sep 17 00:00:00 2001 From: Claas Ahlrichs Date: Mon, 25 Mar 2019 18:11:39 +0100 Subject: [PATCH] new package: align-text (#34158) * npx dts-gen -m align-text --dt * drafted types for align-text * drafted test cases * npx prettier --write .\types\align-text\** * fixed linting issues --- types/align-text/index.d.ts | 37 +++++++++++++++++++++++++ types/align-text/test/center-complex.ts | 12 ++++++++ types/align-text/test/center-simple.ts | 8 ++++++ types/align-text/test/simple.ts | 6 ++++ types/align-text/tsconfig.json | 22 +++++++++++++++ types/align-text/tslint.json | 1 + 6 files changed, 86 insertions(+) create mode 100644 types/align-text/index.d.ts create mode 100644 types/align-text/test/center-complex.ts create mode 100644 types/align-text/test/center-simple.ts create mode 100644 types/align-text/test/simple.ts create mode 100644 types/align-text/tsconfig.json create mode 100644 types/align-text/tslint.json diff --git a/types/align-text/index.d.ts b/types/align-text/index.d.ts new file mode 100644 index 0000000000..652eb5f453 --- /dev/null +++ b/types/align-text/index.d.ts @@ -0,0 +1,37 @@ +// Type definitions for align-text 1.0 +// Project: https://github.com/jonschlinkert/align-text +// Definitions by: Claas Ahlrichs +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +interface TransformResult { + /** + * the amount of indentation to use. Default is 0 when an object is returned. + */ + indent: number; + /** + * the character to use for indentation. Default is '' (empty string) when an object is returned. + */ + character: string; + /** + * leading characters to use at the beginning of each line. '' (empty string) when an object is returned. + */ + prefix: string; +} + +interface Callback { + /** + * @param len the length of the "current" line + * @param longest the length of the longest line + * @param line the current line (string) being aligned + * @param lines the array of all lines + */ + (len: number, longest: number, line: string, lines: string[]): + | number + | TransformResult; +} + +declare function align_text(text: string, fn: number | Callback): string; +declare function align_text(text: string[], fn: number | Callback): string[]; + +export = align_text; diff --git a/types/align-text/test/center-complex.ts b/types/align-text/test/center-complex.ts new file mode 100644 index 0000000000..8520f92583 --- /dev/null +++ b/types/align-text/test/center-complex.ts @@ -0,0 +1,12 @@ +import align from "align-text"; + +function centerAlign(len: number, longest: number) { + return { + character: "\t", + indent: Math.floor((longest - len) / 2), + prefix: "~ " + }; +} + +const text = ["abc", "abc", "abc"]; +align(text, centerAlign); diff --git a/types/align-text/test/center-simple.ts b/types/align-text/test/center-simple.ts new file mode 100644 index 0000000000..5400551b81 --- /dev/null +++ b/types/align-text/test/center-simple.ts @@ -0,0 +1,8 @@ +import align from "align-text"; + +function centerAlign(len: number, longest: number) { + return Math.floor((longest - len) / 2); +} + +const text = ["abc", "abc", "abc"]; +align(text, centerAlign); diff --git a/types/align-text/test/simple.ts b/types/align-text/test/simple.ts new file mode 100644 index 0000000000..0571e5aad0 --- /dev/null +++ b/types/align-text/test/simple.ts @@ -0,0 +1,6 @@ +import align from "align-text"; + +const text = ["abc", "abc", "abc"]; +align(text, 4); + +align("abc", 2); diff --git a/types/align-text/tsconfig.json b/types/align-text/tsconfig.json new file mode 100644 index 0000000000..5184832b59 --- /dev/null +++ b/types/align-text/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "allowSyntheticDefaultImports": true + }, + "files": [ + "index.d.ts", + "test/simple.ts", + "test/center-simple.ts", + "test/center-complex.ts" + ] +} diff --git a/types/align-text/tslint.json b/types/align-text/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/align-text/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }