{"_id":"esformatter-collapse-objects","_rev":"147968","name":"esformatter-collapse-objects","description":"esformatter plugin: conditionally collapses objects and array literals","dist-tags":{"latest":"0.5.1"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"time":{"modified":"2021-06-03T11:30:46.000Z","created":"2015-03-30T06:07:29.996Z","0.5.1":"2015-09-26T05:42:28.073Z","0.5.0":"2015-09-19T02:30:48.505Z","0.4.1":"2015-06-08T22:45:09.288Z","0.4.0":"2015-04-24T06:24:34.528Z","0.3.0":"2015-04-23T22:40:44.546Z","0.2.0":"2015-04-22T17:55:58.475Z","0.1.0":"2015-03-30T06:07:29.996Z"},"users":{},"repository":{"type":"git","url":"git+https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"versions":{"0.5.1":{"name":"esformatter-collapse-objects","version":"0.5.1","description":"esformatter plugin: conditionally collapses objects and array literals","main":"index.js","scripts":{"test":"mocha --ui bdd --reporter spec test"},"repository":{"type":"git","url":"git+https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"keywords":["esformatter","esformatter-plugin","string","AST"],"license":"MIT","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","devDependencies":{"mocha":"https://github.com/millermedeiros/mocha/tarball/latest","chai":"^1.4","esformatter":"^0.6.1"},"dependencies":{"defaults-deep":"^0.2.1","rocambole":"^0.5.1","rocambole-token":"^1.2.1","rocambole-whitespace":"^1.0.0"},"gitHead":"9d6ad0bbb2865a92093e85dbe571c248c42ae9d4","_id":"esformatter-collapse-objects@0.5.1","_shasum":"78b5c130b31f60f6cf4b0711fb80581691a66a78","_from":".","_npmVersion":"3.3.4","_nodeVersion":"4.0.0","_npmUser":{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"},"dist":{"shasum":"78b5c130b31f60f6cf4b0711fb80581691a66a78","size":6613,"noattachment":false,"key":"/esformatter-collapse-objects/-/esformatter-collapse-objects-0.5.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/esformatter-collapse-objects/download/esformatter-collapse-objects-0.5.1.tgz"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"directories":{},"publish_time":1443246148073,"_cnpm_publish_time":1443246148073,"_hasShrinkwrap":false},"0.5.0":{"name":"esformatter-collapse-objects","version":"0.5.0","description":"esformatter plugin: conditionally collapses objects and array literals","main":"index.js","scripts":{"test":"mocha --ui bdd --reporter spec test"},"repository":{"type":"git","url":"git+https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"keywords":["esformatter","esformatter-plugin","string","AST"],"license":"MIT","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","devDependencies":{"mocha":"https://github.com/millermedeiros/mocha/tarball/latest","chai":"^1.4","esformatter":"^0.6.1"},"dependencies":{"defaults-deep":"^0.2.1","rocambole":"^0.5.1","rocambole-token":"^1.2.1","rocambole-whitespace":"^1.0.0"},"gitHead":"9538d220e05ce908781a86a90514dcc079cec077","_id":"esformatter-collapse-objects@0.5.0","_shasum":"dd300a766d0467d3ce09dfa871910d064110e1df","_from":".","_npmVersion":"3.3.4","_nodeVersion":"4.0.0","_npmUser":{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"},"dist":{"shasum":"dd300a766d0467d3ce09dfa871910d064110e1df","size":6396,"noattachment":false,"key":"/esformatter-collapse-objects/-/esformatter-collapse-objects-0.5.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/esformatter-collapse-objects/download/esformatter-collapse-objects-0.5.0.tgz"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"directories":{},"publish_time":1442629848505,"_cnpm_publish_time":1442629848505,"_hasShrinkwrap":false},"0.4.1":{"name":"esformatter-collapse-objects","version":"0.4.1","description":"esformatter plugin: conditionally collapses objects and array literals","main":"index.js","scripts":{"test":"mocha --ui bdd --reporter spec test"},"repository":{"type":"git","url":"git+https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"keywords":["esformatter","esformatter-plugin","string","AST"],"license":"MIT","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","devDependencies":{"mocha":"https://github.com/millermedeiros/mocha/tarball/latest","chai":"^1.4","esformatter":"^0.6.1"},"dependencies":{"defaults-deep":"^0.2.1","rocambole":"^0.5.1","rocambole-token":"^1.2.1","rocambole-whitespace":"^1.0.0"},"gitHead":"8c3db1bd87ac2be0482a4440c3c8b5514316a2aa","_id":"esformatter-collapse-objects@0.4.1","_shasum":"9cb6fff12b032fb8d5c6fc96b2f27abe43d74618","_from":".","_npmVersion":"2.11.0","_nodeVersion":"2.2.1","_npmUser":{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"},"dist":{"shasum":"9cb6fff12b032fb8d5c6fc96b2f27abe43d74618","size":6352,"noattachment":false,"key":"/esformatter-collapse-objects/-/esformatter-collapse-objects-0.4.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/esformatter-collapse-objects/download/esformatter-collapse-objects-0.4.1.tgz"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"directories":{},"publish_time":1433803509288,"_cnpm_publish_time":1433803509288,"_hasShrinkwrap":false},"0.4.0":{"name":"esformatter-collapse-objects","version":"0.4.0","description":"esformatter plugin: conditionally collapses objects and array literals","main":"index.js","scripts":{"test":"mocha --ui bdd --reporter spec test"},"repository":{"type":"git","url":"git+https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"keywords":["esformatter","string","AST"],"license":"MIT","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","devDependencies":{"mocha":"https://github.com/millermedeiros/mocha/tarball/latest","chai":"^1.4","esformatter":"^0.6.1"},"dependencies":{"defaults-deep":"^0.2.1","rocambole":"^0.5.1","rocambole-token":"^1.2.1","rocambole-whitespace":"^1.0.0"},"gitHead":"3568fe82747d54a6a80b750581289f01b597a6d4","_id":"esformatter-collapse-objects@0.4.0","_shasum":"5be1b97e5cad18cdfa8f39198ec6a6525e2d765c","_from":".","_npmVersion":"2.8.4","_nodeVersion":"1.6.3","_npmUser":{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"dist":{"shasum":"5be1b97e5cad18cdfa8f39198ec6a6525e2d765c","size":6340,"noattachment":false,"key":"/esformatter-collapse-objects/-/esformatter-collapse-objects-0.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/esformatter-collapse-objects/download/esformatter-collapse-objects-0.4.0.tgz"},"directories":{},"publish_time":1429856674528,"_cnpm_publish_time":1429856674528,"_hasShrinkwrap":false},"0.3.0":{"name":"esformatter-collapse-objects","version":"0.3.0","description":"esformatter plugin: conditionally collapses objects and array literals","main":"index.js","scripts":{"test":"mocha --ui bdd --reporter spec test"},"repository":{"type":"git","url":"git+https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"keywords":["esformatter","string","AST"],"license":"MIT","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","devDependencies":{"mocha":"https://github.com/millermedeiros/mocha/tarball/latest","chai":"^1.4","esformatter":"^0.6.1"},"dependencies":{"defaults-deep":"^0.2.1","rocambole":"^0.5.1","rocambole-token":"^1.2.1","rocambole-whitespace":"^1.0.0"},"gitHead":"1dd870ed165d2bd5c0dd522885a4b233f3173cd1","_id":"esformatter-collapse-objects@0.3.0","_shasum":"6cf6a300433c6ce9b71193057bff275e0a8a9b9b","_from":".","_npmVersion":"2.8.4","_nodeVersion":"1.6.3","_npmUser":{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"dist":{"shasum":"6cf6a300433c6ce9b71193057bff275e0a8a9b9b","size":5647,"noattachment":false,"key":"/esformatter-collapse-objects/-/esformatter-collapse-objects-0.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/esformatter-collapse-objects/download/esformatter-collapse-objects-0.3.0.tgz"},"directories":{},"publish_time":1429828844546,"_cnpm_publish_time":1429828844546,"_hasShrinkwrap":false},"0.2.0":{"name":"esformatter-collapse-objects","version":"0.2.0","description":"esformatter plugin: conditionally collapses objects and array literals","main":"index.js","scripts":{"test":"mocha --ui bdd --reporter spec test"},"repository":{"type":"git","url":"git+https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"keywords":["esformatter","string","AST"],"license":"MIT","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","devDependencies":{"mocha":"https://github.com/millermedeiros/mocha/tarball/latest","chai":"^1.4","esformatter":"^0.6.1"},"dependencies":{"defaults-deep":"^0.2.1","rocambole":"^0.5.1","rocambole-token":"^1.2.1","rocambole-whitespace":"^1.0.0"},"gitHead":"35804bb32e4ba2ab83f694718a3cdc66eb1b5746","_id":"esformatter-collapse-objects@0.2.0","_shasum":"47caa268444a8bf54ff885b1bafa5dea22830857","_from":".","_npmVersion":"2.8.4","_nodeVersion":"1.6.3","_npmUser":{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"dist":{"shasum":"47caa268444a8bf54ff885b1bafa5dea22830857","size":5630,"noattachment":false,"key":"/esformatter-collapse-objects/-/esformatter-collapse-objects-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/esformatter-collapse-objects/download/esformatter-collapse-objects-0.2.0.tgz"},"directories":{},"publish_time":1429725358475,"_cnpm_publish_time":1429725358475,"_hasShrinkwrap":false},"0.1.0":{"name":"esformatter-collapse-objects","version":"0.1.0","description":"esformatter plugin: conditionally collapses objects and array literals","main":"index.js","scripts":{"test":"mocha --ui bdd --reporter spec test"},"repository":{"type":"git","url":"https://github.com/wbinnssmith/esformatter-collapse-objects.git"},"keywords":["esformatter","string","AST"],"license":"MIT","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","devDependencies":{"mocha":"https://github.com/millermedeiros/mocha/tarball/latest","chai":"^1.4","esformatter":"^0.6.1"},"dependencies":{"defaults-deep":"^0.2.1","rocambole":"^0.5.1","rocambole-token":"^1.2.1"},"gitHead":"f464c44eea0101125c5b1b487eccd816324d3836","_id":"esformatter-collapse-objects@0.1.0","_shasum":"3928b369b1ca1505c0d57340e8ffbe7549c8071b","_from":".","_npmVersion":"2.7.3","_nodeVersion":"1.5.1","_npmUser":{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"},"maintainers":[{"name":"wbinnssmith","email":"wbinnssmith@gmail.com"}],"dist":{"shasum":"3928b369b1ca1505c0d57340e8ffbe7549c8071b","size":4144,"noattachment":false,"key":"/esformatter-collapse-objects/-/esformatter-collapse-objects-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/esformatter-collapse-objects/download/esformatter-collapse-objects-0.1.0.tgz"},"directories":{},"publish_time":1427695649996,"_cnpm_publish_time":1427695649996,"_hasShrinkwrap":false}},"readme":"# esformatter-collapse-objects\n\n[esformatter](https://github.com/millermedeiros/esformatter) plugin for\nconditionally collapsing object and array literals.\n\n## Features\n* Conditionally formats literals on a single line, while leaving others expanded\n* Respects your original esformatter whitespace settings\n* Conditions include a **max line-length**, a **max number of keys/elements** in the literal,\n  a **max depth** of the literal (when it contains other objects or arrays), or when\n  it contains complex expressions like inline function expressions.\n\n\n## Usage\n\ninstall it:\n\n```sh\nnpm install esformatter-collapse-objects\n```\n\nand something like this to your esformatter config file:\n\n```json\n{\n  \"plugins\": [\n    \"esformatter-collapse-objects\"\n  ]\n}\n```\n\n### Important: Update your esformatter config\n\nThis plugin works by relying on esformatter expanding the relevant expressions,\nand conditionally collapsing them back down to a single line. Therefore, you\nneed to have esformatter expand them in the first place (esformatter defaults to\nexpanding object literals, but not array literals).\n\nAdd the following to your esformatter config when collapsing arrays:\n\n```json\n\"lineBreak\": {\n  \"before\": {\n    \"ArrayExpressionClosing\": 1\n  },\n  \"after\": {\n    \"ArrayExpressionOpening\": 1,\n    \"ArrayExpressionComma\": 1\n  }\n},\n```\n\nSince expressions were collapsed, you might be surprised that some appear as\n`{a:b,c:d}`. This is because esformatter defaults are tuned toward expanded\nexpressions. Try merging the following into your config for whitespace before\neach property in an object:\n\n```json\n{\n  \"whiteSpace\": {\n    \"before\": {\n      \"PropertyName\": 1\n    }\n}\n```\n\n## Options\n\nThe following is the default configuration for the plugin, which can be reproduced\nand modified in your .esformatter config:\n\n```json\n\n{\n  \"collapseObjects\": {\n    \"ObjectExpression\": {\n      \"maxLineLength\": 80,\n      \"maxKeys\": 3,\n      \"maxDepth\": 2,\n      \"forbidden\": [\n        \"FunctionExpression\"\n      ]\n    },\n    \"ArrayExpression\": {\n      \"maxLineLength\": 80,\n      \"maxKeys\": 3,\n      \"maxDepth\": 2,\n      \"forbidden\": [\n        \"FunctionExpression\"\n      ]\n    }\n  }\n}\n\n```\n\nOptions map esprima AST Node types (in this case both ObjectExpression and\nArrayExpression) to their respective options, just like indentation in\nesformatter.\n\n__Set either expression's value to `-1` to opt out of collapsing those nodes.__\n\n### maxLineLength (int)\nIf the literal exceeds a certain number of columns collapsed, it will *not* be collapsed.\n\n\nUse a `maxLineLength` of `-1` to ignore this option.\n\n### forbidden (Array)\nYou can also avoid collapsing literals under certain conditions\nlike a maximum number of keys, or when they contain other nodes like\nFunctionExpression.\n\n```js\n[function foo() { return 'bar' }]\n```\n\nfor example, could never occur since FunctionExpression is forbidden when\ntrying to collapse a literal if this is set.\n\n\nUse a `forbidden` of `[]` to ignore this option.\n\n### maxDepth (int)\nYou can also limit the depth of nested literals. All literals begin at a depth\nof 1, and *for performance reasons setting a maxDepth of greater than 3 is\nignored*. For example, `{foo: { bar: 'baz' }}` has a depth of two and would be\ncollapsed if the maxDepth is 2 or greater.\n\n\nUse a `maxDepth` of `-1` to opt out of this functionality.\n\n## JavaScript API\n\nRegister the plugin and call esformatter like so:\n\n```js\n// register plugin\nesformatter.register(require('esformatter-collapse-objects'));\n// pass options as second argument\nvar output = esformatter.format(str, options);\n```\n\n## License\n\nReleased under the [MIT License](http://opensource.org/licenses/MIT).\n\n## Credits\n\nHuge thanks to Jörn Zaefferer, who published [an MIT-licensed gist](https://gist.github.com/jzaefferer/23bef744ffea751b2668)\nwhich serves as the foundation for this module.\n","_attachments":{},"homepage":"https://github.com/wbinnssmith/esformatter-collapse-objects","bugs":{"url":"https://github.com/wbinnssmith/esformatter-collapse-objects"},"license":"MIT"}