{"name":"@putout/operate","version":"14.1.0","keywords":["ast","lint","variable","unused"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/operate@14.1.0","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"https://github.com/coderaiser/putout/tree/master/packages/operate#readme","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"tag":false,"dist":{"shasum":"10bb17914dee243d2f53d7180bbda853f6405409","tarball":"http://registry-npm.ywwl.com/@putout/operate/download/@putout/operate-14.1.0.tgz","fileCount":28,"integrity":"sha512-0cUD1EqCxU+PEp94PqaHWq9HAUUGwrbMg/ea04QKsHNDqnfZcj2FZLXXNRjPNZIWEBBlasEDi5zfTKVrsdunFA==","signatures":[{"sig":"MEUCIHhM+cGNSnB6UvZpfoKvDUn7tDqD0cAokj9qTk5AJ8y2AiEAk7o42sRWFoAwO7RHFL9xHKB7J/JVH7MJ0E1EZVN6scM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":30220,"size":8732,"noattachment":false,"key":"/@putout/operate/-/@putout/operate-14.1.0.tgz"},"main":"lib/operate.js","type":"commonjs","engines":{"node":">=20"},"gitHead":"6affaa9bcda3d101961021e2d3121b4c660df261","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","wisdom":"madrun wisdom","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":"Operate on AST for 🐊 Putout","directories":{},"_nodeVersion":"24.6.0","dependencies":{"@putout/babel":"^4.0.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.0.0","eslint":"^9.0.0","madrun":"^11.0.0","montag":"^1.0.0","putout":"*","nodemon":"^3.0.1","supertape":"^11.0.3","try-catch":"^3.0.0","eslint-plugin-n":"^17.0.0","just-camel-case":"^6.2.0","@putout/plugin-esm":"*","@putout/eslint-flat":"^3.0.0","eslint-plugin-putout":"^28.0.0","@putout/engine-runner":"*","@putout/plugin-minify":"*","@putout/plugin-remove-unreferenced-variables":"*"},"_npmOperationalInternal":{"tmp":"tmp/operate_14.1.0_1756743965563_0.44781513245346094","host":"s3://npm-registry-packages-npm-production"},"readme":"# Operate [![NPM version][NPMIMGURL]][NPMURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]\n\n[NPMURL]: https://npmjs.org/package/putout \"npm\"\n[NPMIMGURL]: https://img.shields.io/npm/v/@putout/operate.svg?style=flat&longCache=true\n[CoverageURL]: https://coveralls.io/github/coderaiser/putout?branch=master\n[CoverageIMGURL]: https://coveralls.io/repos/coderaiser/putout/badge.svg?branch=master&service=github\n\nManipulate with `path` nodes and keep `comments` and `loc` information.\n\n## Install\n\n```\nnpm i @putout/operate\n```\n\nIf you write plugin for `putout` you already have `operator` in `putout`, all examples will get `operator` from `putout`, but you can use direct `require('@putout/operate')` as well.\n\n## API\n\n### `rename`\n\nLet's suppose you have code\n\n```js\nconst {hello} = one;\nhello();\n```\n\nYou want to change to:\n\n```js\nconst {world} = one;\nworld();\n```\n\nUse:\n\n```js\nrename(path, 'hello', 'world');\n```\n\n### `renameProperty`\n\nLet's suppose you have code\n\n```js\nconst {hello: world} = one;\n```\n\nYou want to change to:\n\n```js\nconst {world} = one;\n```\n\nUse:\n\n```js\nrenameProperty(path, 'hello', 'world');\n```\n\n### `setLiteralValue(path: Path | Node, value: string)`\n\nSet `raw` and `value` of a literal.\n\n### `isSimple(path: Path | Node)`\n\nCheck if path is:\n\n- `Literal`;\n- `Identifier`;\n- `MemberExpression`;\n- `OptionalMemberExpression`;\n\n### `extract(path)`\n\nExtract node value according to it's type::\n\n- if it is `Identifier` or `JSXIdentifier` or `JSXAttribute` return `name`;\n- if it is any type of `Literal` or `JSXText` return `value`;\n- if it is `RegExp` return `pattern`;\n- if it is `TemplateLiteral` return `qusis[0].value.raw`;\n- if it is `TemplateElement` return `value.raw`;\n- if it is `ClassMethod` return `key`;\n- if it is `TSTypeReference` return `typeName.name`;\n- if it is `TSTypeParameter` return `name`;\n- if it is `MemberExpression` return `object.property`;\n- if it is `ArrayExpression` return `element1,element2,...,elementN`;\n- if it is `TSAsExpression` return `key.expression`;\n- if it is `TSLiteralType` return `literal`;\n- `throw` in other cases\n\n### `insertAfter(path, node)`\n\nSafe way to insert `node` after `path` without duplicating comments.\n\n### `insertBefore(path, node)`\n\nSafe way to insert `node` before `path`.\n\n### `replaceWith(path, node)`\n\n```js\nconst {operator, types} = require('putout');\n\nconst {replaceWith} = operator;\nconst {ContinueStatement} = types;\n\nreplaceWith(path, continueStatement());\n```\n\n### `replaceWithMultiple(path, nodes)`\n\n```js\nconst {operator, types} = require('putout');\n\nconst {replaceWithMultiple} = operator;\nconst {\n    expressionStatement,\n    continueStatement,\n} = types;\n\nreplaceWithMultiple(path, [\n    expressionStatement(path.node.argument),\n    ContinueStatement,\n]);\n```\n\n### `isModuleExports(path)`\n\nCheck if currentPath is `module.exports` expression.\n\n### `toExpression(node)`\n\nCan be used to convert node to `expression` when building new nodes.\n\n### `remove(path)`\n\nRemove `node`, preserve comments.\n\n```js\npath.toString();\n\n// returns const [a, b] = c;\nremove(path.get('declarations.0.id.0'));\n\npath.toString(); // returns const [, b] = c;\n```\n\n### `getLiteralRaw(path: Path|Node)`\n\nGet `raw` or `extra.raw`, which can be received from `template` methods.\n\n### `getPathAfterRequires(body)`\n\nGet next `path` after latest `require`:\n\n```js\nconst programPath = path.scope.getProgramParent().path;\nconst afterRequirePath = getPathAfterRequires(programPath.get('body'));\n```\n\n### `getPathAfterImports(body)`\n\nGet next `path` after latest `ImportDeclaration`:\n\n```js\nconst programPath = path.scope.getProgramParent().path;\nconst afterImportsPath = getPathAfterImports(programPath.get('body'));\n```\n\n### `getBinding(path, name: string | Node)`\n\nGet binding (declaration of variable) by name using starting from `path` and move up.\n\n```js\ngetBinding(path, 'hello');\n```\n\n### `getBindingPath(path, name: string | Node)`\n\nGet binding `path` by name using starting from `path` and move up.\n\n```js\nconst bindingPath = getBindingPath(path, 'hello');\n\nmodule.exports.match = () => ({\n    'typeof __a === \"__b\"': ({__a}, path) => {\n        // when __a declared proceed to replace\n        return getBindingPath(path, __a);\n    },\n});\n```\n\n### `compute(path)`\n\nComputes value of expression:\n\nFor `code` like this:\n\n```js\nconst bodies = {\n    function: `typeof __a === 'function'`,\n};\n\nmodule.exports.replace = () => ({\n    [bodies.function]: 'isFn(__a)',\n});\n```\n\nYou can compute value of `bodies.function`:\n\n```js\nconst {parse, operator} = require('putout');\nconst {traverse, compute} = operator;\n\ntraverse({\n    '__a.__b': (path) => {\n        const [computed, value] = compute(path);\n        \n        // returns\n        [true, `typeof __a === 'function'`];\n    },\n});\n```\n\n### `getExportDefault(path)`\n\nGet `export default` or null.\n\n### `isESM(path)`\n\nCheck if given source is `ESM` search for `ImportDeclaration` and `ExportDeclaration` nodes.\n\n### `getProperty(path: Path, name: string)`\n\nGet property from `ObjectExpression` path:\n\n```js\nconst homepagePath = getProperty(__aPath, 'homepage');\n```\n\n### `getProperties(path: Path, names: string[])`\n\nGet properties from `ObjectExpression` path and add a `Path` suffix to each result:\n\n```js\nconst {homepagePath} = getProperties(__aPath, ['homepage']);\n```\n\n### `traverseProperties(path: Path | Node, name: string, {firstLevel?: false})`\n\nTraverse list of properties from `ObjectExpression`.\n\n```js\nconst object = template.ast('x({\"a\": \"b\"})');\nconst [propertyPath] = traverseProperties(object, 'a');\n```\n\n## License\n\nMIT\n","publish_time":1756743965775,"_cnpm_publish_time":1756743965775,"dist-tags":{"latest":"15.10.0"}}