UNPKG

@parischap/pretty-print

Version:
101 lines (99 loc) 4.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.treeify = exports.toLongestPropLength = exports.toLength = exports.tabify = exports.prependProperty = exports.appendProperty = exports.addMarkInBetween = void 0; var _effectLib = /*#__PURE__*/require("@parischap/effect-lib"); var _effect = /*#__PURE__*/require("effect"); var PPStringifiedValue = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./StringifiedValue.js")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * 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. */ /** * Return a copy of `self` with a mark added at the end of each stringified property except the last * one * * @category Utils */ const addMarkInBetween = mark => (0, _effect.flow)(_effectLib.MArray.modifyInit(PPStringifiedValue.appendToLastLine(mark))); /** * Return a copy of `self` with `property` added as a single-line StringifiedValue at the start * * @category Utils */ exports.addMarkInBetween = addMarkInBetween; const prependProperty = property => _effect.Array.prepend(PPStringifiedValue.fromText(property)); /** * Return a copy of `self` with `property` added as a single-line StringifiedValue at the end * * @category Utils */ exports.prependProperty = prependProperty; const appendProperty = property => _effect.Array.append(PPStringifiedValue.fromText(property)); /** * Returns a copy of `self` in which each stringified property has been tabified with `tab` * * @category Utils */ exports.appendProperty = appendProperty; const tabify = tab => _effect.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 */ exports.tabify = tabify; const treeify = ({ treeIndentForFirstLineOfInitProps, treeIndentForTailLinesOfInitProps, treeIndentForFirstLineOfLastProp, treeIndentForTailLinesOfLastProp }) => (0, _effect.flow)(_effectLib.MArray.modifyInit((0, _effect.flow)(PPStringifiedValue.prependToFirstLine(treeIndentForFirstLineOfInitProps), PPStringifiedValue.prependToTailLines(treeIndentForTailLinesOfInitProps))), _effectLib.MArray.modifyLast((0, _effect.flow)(PPStringifiedValue.prependToFirstLine(treeIndentForFirstLineOfLastProp), PPStringifiedValue.prependToTailLines(treeIndentForTailLinesOfLastProp)))); /** * Returns the length of `self` * * @category Destructors */ exports.treeify = treeify; const toLength = exports.toLength = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/_effect.Array.map(PPStringifiedValue.toLength), _effect.Number.sumAll); /** * Returns the length of the longest property of `self` * * @category Destructors */ const toLongestPropLength = exports.toLongestPropLength = /*#__PURE__*/(0, _effect.flow)(/*#__PURE__*/_effect.Array.map(PPStringifiedValue.toLength), /*#__PURE__*/_effect.Array.match({ onEmpty: /*#__PURE__*/_effect.Function.constant(0), onNonEmpty: /*#__PURE__*/_effect.Array.max(_effect.Order.number) })); //# sourceMappingURL=StringifiedProperties.js.map