{"name":"@putout/operate","version":"15.5.0","keywords":["ast","lint","variable","unused"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@putout/operate@15.5.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":"39063ef9cb3ca61423aee069adbe76c8c9815e12","tarball":"http://registry-npm.ywwl.com/@putout/operate/download/@putout/operate-15.5.0.tgz","fileCount":29,"integrity":"sha512-PIZX8q9ieJR7lrkD2cKV2OLLccLptRg9VWUeaveQr9QQmFztMwlXCuLIgN+x+Ne0vPOBKerW+1Nt8lXGnErQHg==","signatures":[{"sig":"MEQCIER/XWxqQ7S9FOmSDGS8n1ssQkrn0NaU90utr2hXsvt/AiAA7VHmFDMbvTVtFmX2zYbg5nMjARYtrOkJR08Fv7/9ZA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":31562,"size":9090,"noattachment":false,"key":"/@putout/operate/-/@putout/operate-15.5.0.tgz"},"main":"lib/operate.js","type":"module","types":"lib/operate.d.ts","engines":{"node":">=22"},"gitHead":"1a8ee5f10e481b7ad388c1e02f010ab36c8489ec","release":false,"scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","wisdom":"madrun wisdom","coverage":"madrun coverage","fix:lint":"madrun fix:lint","test:dts":"madrun test:dts","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":"26.3.0","dependencies":{"@putout/babel":"^5.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"eslint":"^10.0.0","madrun":"^13.0.0","montag":"^2.0.0","putout":"*","nodemon":"^3.0.1","superc8":"^12.0.0","supertape":"^13.0.0","try-catch":"^4.0.0","just-camel-case":"^6.2.0","@putout/plugin-esm":"*","eslint-plugin-putout":"^31.0.0","@putout/engine-runner":"*","@putout/plugin-minify":"*","@putout/plugin-variables":"*"},"_npmOperationalInternal":{"tmp":"tmp/operate_15.5.0_1781821337199_0.901316435173688","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":1781821337344,"_cnpm_publish_time":1781821337344,"dist-tags":{"latest":"15.10.0"}}