mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-05 17:50:03 +00:00
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:
37
types/align-text/index.d.ts
vendored
Normal file
37
types/align-text/index.d.ts
vendored
Normal 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;
|
||||
12
types/align-text/test/center-complex.ts
Normal file
12
types/align-text/test/center-complex.ts
Normal 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);
|
||||
8
types/align-text/test/center-simple.ts
Normal file
8
types/align-text/test/center-simple.ts
Normal 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);
|
||||
6
types/align-text/test/simple.ts
Normal file
6
types/align-text/test/simple.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import align from "align-text";
|
||||
|
||||
const text = ["abc", "abc", "abc"];
|
||||
align(text, 4);
|
||||
|
||||
align("abc", 2);
|
||||
22
types/align-text/tsconfig.json
Normal file
22
types/align-text/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/align-text/tslint.json
Normal file
1
types/align-text/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user