{"name":"@putout/operator-declare","version":"14.0.2","keywords":["putout","putout-operator","operator","declare"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/operator-declare@14.0.2","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/operator-declare#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"5b08f9da432d0a65bd29b9024c580c343bed4491","tarball":"http://registry-npm.ywwl.com/@putout/operator-declare/download/@putout/operator-declare-14.0.2.tgz","fileCount":5,"integrity":"sha512-yiBVuOl8HC9JM9u4dSn5WxPkjYxz34ZxvTjysffq9syETjFc42e+IU9Cwzxs7ohH1BMlhirCfMjqtJR5ooZ/6w==","signatures":[{"sig":"MEUCIQCzb1sb+wrtlH0dbn4ZWE8d4rySYtfj37sZ9QEf83NTjgIgdkT50CthDKqhLmhrW8feVLEtFavlvPLKQ4Pg5iBO5E0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12087,"size":3873,"noattachment":false,"key":"/@putout/operator-declare/-/@putout/operator-declare-14.0.2.tgz"},"main":"lib/declare.js","type":"commonjs","engines":{"node":">=20"},"gitHead":"cef9ba9a8f0ad96a02615e29e3d65499eabfdcb9","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 operator adds ability to declare referenced variables that was not defined","directories":{},"_nodeVersion":"24.8.0","dependencies":{"@putout/babel":"^4.0.1","@putout/compare":"^18.0.0","@putout/operate":"^14.0.0","@putout/engine-parser":"^14.0.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","eslint":"^9.0.0","madrun":"^11.0.0","montag":"^1.2.1","nodemon":"^3.0.1","supertape":"^11.0.3","try-catch":"^3.0.0","@putout/test":"^14.0.0","eslint-plugin-n":"^17.0.0","@putout/eslint-flat":"^3.0.0","eslint-plugin-putout":"^28.0.0","@putout/plugin-nodejs":"*"},"peerDependencies":{"putout":">=40"},"_npmOperationalInternal":{"tmp":"tmp/operator-declare_14.0.2_1761488958777_0.5149085491514749","host":"s3://npm-registry-packages-npm-production"},"readme":"# @putout/operator-declare [![NPM version][NPMIMGURL]][NPMURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/operator-declare.svg?style=flat&longCache=true\n[NPMURL]: https://npmjs.org/package/@putout/operator-declare \"npm\"\n\n🐊[**Putout**](https://github.com/coderaiser/putout) operator adds ability to declare variables that has references with no definitions. Most likely you prefer using [Declarator](https://github.com/coderaiser/putout/blob/master/packages/engine-runner/README.md#Declarator) plugin type based on current Operator.\n\n## Install\n\n```\nnpm i putout @putout/operator-declare\n```\n\n## API\n\nIf you want to create 🐊[**Putout**](https://github.com/coderaiser/putout) `plugin` that will declare variables according to your needs just:\n\n```js\nimport {operator} from 'putout';\n\nconst {declare} = operator;\n\nexport const {\n    report,\n    include,\n    fix,\n    filter,\n} = declare({\n    fs: `import fs from 'fs/promises'`,\n});\n```\n\n### `nearby`\n\nBy default `@putout/operator-declare` declares variables on the top level, when you need to declare on the same level,\n\n```diff\nexport const FunctionDeclaration = {\n    print(path, printer, semantics) {\n        const {\n+           indent\n            print,\n        } = printer;\n        indent();\n    }\n}\n```\n\nUse `nearby`:\n\n```js\nconst {operator} = require('putout');\nconst {declare} = operator;\n\nexport const {\n    report,\n    include,\n    fix,\n    filter,\n} = declare({\n    indent: ['const {indent} = printer', {\n        nearby: true,\n    }],\n});\n```\n\n### Dual packages\n\nWhen you need different declarations for `ESM` and `CommonJS` you can use:\n\n```js\nconst {operator} = require('putout');\nconst {declare} = operator;\n\nexport const {\n    report,\n    include,\n    fix,\n    filter,\n} = declare({\n    fs: {\n        esm: `import fs from 'fs/promises'`,\n        comomnjs: `const fs = require('fs')`, // drop when not needed\n    },\n});\n```\n\n### Configuration\n\nPlugin supports options, so you can pass it in `.putout.json`:\n\n```json\n{\n    \"rules\": {\n        \"putout/declare\": [\"on\", {\n            \"declarations\": {\n                \"fs\": \"import fs from 'fs/promises'\"\n            }\n        }]\n    }\n}\n```\n\nIf for some reason you don't need some kind of declaration, add `dismiss` field and it will be ignored:\n\n```json\n{\n    \"rules\": {\n        \"putout/declare\": [\"on\", {\n            \"declarations\": {\n                \"fs\": \"import fs from 'fs/promises'\"\n            },\n            \"dismiss\": [\"fs\"]\n        }]\n    }\n}\n```\n\nIf you want to override `type` to avoid detecting, set it to `esm|commonjs`:\n\n```json\n{\n    \"rules\": {\n        \"putout/declare\": [\"on\", {\n            \"declarations\": {\n                \"fs\": \"import fs from 'fs/promises'\"\n            },\n            \"dismiss\": [\"fs\"],\n            \"type\": \"esm\"\n        }]\n    }\n}\n```\n\n### `top`\n\nWhen you need to put declaration on top:\n\n```diff\n+{defineProperty} = Object;\ndefineProperty(require, '__esModule', {\n    value: true,\n});\nrequire.require = require;\nconst a = require('hello');\n\nconsole.log(a);\n\nfunction require(a) {\n    return a;\n}\n```\n\nUse `nearby`:\n\n```js\nconst {operator} = require('putout');\nconst {declare} = operator;\n\nexport const {\n    report,\n    include,\n    fix,\n    filter,\n} = declare({\n    defineProperty: ['const {defineProperty} = Object', {\n        top: true,\n    }],\n});\n```\n\n### Used in\n\n- ✅ [declare](https://github.com/coderaiser/putout/tree/master/packages/plugin-declare#readme)\n- ✅ [tape/declare](https://github.com/coderaiser/putout/tree/master/packages/plugin-tape#declare)\n- ✅ [putout/declare](https://github.com/coderaiser/putout/tree/master/packages/plugin-putout#declare)\n- ✅ [nodejs/declare](https://github.com/coderaiser/putout/blob/master/packages/plugin-nodejs/#declare)\n- ✅ [react-hooks/declare](https://github.com/coderaiser/putout/blob/master/packages/plugin-react-hooks/README.md#declare)\n- ✅ [try-catch/declare](https://github.com/coderaiser/putout/blob/master/packages/plugin-try-catch/#declare)\n- ✅ [montag/declare](https://github.com/coderaiser/putout/blob/master/packages/plugin-montag/#declare)\n- ✅ [madrun/declare](https://github.com/coderaiser/putout/blob/master/packages/plugin-madrun/#declare)\n- ✅ [maybe/declare](https://github.com/coderaiser/putout/tree/master/packages/plugin-maybe#declare)\n\n### Evaluate\n\nCan be used with **ESLint's** [putout/evaluate](https://github.com/coderaiser/putout/tree/master/packages/eslint-plugin-putout/lib/evaluate#readme):\n\n```json\n{\n    \"rules\": {\n        \"putout/declare\": [\"on\", {\n            \"declarations\": {\n                \"superMethod\": \"import superMethod from '__putout_evaluate: join(`./`, basename(__filename), `.js`)'\"\n            }\n        }]\n    }\n}\n```\n\nIf you have a file `index.spec.js`:\n\n```diff\n+ import superMethod from './index.js'\nsuperMethod();\n```\n\n## License\n\nMIT\n","publish_time":1761488958968,"_cnpm_publish_time":1761488958968,"dist-tags":{"latest":"18.2.0"}}