UNPKG

977 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.wordWrap = exports.indent = exports.TTY_WIDTH = exports.stripAnsi = exports.stringWidth = exports.sliceAnsi = void 0;
4const sliceAnsi = require("slice-ansi");
5exports.sliceAnsi = sliceAnsi;
6const stringWidth = require("string-width");
7exports.stringWidth = stringWidth;
8const stripAnsi = require("strip-ansi");
9exports.stripAnsi = stripAnsi;
10const wrapAnsi = require("wrap-ansi");
11const MIN_TTY_WIDTH = 80;
12const MAX_TTY_WIDTH = 120;
13exports.TTY_WIDTH = process.stdout.columns ? Math.max(MIN_TTY_WIDTH, Math.min(process.stdout.columns, MAX_TTY_WIDTH)) : Infinity;
14function indent(n = 4) {
15 return ' '.repeat(n);
16}
17exports.indent = indent;
18function wordWrap(msg, { width = exports.TTY_WIDTH, indentation = 0, append = '' }) {
19 return wrapAnsi(msg, width - indentation - append.length, { trim: true }).split('\n').join(`${append}\n${indent(indentation)}`);
20}
21exports.wordWrap = wordWrap;