@parischap/pretty-print
Version:
A functional library to pretty-print and treeify objects
64 lines • 2.85 kB
JavaScript
/**
* Type that is an alias for an array of StringifiedValue's (see StringifiedValue.ts). It represents
* the output of the stringification process of the properties of a non-primitive value.
*/
import { MArray } from '@parischap/effect-lib';
import { Array, flow, Function, Number, Order } from 'effect';
import * as PPStringifiedValue from './StringifiedValue.js';
/**
* Return a copy of `self` with a mark added at the end of each stringified property except the last
* one
*
* @category Utils
*/
export const addMarkInBetween = mark => flow(MArray.modifyInit(PPStringifiedValue.appendToLastLine(mark)));
/**
* Return a copy of `self` with `property` added as a single-line StringifiedValue at the start
*
* @category Utils
*/
export const prependProperty = property => Array.prepend(PPStringifiedValue.fromText(property));
/**
* Return a copy of `self` with `property` added as a single-line StringifiedValue at the end
*
* @category Utils
*/
export const appendProperty = property => Array.append(PPStringifiedValue.fromText(property));
/**
* Returns a copy of `self` in which each stringified property has been tabified with `tab`
*
* @category Utils
*/
export const tabify = tab => Array.map(PPStringifiedValue.prependToAllLines(tab));
/**
* Returns a copy of `self` in which `treeIndentForFirstLineOfInitProps` has been prepended to the
* first line of all properties but the last, `treeIndentForTailsLinesOfInitProps` has been
* prepended to all the lines but the first of all properties but the last,
* `treeIndentForFirstLineOfLastProp` has been prepended to the first line of the last property, and
* `treeIndentForTailLinesOfLastProp` has been prepended to all the lines but the first of last
* property.
*
* @category Utils
*/
export const treeify = ({
treeIndentForFirstLineOfInitProps,
treeIndentForTailLinesOfInitProps,
treeIndentForFirstLineOfLastProp,
treeIndentForTailLinesOfLastProp
}) => flow(MArray.modifyInit(flow(PPStringifiedValue.prependToFirstLine(treeIndentForFirstLineOfInitProps), PPStringifiedValue.prependToTailLines(treeIndentForTailLinesOfInitProps))), MArray.modifyLast(flow(PPStringifiedValue.prependToFirstLine(treeIndentForFirstLineOfLastProp), PPStringifiedValue.prependToTailLines(treeIndentForTailLinesOfLastProp))));
/**
* Returns the length of `self`
*
* @category Destructors
*/
export const toLength = /*#__PURE__*/flow(/*#__PURE__*/Array.map(PPStringifiedValue.toLength), Number.sumAll);
/**
* Returns the length of the longest property of `self`
*
* @category Destructors
*/
export const toLongestPropLength = /*#__PURE__*/flow(/*#__PURE__*/Array.map(PPStringifiedValue.toLength), /*#__PURE__*/Array.match({
onEmpty: /*#__PURE__*/Function.constant(0),
onNonEmpty: /*#__PURE__*/Array.max(Order.number)
}));
//# sourceMappingURL=StringifiedProperties.js.map