add wordWrap and trim options for wrap-ansi v3

This commit is contained in:
Daniel Imhoff
2018-03-23 14:48:30 -05:00
parent 53a0bb67c2
commit 9363c54fa9
6 changed files with 139 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for wrap-ansi v2.0.0
// Type definitions for wrap-ansi v3.0.0
// Project: https://www.npmjs.com/package/wrap-ansi
// Definitions by: Klaus Reimer <https://github.com/kayahr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -12,7 +12,7 @@
* @param options By default the wrap is soft, meaning long words may extend past the column width. Setting
* this to true will make it hard wrap at the column width.
*/
declare function wrapAnsi(input: string, columns: number, options?: { hard?: boolean }): string;
declare function wrapAnsi(input: string, columns: number, options?: { hard?: boolean; trim?: boolean; wordWrap?: boolean; }): string;
declare namespace wrapAnsi {}

20
types/wrap-ansi/v2/index.d.ts vendored Normal file
View File

@@ -0,0 +1,20 @@
// Type definitions for wrap-ansi v2.0.0
// Project: https://www.npmjs.com/package/wrap-ansi
// Definitions by: Klaus Reimer <https://github.com/kayahr>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Wrap words to the specified column width.
*
* @param input String with ANSI escape codes. Like one styled by chalk.
* @param columns Number of columns to wrap the text to.
* @param options By default the wrap is soft, meaning long words may extend past the column width. Setting
* this to true will make it hard wrap at the column width.
*/
declare function wrapAnsi(input: string, columns: number, options?: { hard?: boolean }): string;
declare namespace wrapAnsi {}
export = wrapAnsi;

View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"baseUrl": "../../",
"typeRoots": [
"../../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"wrap-ansi": ["wrap-ansi/v2"]
}
},
"files": [
"index.d.ts",
"wrap-ansi-tests.ts"
]
}

View File

@@ -0,0 +1,79 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}

View File

@@ -0,0 +1,8 @@
import wrapAnsi = require("wrap-ansi");
wrapAnsi("input", 80) === "output";
wrapAnsi("input", 80, {}) === "output";
wrapAnsi("input", 80, { hard: true }) === "output";
wrapAnsi("input", 80, { hard: false }) === "output";

View File

@@ -6,3 +6,7 @@ wrapAnsi("input", 80) === "output";
wrapAnsi("input", 80, {}) === "output";
wrapAnsi("input", 80, { hard: true }) === "output";
wrapAnsi("input", 80, { hard: false }) === "output";
wrapAnsi("input", 80, { trim: true }) === "output";
wrapAnsi("input", 80, { trim: false }) === "output";
wrapAnsi("input", 80, { wordWrap: true }) === "output";
wrapAnsi("input", 80, { wordWrap: false }) === "output";