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
This commit is contained in:
Claas Ahlrichs
2019-03-25 18:11:39 +01:00
committed by timolinn
parent 541feb9ac3
commit 763a15fa60
6 changed files with 86 additions and 0 deletions

37
types/align-text/index.d.ts vendored Normal file
View File

@@ -0,0 +1,37 @@
// Type definitions for align-text 1.0
// Project: https://github.com/jonschlinkert/align-text
// Definitions by: Claas Ahlrichs <https://github.com/claasahl>
// 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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -0,0 +1,6 @@
import align from "align-text";
const text = ["abc", "abc", "abc"];
align(text, 4);
align("abc", 2);

View File

@@ -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"
]
}

View File

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