UNPKG

@parischap/pretty-print

Version:
128 lines (126 loc) 4.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toUnstyledStrings = exports.toSingleLine = exports.toLength = exports.toAnsiString = exports.prependToTailLines = exports.prependToFirstLine = exports.prependToAllLines = exports.isNotEmpty = exports.isEmpty = exports.fromText = exports.fromStringifiedProperties = exports.equivalence = exports.empty = exports.appendToLastLine = exports.addLineBefore = exports.addLineAfter = void 0; var _ansiStyles = /*#__PURE__*/require("@parischap/ansi-styles"); var _effectLib = /*#__PURE__*/require("@parischap/effect-lib"); var _effect = /*#__PURE__*/require("effect"); /** * Type that represents the output of the stringification process of a value. It is in fact an alias * for an array of ASText's (see Text.ts in @parischap/ansi-styles). Each elament of the array * represents a line of the stringified value. There must always be at least one line. But that line * may contain en empty text. */ /** * Equivalence for StringifiedValue's. To be removed when Equal.equals will handle Arrays properly * (from Effect 4.0 onwards) * * @category Equivalences */ const equivalence = exports.equivalence = /*#__PURE__*/_effect.Array.getEquivalence(_ansiStyles.ASText.equivalence); /** * Builds a StringifiedValue from a Text * * @category Constructors */ const fromText = exports.fromText = _effect.Array.of; /** * Empty StringifiedValue instance * * @category Instances */ const empty = exports.empty = /*#__PURE__*/(0, _effect.pipe)(_ansiStyles.ASText.empty, fromText); /** * Builds a StringifiedValue from a StringifiedProperties * * @category Constructors */ const fromStringifiedProperties = exports.fromStringifiedProperties = /*#__PURE__*/_effect.Array.match({ onEmpty: /*#__PURE__*/_effect.Function.constant(empty), onNonEmpty: _effect.Array.flatten }); /** * Returns a single-line version of `self` * * @category Utils */ const toSingleLine = exports.toSingleLine = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/_ansiStyles.ASText.join(_ansiStyles.ASText.empty), fromText); /** * Returns `true` if `self` is empty. * * @category Predicates */ const isEmpty = exports.isEmpty = /*#__PURE__*/_effectLib.MArray.match012({ onEmpty: _effect.Function.constTrue, onSingleton: _ansiStyles.ASText.isEmpty, onOverTwo: _effect.Function.constFalse }); /** * Returns `true` if `self` is not empty. * * @category Predicates */ const isNotEmpty = exports.isNotEmpty = /*#__PURE__*/_effect.Predicate.not(isEmpty); /** * Returns a copy of `self` with a new line at the end * * @category Utils */ const addLineAfter = line => _effect.Array.append(line); /** * Returns a copy of `self` with a new line at the start * * @category Utils */ exports.addLineAfter = addLineAfter; const addLineBefore = line => _effect.Array.prepend(line); /** * Returns a copy of `self` in which `text` has been prepended to each line * * @category Utils */ exports.addLineBefore = addLineBefore; const prependToAllLines = text => _effect.Array.map(_ansiStyles.ASText.prepend(text)); /** * Returns a copy of `self` in which `text` has been appended to the last line * * @category Utils */ exports.prependToAllLines = prependToAllLines; const appendToLastLine = text => _effect.Array.modifyNonEmptyLast(_ansiStyles.ASText.append(text)); /** * Returns a copy of `self` in which `text` has been prepended to the first line * * @category Utils */ exports.appendToLastLine = appendToLastLine; const prependToFirstLine = text => _effect.Array.modifyNonEmptyHead(_ansiStyles.ASText.prepend(text)); /** * Returns a copy of `self` in which `text` has been prepended to all lines but the first * * @category Utils */ exports.prependToFirstLine = prependToFirstLine; const prependToTailLines = text => _effectLib.MArray.modifyTail(_ansiStyles.ASText.prepend(text)); /** * Returns the length of `self` * * @category Destructors */ exports.prependToTailLines = prependToTailLines; const toLength = exports.toLength = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/_effect.Array.map(_ansiStyles.ASText.toLength), _effect.Number.sumAll); /** * Returns the ANSI string corresponding to `self` * * @category Destructors */ const toAnsiString = (sep = _ansiStyles.ASText.lineBreak) => (0, _effect.flow)(_ansiStyles.ASText.join(sep), _ansiStyles.ASText.toAnsiString); /** * Returns the stringq corresponding to `self` without any styling * * @category Destructors */ exports.toAnsiString = toAnsiString; const toUnstyledStrings = exports.toUnstyledStrings = /*#__PURE__*/_effect.Array.map(_ansiStyles.ASText.toUnstyledString); //# sourceMappingURL=StringifiedValue.js.map