{"id":19115389,"url":"https://github.com/polytypic/prettier-printer","last_synced_at":"2025-04-30T23:10:49.597Z","repository":{"id":57330059,"uuid":"110429107","full_name":"polytypic/prettier-printer","owner":"polytypic","description":"A pretty printing library","archived":false,"fork":false,"pushed_at":"2019-01-06T08:27:05.000Z","size":282,"stargazers_count":24,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T09:33:45.939Z","etag":null,"topics":["pretty-printer","text"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polytypic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-12T12:04:20.000Z","updated_at":"2024-04-12T19:44:34.000Z","dependencies_parsed_at":"2022-08-29T05:11:08.708Z","dependency_job_id":null,"html_url":"https://github.com/polytypic/prettier-printer","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fprettier-printer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fprettier-printer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fprettier-printer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polytypic%2Fprettier-printer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polytypic","download_url":"https://codeload.github.com/polytypic/prettier-printer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251795415,"owners_count":21645023,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pretty-printer","text"],"created_at":"2024-11-09T04:46:14.779Z","updated_at":"2025-04-30T23:10:49.545Z","avatar_url":"https://github.com/polytypic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003ca id=\"prettier-printer\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#) [Prettier Printer](#prettier-printer) \u0026middot; [![GitHub stars](https://img.shields.io/github/stars/polytypic/prettier-printer.svg?style=social)](https://github.com/polytypic/prettier-printer) [![npm](https://img.shields.io/npm/dm/prettier-printer.svg)](https://www.npmjs.com/package/prettier-printer)\n\nA pretty printing library for text documents that can be rendered to a desired\nmaximum width.  Basic features:\n\n* Interactive documentation (the [▶ links](https://polytypic.github.io/prettier-printer/index.html))\n* Functional API:\n  * [Referentially transparent functions](https://en.wikipedia.org/wiki/Referential_transparency)\n  * [Curried functions](http://fr.umio.us/favoring-curry/)\n* [Supports tree-shaking](https://webpack.js.org/guides/tree-shaking/)\n* [TypeScript typings](./src/prettier-printer.d.ts)\n* [Contract checking in non-production builds](./src/prettier-printer.js)\n* [MIT license](./LICENSE.md)\n\nAs an example, the evaluation output in this live\n[CodeSandbox](https://codesandbox.io/s/8zo3ko95p2) example is formatted using\nthis library.\n\n[![npm version](https://badge.fury.io/js/prettier-printer.svg)](http://badge.fury.io/js/prettier-printer)\n[![Bower version](https://badge.fury.io/bo/prettier-printer.svg)](https://badge.fury.io/bo/prettier-printer)\n[![Build Status](https://travis-ci.org/polytypic/prettier-printer.svg?branch=master)](https://travis-ci.org/polytypic/prettier-printer)\n[![Code Coverage](https://img.shields.io/codecov/c/github/polytypic/prettier-printer/master.svg)](https://codecov.io/github/polytypic/prettier-printer?branch=master)\n[![](https://david-dm.org/polytypic/prettier-printer.svg)](https://david-dm.org/polytypic/prettier-printer) [![](https://david-dm.org/polytypic/prettier-printer/dev-status.svg)](https://david-dm.org/polytypic/prettier-printer?type=dev)\n\n## \u003ca id=\"contents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#contents) [Contents](#contents)\n\n* [Tutorial](#tutorial)\n* [Reference](#reference)\n  * [Rendering documents](#rendering-documents)\n    * [`PP.render(maxCols, doc) ~\u003e string`](#PP-render) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.renderWith({text: (state, string) =\u003e state, line: state =\u003e state}, state, maxCols, doc) ~\u003e state`](#PP-renderWith) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Document constants](#document-constants)\n    * [`PP.line ~\u003e doc`](#PP-line) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.lineBreak ~\u003e doc`](#PP-lineBreak) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.softLine ~\u003e doc`](#PP-softLine) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.softBreak ~\u003e doc`](#PP-softBreak) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Concatenating documents](#concatenating-documents)\n    * [`PP.append(rhsDoc, lhsDoc) ~\u003e doc`](#PP-append) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.prepend(lhsDoc, rhsDoc) ~\u003e doc`](#PP-prepend) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Lists of documents](#lists-of-documents)\n    * [`PP.intersperse(doc, [...docs]) ~\u003e [...docs]`](#PP-intersperse) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.punctuate(sepDoc, [...docs]) ~\u003e [...docs]`](#PP-punctuate) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Lazy documents](#lazy-documents)\n    * [`PP.lazy(() =\u003e doc) ~\u003e doc`](#PP-lazy) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Enclosing documents](#enclosing-documents)\n    * [`PP.enclose([lhsDoc, rhsDoc], doc) ~\u003e doc`](#PP-enclose) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [Document pair constants](#document-pair-constants)\n      * [`PP.angles ~\u003e ['\u003c', '\u003e']`](#PP-angles) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n      * [`PP.braces ~\u003e ['{', '}']`](#PP-braces) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n      * \u003ca href=\"#PP-brackets\"\u003e\u003ccode\u003ePP.brackets ~\u0026gt; ['[', ']']\u003c/code\u003e\u003c/a\u003e \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n      * [`PP.dquotes ~\u003e ['\"', '\"']`](#PP-dquotes) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n      * [`PP.lineBreaks ~\u003e [PP.lineBreak, PP.lineBreak]`](#PP-lineBreaks) \u003csmall\u003e\u003csup\u003ev1.1.0\u003c/sup\u003e\u003c/small\u003e\n      * [`PP.lines ~\u003e [PP.line, PP.line]`](#PP-lines) \u003csmall\u003e\u003csup\u003ev1.1.0\u003c/sup\u003e\u003c/small\u003e\n      * [`PP.parens ~\u003e ['(', ')']`](#PP-parens) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n      * [`PP.spaces ~\u003e [' ', ' ']`](#PP-spaces) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n      * [`PP.squotes ~\u003e [\"'\", \"'\"]`](#PP-squotes) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Alternative documents](#alternative-documents)\n    * [`PP.choice(wideDoc, narrowDoc) ~\u003e doc`](#PP-choice) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.group(doc) ~\u003e doc`](#PP-group) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Nested documents](#nested-documents)\n    * [`PP.nest(string | number, doc) ~\u003e doc`](#PP-nest) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Layout dependent documents](#layout-dependent-documents)\n    * [`PP.column(column =\u003e doc) ~\u003e doc`](#PP-column) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.nesting(nesting =\u003e doc) ~\u003e doc`](#PP-nesting) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n  * [Aligned documents](#aligned-documents)\n    * [`PP.align(doc) ~\u003e doc`](#PP-align) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.hang(string | number, doc) ~\u003e doc`](#PP-hang) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n    * [`PP.indent(string | number, doc) ~\u003e doc`](#PP-indent) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n* [Related Work](#related-work)\n\n## \u003ca id=\"tutorial\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#tutorial) [Tutorial](#tutorial)\n\nTo be done.\n\nIn the meanwhile, read Philip Wadler's paper [A prettier\nprinter](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf).\n\n## \u003ca id=\"reference\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#reference) [Reference](#reference)\n\nTypically one imports the library as:\n\n```jsx\nimport * as PP from 'prettier-printer'\n```\n\nThe examples also utilize [Ramda](http://ramdajs.com/), bound as `R`.\n\n### \u003ca id=\"rendering-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#rendering-documents) [Rendering documents](#rendering-documents)\n\n#### \u003ca id=\"PP-render\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-render) [`PP.render(maxCols, doc) ~\u003e string`](#PP-render) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.render` renders the document to a string trying to keep the width of the\ndocument within the specified maximum.  A width of `0` means that there is no\nmaximum.  See also [`PP.renderWith`](#PP-renderWith).\n\nFor example:\n\n```js\nPP.render(\n  10,\n  PP.indent('-- ', PP.group(PP.intersperse(PP.line, ['Hello,', 'world!'])))\n)\n// -- Hello,\n// -- world!\n```\n\n#### \u003ca id=\"PP-renderWith\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-renderWith) [`PP.renderWith({text: (state, string) =\u003e state, line: state =\u003e state}, state, maxCols, doc) ~\u003e state`](#PP-renderWith) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.renderWith` renders the document with the given actions `text` and `line`.\nYou can use this function to output the document without creating an\nintermediate string of the whole document.  See also [`PP.render`](#PP-render).\n\n### \u003ca id=\"document-constants\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#document-constants) [Document constants](#document-constants)\n\nAny string that doesn't contain `'\\n'` or `'\\r'` characters is considered as an\natomic document.  For example, `''` is an empty document and `' '` is a space.\n\n#### \u003ca id=\"PP-line\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-line) [`PP.line ~\u003e doc`](#PP-line) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.line` renders as a new line unless undone by [`PP.group`](#PP-group) in\nwhich case `PP.line` renders as a space.\n\nFor example:\n\n```js\nPP.render(20, ['Hello,', PP.line, 'world!'])\n// Hello,\n// world!\n```\n\n```js\nPP.render(20, PP.group(['Hello,', PP.line, 'world!']))\n// Hello, world!\n```\n\n#### \u003ca id=\"PP-lineBreak\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-lineBreak) [`PP.lineBreak ~\u003e doc`](#PP-lineBreak) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.lineBreak` renders as a new line unless undone by [`PP.group`](#PP-group) in\nwhich case `PP.lineBreak` renders as empty.\n\nFor example:\n\n```js\nPP.render(20, ['Lol', PP.lineBreak, 'Bal'])\n// Lol\n// Bal\n```\n\n```js\nPP.render(20, PP.group(['Lol', PP.lineBreak, 'Bal']))\n// LolBal\n```\n\n#### \u003ca id=\"PP-softLine\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-softLine) [`PP.softLine ~\u003e doc`](#PP-softLine) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.softLine` renders as a space if the output fits and otherwise as a new line.\n\nFor example:\n\n```js\nPP.render(\n  20,\n  PP.intersperse(\n    PP.softLine,\n    R.split(\n      /\\s+/,\n      'Here is a paragraph of text that we will format to a desired width.'\n    )\n  )\n)\n// Here is a paragraph\n// of text that we will\n// format to a desired\n// width.\n```\n\n#### \u003ca id=\"PP-softBreak\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-softBreak) [`PP.softBreak ~\u003e doc`](#PP-softBreak) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.softBreak` renders as empty if the output fits and otherwise as a new line.\n\nFor example:\n\n```js\nPP.render(10, PP.intersperse(PP.softBreak, R.split(/\\b/, 'this.method(rocks)')))\n// this.\n// method(\n// rocks)\n```\n\n### \u003ca id=\"concatenating-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#concatenating-documents) [Concatenating documents](#concatenating-documents)\n\nAn array of documents is considered as a concatenation of documents.  For\nexample, `[]` is an empty document and `['foo', 'bar']` is equivalent to\n`'foobar'`.\n\n#### \u003ca id=\"PP-append\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-append) [`PP.append(rhsDoc, lhsDoc) ~\u003e doc`](#PP-append) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.append` reverse concatenates the documents.\n\nFor example:\n\n```js\nPP.render(0, PP.append('bar', 'foo'))\n// foobar\n```\n\n#### \u003ca id=\"PP-prepend\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-prepend) [`PP.prepend(lhsDoc, rhsDoc) ~\u003e doc`](#PP-prepend) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.prepend` concatenates the documents.\n\nFor example:\n\n```js\nPP.render(0, PP.prepend('foo', 'bar'))\n// foobar\n```\n\n### \u003ca id=\"lists-of-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#lists-of-documents) [Lists of documents](#lists-of-documents)\n\n#### \u003ca id=\"PP-intersperse\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-intersperse) [`PP.intersperse(doc, [...docs]) ~\u003e [...docs]`](#PP-intersperse) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.intersperse` puts the given separator document between each document in the\ngiven list of documents.\n\nFor example:\n\n```js\nPP.intersperse(',', ['a', 'b', 'c'])\n// ['a', ',', 'b', ',', 'c']\n```\n\n#### \u003ca id=\"PP-punctuate\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-punctuate) [`PP.punctuate(sepDoc, [...docs]) ~\u003e [...docs]`](#PP-punctuate) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.punctuate` concatenates the given separator after each document in the given\nlist of documents except the last.\n\nFor example:\n\n```js\nPP.punctuate(',', ['a', 'b', 'c'])\n// [ [ 'a', ',' ], [ 'b', ',' ], 'c' ]\n```\n\n### \u003ca id=\"lazy-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#lazy-documents) [Lazy documents](#lazy-documents)\n\n#### \u003ca id=\"PP-lazy\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-lazy) [`PP.lazy(() =\u003e doc) ~\u003e doc`](#PP-lazy) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.lazy` creates a lazy document.  The given thunk is only invoked as needed to\ncompute the document.\n\n### \u003ca id=\"enclosing-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#enclosing-documents) [Enclosing documents](#enclosing-documents)\n\n#### \u003ca id=\"PP-enclose\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-enclose) [`PP.enclose([lhsDoc, rhsDoc], doc) ~\u003e doc`](#PP-enclose) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.enclose` encloses the given document between the given pair of documents.\n\nFor example:\n\n```js\nPP.render(0, PP.enclose(PP.parens, 'foo'))\n// (foo)\n```\n\n#### \u003ca id=\"document-pair-constants\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#document-pair-constants) [Document pair constants](#document-pair-constants)\n\n##### \u003ca id=\"PP-angles\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-angles) [`PP.angles ~\u003e ['\u003c', '\u003e']`](#PP-angles) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-braces\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-braces) [`PP.braces ~\u003e ['{', '}']`](#PP-braces) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-brackets\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-brackets) \u003ca href=\"#PP-brackets\"\u003e\u003ccode\u003ePP.brackets ~\u0026gt; ['[', ']']\u003c/code\u003e\u003c/a\u003e \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-dquotes\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-dquotes) [`PP.dquotes ~\u003e ['\"', '\"']`](#PP-dquotes) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-lineBreaks\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-lineBreaks) [`PP.lineBreaks ~\u003e [PP.lineBreak, PP.lineBreak]`](#PP-lineBreaks) \u003csmall\u003e\u003csup\u003ev1.1.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-lines\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-lines) [`PP.lines ~\u003e [PP.line, PP.line]`](#PP-lines) \u003csmall\u003e\u003csup\u003ev1.1.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-parens\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-parens) [`PP.parens ~\u003e ['(', ')']`](#PP-parens) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-spaces\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-spaces) [`PP.spaces ~\u003e [' ', ' ']`](#PP-spaces) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n##### \u003ca id=\"PP-squotes\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-squotes) [`PP.squotes ~\u003e [\"'\", \"'\"]`](#PP-squotes) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n### \u003ca id=\"alternative-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#alternative-documents) [Alternative documents](#alternative-documents)\n\n#### \u003ca id=\"PP-choice\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-choice) [`PP.choice(wideDoc, narrowDoc) ~\u003e doc`](#PP-choice) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.choice(wideDoc, narrowDoc)` renders as the given `wideDoc` on a line if it\nfits within the maximum width and otherwise as the `narrowDoc`.\n[`PP.line`](#PP-line)s and [`PP.lineBreak`](#PP-lineBreak)s within the `wideDoc`\nare undone like with [`PP.group`](#PP-group).\n\nFor example:\n\n```js\nPP.render(5, PP.choice('wide', 'narrow'))\n// 'wide'\n```\n\n```js\nPP.render(3, PP.choice('wide', 'narrow'))\n// 'narrow'\n```\n\nNote that usually the idea is that the narrow version can indeed be rendered\nmore narrowly.\n\nFor example:\n\n```js\nconst hyphen = PP.choice('', ['-', PP.lineBreak])\n\nPP.render(5, PP.intersperse(hyphen, ['hy', 'phen', 'at', 'ed']))\n// hy-\n// phen-\n// ated\n```\n\n#### \u003ca id=\"PP-group\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-group) [`PP.group(doc) ~\u003e doc`](#PP-group) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.group` allows [`PP.line`](#PP-line)s and [`PP.lineBreak`](#PP-lineBreak)s\nwithin the given document to be undone if the result fits within the maximum\nwidth.  `PP.group(doc)` is equivalent to [`PP.choice(doc, doc)`](#PP-choice).\n\n### \u003ca id=\"nested-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#nested-documents) [Nested documents](#nested-documents)\n\n#### \u003ca id=\"PP-nest\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-nest) [`PP.nest(string | number, doc) ~\u003e doc`](#PP-nest) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.nest` increases the nesting after next new line by the given string or by\nthe given number of spaces.\n\nFor example:\n\n```js\nPP.render(6, PP.nest(2, PP.group(PP.intersperse(PP.line, ['foo', 'bar']))))\n// foo\n//   bar\n```\n\n### \u003ca id=\"layout-dependent-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#layout-dependent-documents) [Layout dependent documents](#layout-dependent-documents)\n\n#### \u003ca id=\"PP-column\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-column) [`PP.column(column =\u003e doc) ~\u003e doc`](#PP-column) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.column` allows a document to depend on the column at which the document\nstarts.\n\n#### \u003ca id=\"PP-nesting\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-nesting) [`PP.nesting(nesting =\u003e doc) ~\u003e doc`](#PP-nesting) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.nesting` allows a document to depend on the nesting after the next new line.\n\n### \u003ca id=\"aligned-documents\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#aligned-documents) [Aligned documents](#aligned-documents)\n\n#### \u003ca id=\"PP-align\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-align) [`PP.align(doc) ~\u003e doc`](#PP-align) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.align` creates a document such that the nesting of the document is aligned\nto the current column.\n\nFor example:\n\n```js\nPP.render(10, PP.group(['foo(', PP.align(['bar,', PP.line, 'baz']), ')']))\n// foo(bar,\n//     baz)\n```\n\n#### \u003ca id=\"PP-hang\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-hang) [`PP.hang(string | number, doc) ~\u003e doc`](#PP-hang) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.hang` creates a document such that the document is nested by the given\nstring or number of spaces starting from the current column.\n\nFor example:\n\n```js\nPP.render(10, PP.group(['foo(', PP.hang(2, ['bar,', PP.line, 'baz']), ')']))\n// foo(bar,\n//       baz)\n```\n\n#### \u003ca id=\"PP-indent\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#PP-indent) [`PP.indent(string | number, doc) ~\u003e doc`](#PP-indent) \u003csmall\u003e\u003csup\u003ev1.0.0\u003c/sup\u003e\u003c/small\u003e\n\n`PP.indent` creates a document such that the document is indented by the given\nprefix or number of spaces starting from the current column.\n\n```js\nPP.render(\n  20,\n  PP.nest(\n    2,\n    PP.group([\n      'A comment:',\n      PP.line,\n      PP.line,\n      PP.indent(\n        '-- ',\n        PP.intersperse(\n          PP.softLine,\n          R.split(/\\s+/, 'This is the comment that you are looking for.')\n        )\n      )\n    ])\n  )\n)\n// A comment:\n// \n//   -- This is the\n//   -- comment that\n//   -- you are looking\n//   -- for.\n```\n\n## \u003ca id=\"related-work\"\u003e\u003c/a\u003e [≡](#contents) [▶](https://polytypic.github.io/prettier-printer/index.html#related-work) [Related Work](#related-work)\n\n* Philip Wadler's paper [A prettier\n  printer](https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf)\n  describes the basic ideas and implementation.\n* [Text.PrettyPrint.Leijen](https://hackage.haskell.org/package/wl-pprint-1.2/docs/Text-PrettyPrint-Leijen.html)\n  is Daan Leijen's implementation with some extensions.\n* Other prettier printer implementations by the author of this library:\n  * [prettier](https://github.com/MLton/mltonlib/tree/master/com/ssh/prettier/unstable)\n  * [PPrint](https://github.com/polytypic/PPrint)\n* [text.pretty-printing](https://github.com/folktale/text.pretty-printing)\n  another JS implementation based on Wadler's paper.  Marked as\n  \"[Unmaintained]\".\n* [Prettier](https://prettier.io/) uses a similar pretty printing library\n  underneath.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolytypic%2Fprettier-printer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolytypic%2Fprettier-printer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolytypic%2Fprettier-printer/lists"}