{"name":"@putout/operate","version":"13.4.0","type":"commonjs","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"Operate on AST for 🐊 Putout","homepage":"https://github.com/coderaiser/putout/tree/master/packages/operate#readme","main":"lib/operate.js","release":false,"tag":false,"changelog":false,"repository":{"type":"git","url":"git+https://github.com/coderaiser/putout.git"},"scripts":{"test":"madrun test","watch:test":"madrun watch:test","lint":"madrun lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","fix:lint":"madrun fix:lint","coverage":"madrun coverage","report":"madrun report","wisdom":"madrun wisdom"},"dependencies":{"@putout/babel":"^3.0.0"},"keywords":["ast","lint","variable","unused"],"devDependencies":{"@putout/engine-runner":"*","@putout/eslint-flat":"^2.0.0","@putout/plugin-minify":"*","@putout/plugin-remove-unreferenced-variables":"*","c8":"^10.0.0","eslint":"^9.0.0","eslint-plugin-n":"^17.0.0","eslint-plugin-putout":"^25.0.1","just-camel-case":"^6.2.0","madrun":"^10.0.0","montag":"^1.0.0","nodemon":"^3.0.1","putout":"*","supertape":"^10.0.0","try-catch":"^3.0.0"},"license":"MIT","engines":{"node":">=18"},"publishConfig":{"access":"public"},"_id":"@putout/operate@13.4.0","gitHead":"84bce8aa35486c964cf71acdd8f5c2432d901785","bugs":{"url":"https://github.com/coderaiser/putout/issues"},"_nodeVersion":"22.14.0","_npmVersion":"11.1.0","dist":{"integrity":"sha512-HQB1DEk1p77j3+HobBNHUAsyszEodSaUArglkX1N3S8Tn2OIsKTFQUFZaHfLSsT2Yr5Pi1vrLpzZP9EwCtgZBg==","shasum":"8eea2b5c3b6af065be523c899af979576d2185bf","tarball":"http://registry-npm.ywwl.com/@putout/operate/download/@putout/operate-13.4.0.tgz","fileCount":26,"unpackedSize":28988,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC0o1clmabmxDEqrYoltX4YgUPbIU2nYVZ2MaYZWh8VCQIhAMp6xvKHP3/L2aKV1ZXHx1LANNalgYNoExtzH4ZVzCro"}],"size":8336,"noattachment":false,"key":"/@putout/operate/-/@putout/operate-13.4.0.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/operate_13.4.0_1741366764519_0.7892851010888982"},"_hasShrinkwrap":false,"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 exampes 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- `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// 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":1741366764722,"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_cnpm_publish_time":1741366764722,"dist-tags":{"latest":"15.10.0"}}