{"name":"@putout/plugin-destructuring","version":"1.1.0","keywords":["putout","putout-plugin","plugin","destructuring"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/plugin-destructuring@1.1.0","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/plugin-destructuring#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"3fa1af64fe601bce97893bc2bdd2d710c016d1f7","tarball":"http://registry-npm.ywwl.com/@putout/plugin-destructuring/download/@putout/plugin-destructuring-1.1.0.tgz","fileCount":12,"integrity":"sha512-4EuaQAZGu+pcT4ow8sYTnS1v3Utg/OB2MAgfakJIXrPHxkM9Mzwuly5lk0Jrxk/ZORfgtWi1T4EOf1xUJfwJ9Q==","signatures":[{"sig":"MEQCICUDdi7D29FyswRERSf8G8o6uTNQGu33Pc1p8FPcccx+AiBJlC5wH0W/UwtoqB8duNN5iZ6ADkYp7wh5UHg2s3vKlw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":18236,"size":5805,"noattachment":false,"key":"/@putout/plugin-destructuring/-/@putout/plugin-destructuring-1.1.0.tgz"},"main":"lib/index.js","type":"module","engines":{"node":">=20"},"gitHead":"81d14eca64f6ec300a4c95ee4be84c18edbf5714","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","coverage":"madrun coverage","fix:lint":"madrun fix:lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"changelog":false,"repository":{"url":"git+https://github.com/coderaiser/putout.git","type":"git"},"_npmVersion":"11.4.2","description":"🐊Putout plugin adds ability to transform destructuring","directories":{},"_nodeVersion":"25.2.1","dependencies":{},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","eslint":"v10.0.0-alpha.0","madrun":"^11.0.0","nodemon":"^3.0.1","@putout/test":"^14.0.0","eslint-plugin-n":"^17.0.0","@putout/plugin-esm":"*","@putout/plugin-tape":"*","eslint-plugin-putout":"^29.0.0","@putout/plugin-minify":"*","@putout/plugin-nodejs":"*","@putout/plugin-putout":"*","@putout/plugin-declare":"*","@putout/plugin-printer":"*","@putout/plugin-declare-before-reference":"*"},"peerDependencies":{"putout":">=41"},"_npmOperationalInternal":{"tmp":"tmp/plugin-destructuring_1.1.0_1764501848613_0.22280593662763404","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/plugin-destructuring [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-destructuring.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/plugin-destructuring \"npm\"\n\n> The **destructuring** assignment syntax is a **JavaScript** expression that makes it possible to unpack values from `arrays`, or `properties` from `objects`, into distinct `variables`.\n>\n> (c) [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)\n\n🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to use **destructuring** on variable declarations.\n\n## Install\n\n```\nnpm i @putout/plugin-destructuring\n```\n\n## Rules\n\n- ✅ [apply-array](#apply-array);\n- ✅ [apply-object](#apply-object);\n- ✅ [convert-object-to-array](#convert-object-to-array);\n- ✅ [extract-properties](#extract-properties);\n- ✅ [remove-useless-object](#remove-useless-object);\n- ✅ [remove-useless-arguments](#remove-useless-arguments);\n- ✅ [remove-useless-variables](#remove-useless-variables);\n- ✅ [remove-useless-rename](#remove-useless-rename);\n- ✅ [split-nested](#split-nested);\n- ✅ [split-call](#split-call);\n- ✅ [merge-properties](#merge-properties);\n\n## Config\n\n```json\n{\n    \"rules\": {\n        \"destructuring/apply-array\": \"on\",\n        \"destructuring/apply-object\": \"on\",\n        \"destructuring/convert-object-to-array\": \"on\",\n        \"destructuring/extract-properties\": \"on\",\n        \"destructuring/remove-useless-object\": \"on\",\n        \"destructuring/remove-useless-arguments\": \"on\",\n        \"destructuring/remove-useless-variables\": \"on\",\n        \"destructuring/remove-useless-rename\": \"on\",\n        \"destructuring/split-nested\": \"on\",\n        \"destructuring/split-call\": \"on\",\n        \"destructuring/merge-properties\": \"on\"\n    }\n}\n```\n\n## apply-array\n\n### ❌ Example of incorrect code\n\n```js\nconst first = array[0];\n```\n\n### ✅ Example of correct code\n\n```js\nconst [first] = array;\n```\n\n## apply-object\n\n### ❌ Example of incorrect code\n\n```js\nconst name = user.name;\n\nhello = world.hello;\n```\n\n### ✅ Example of correct code\n\n```js\nconst {name} = user;\n\n({hello} = world);\n```\n\n## remove-useless-object\n\nCheck out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c9ed04b421d75ae39e58038fa6e14630/4c097e3173990ec7e5ebabbe2cedf8e952092ebf).\n\n### ❌ Example of incorrect code\n\n```js\nconst {maxElementsInOneLine} = {\n    options,\n};\n```\n\n### ✅ Example of correct code\n\n```js\nconst {maxElementsInOneLine} = options;\n```\n\n## remove-useless-rename\n\nCheck out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/bff12ac912bec590fece55d63af467fc/0928cb7c8403d77497e9619503caa29ca6c1538c).\n\n### ❌ Example of incorrect code\n\n```js\nconst {\n    convert: convertFn = convertFile,\n} = overrides;\n\nconvertFn('hello');\n```\n\n### ✅ Example of correct code\n\n```js\nconst {\n    convert = convertFile,\n} = overrides;\n\nconvert('hello');\n```\n\n## convert-object-to-array\n\nCheck out in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a1d26daf8bb83ee3ea1c0b62a6ad3afd/cef9b4d27c9dbb0d413a935b0359a6fe9b50364f).\n\n### ❌ Example of incorrect code\n\n```js\nconst {0: a, 1: b} = c;\n```\n\n### ✅ Example of correct code\n\n```js\nconst [a, b] = c;\n```\n\n## split-nested\n\n> - Don't use nested destructuring on data that comes from any external data sources (such as `REST API`s, `GraphQL` endpoints or files).\n> - Don't use nested destructuring on function arguments that have long or complicated signatures.\n>\n> (c) [Destructuring in JavaScript: the not so good parts](https://goodguydaniel.com/blog/destructuring-not-so-good-parts)\n\n### ❌ Example of incorrect code\n\n```js\nconst {\n    a: {\n        b,\n    },\n    a: {\n        b: x,\n    },\n} = c;\n\nfunction f({a}) {\n    const {b} = a;\n    console.log(b);\n}\n```\n\n### ✅ Example of correct code\n\n```js\nconst {a} = c;\nconst {b, b: x} = a;\n\nfunction f({a}) {\n    const {b} = a;\n    console.log(b);\n}\n```\n\n## split-call\n\n### ❌ Example of incorrect code\n\n```js\nconsole.log('hello')({uid} = path.scope);\nconsole.log('hello')[uid] = path.scope;\n```\n\n### ✅ Example of correct code\n\n```js\nconsole.log('hello');\n({uid} = path.scope);\n\nconsole.log('hello');\n[uid] = path.scope;\n```\n\n## merge-properties\n\nCheckout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/11c8cfa59f87e46238309b857448b9c5/688f10ad8fd7c0e4d9e9e0c74c399f1edb3ba29e).\n\n### ❌ Example of incorrect code\n\n```js\nconst {one} = require('numbers');\nconst {two} = require('numbers');\n\n({from} = data);\n({to} = data);\n({names} = data);\n```\n\n### ✅ Example of correct code\n\n```js\nconst {one, two} = require('numbers');\n\n({\n    from,\n    to,\n    names,\n} = data);\n```\n\n## remove-useless-arguments\n\n### ❌ Example of incorrect code\n\n```js\nonIfStatement({\n    push,\n    generate,\n    abc,\n    helloworld,\n});\n\nfunction onIfStatement({push}) {}\n```\n\n### ✅ Example of correct code\n\n```js\nonIfStatement({\n    push,\n});\n\nfunction onIfStatement({push}) {}\n```\n\n## remove-useless-variables\n\n### ❌ Example of incorrect code\n\n```js\nfunction hi(c) {\n    const {a, b} = c;\n}\n```\n\n### ✅ Example of correct code\n\n```js\nfunction hi({a, b}) {}\n```\n\n## extract-properties\n\n### Equal Deep\n\n#### ❌ Example of incorrect code\n\n```js\nconst {replaceWith} = a.operate;\nconst {isIdentifier} = a.types;\n```\n\n#### ✅ Example of correct code\n\n```js\nconst {operator, types} = a;\n\nconst {replaceWith} = operator;\nconst {isIdentifier} = types;\n```\n\n### Not Equal Deep\n\n#### ❌ Example of incorrect code\n\n```js\nconst {replaceWith} = a;\nconst {isIdentifier} = a.types;\n```\n\n#### ✅ Example of correct code\n\n```js\nconst {replaceWith, types} = a;\nconst {isIdentifier} = types;\n```\n\n## License\n\nMIT\n","publish_time":1764501848842,"_cnpm_publish_time":1764501848842,"dist-tags":{"latest":"2.1.1"}}