{"name":"@phenomnomnominal/tsquery","version":"2.1.0","description":"Query TypeScript ASTs with the esquery API!","main":"dist/src/index.js","typings":"dist/src/index.d.ts","author":{"name":"Craig Spence","email":"craigspence0@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/phenomnomnominal/tsquery.git"},"license":"MIT","scripts":{"build":"npm run clean && npm run compile && npm run lint && npm run test","clean":"rimraf dist","compile":"tsc","lint":"npm run lint:src && npm run lint:test","lint:src":"tslint --project ./tsconfig.json -c ./tslint.json 'src/**/*.ts'","lint:test":"tslint --project ./tsconfig.json -c ./tslint.json 'test/**/*.ts'","lint:fix":"npm run lint:src:fix && npm run lint:test","lint:src:fix":"tslint -c tslint.json 'src/**/*.ts' --fix","lint:test:fix":"tslint -c tslint.json 'test/**/*.ts' --fix","test":"jest","test:debug":"node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand","prepublishOnly":"npm run build"},"dependencies":{"esquery":"^1.0.1"},"peerDependencies":{"typescript":"^2"},"devDependencies":{"@types/chai":"^4.1.4","@types/jasmine":"^2.8.8","@types/minimist":"^1.2.0","@types/node":"^10.10.1","chai":"^4.1.2","jest":"^23.6.0","rimraf":"^2.6.2","ts-jest":"^23.1.4","ts-node":"^7.0.1","tslint":"^5.11.0","typescript":"^3.0.3","webpack":"^4.19.1","webpack-cli":"^3.1.0"},"jest":{"globals":{"__TS_CONFIG__":"tsconfig.json"},"moduleFileExtensions":["ts","js"],"collectCoverage":true,"collectCoverageFrom":["<rootDir>/src/**"],"coverageDirectory":"<rootDir>/reports/coverage","transform":{"\\.(ts)$":"ts-jest"},"testRegex":"/test/.*\\.spec\\.ts$"},"gitHead":"b29a99340fa79b57a3f04abc43f7e4ef271ad800","bugs":{"url":"https://github.com/phenomnomnominal/tsquery/issues"},"homepage":"https://github.com/phenomnomnominal/tsquery#readme","_id":"@phenomnomnominal/tsquery@2.1.0","_npmVersion":"5.6.0","_nodeVersion":"9.5.0","_npmUser":{"name":"phenomnomnominal","email":"craigspence0@gmail.com"},"dist":{"integrity":"sha512-GfVvugSE0ZJTrscg6UqVpi0Kg+C/w+Alm5wGI+mzjsBLvf3ggiBSNqOzEXwb1MHpwbdfOQ8F2wgRWjCQ/8Jfzw==","shasum":"86e165f53651beb398bf3ff664daee10935a8db9","tarball":"http://registry-npm.ywwl.com/@phenomnomnominal/tsquery/download/@phenomnomnominal/tsquery-2.1.0.tgz","fileCount":78,"unpackedSize":58954,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJboNbnCRA9TVsSAnZWagAA5B0P/RVyS3Pg9mXHLG/kEdnX\nlUNVaaEE0sgJ6qU8y1YP+9VomTV71kfjEKFJQYaeckwy46vnOM40sXm9jbZ4\n/RynqJ6F+bEX3mVRmn+xaOJeSrZAUnDvRO/0j4dYa+3sj2AZGe0uWXpra38J\nZQN2T5TsmztHNaC9zfobVw7qInzAoXEbxkzVSHd76F2gapKwoAo3/wz8JGZ9\n8yKyhCQXu+8aRG8wviErCghn9TaiX93cETyPR5SQDN+V2/q9oGvrr3RIiEqW\n4NaRVpLPeh/3iHPVkeWkI/BYpl4cHJhaxTR45eJ93J1ycD/iumCYyr0Bj5JZ\nOubh5lOFdNCprFERKDlkbGub3WPXNIbXnXh3gvEOARTIbFcv9QSN0t12fZkT\nP1jju62QJJDYsWJeAQ9IZyXA05q5rztksipBP62klIncGAapOXtyw4TCv0UL\nilQj7zkmvMmXR4/+x4ZDwmhy44LXxSM3RoxsTn4ZKL8eMlfxv2vb0Mo7kydS\nCfdBoweooa4gKPHsNiPOkJF6tZLk04+IhQ/RP1yM3NNj9gE8m/2CpAkIK2/O\ncN6UZc+y3SxOHiSLRJ8ZwXQuY/XK9q0pf5sp87GQNJY0QdUCtRa++qY6nXR7\nh7wAgNuqqThYcppxo1rcXaj8ZU6k6lXLb2nN8nTpQg89Uk2k/LPI39WpLkpQ\n8o3W\r\n=TAmz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDVrMxNBmEWvcOOjdCDU4hTANzfcd47PIbs8OXgwteYOAIhANKy+/wzyyu6se+hQv5QJuYbrsBvbiUDwsXmkmDOKMrG"}],"size":16247,"noattachment":false,"key":"/@phenomnomnominal/tsquery/-/@phenomnomnominal/tsquery-2.1.0.tgz"},"maintainers":[{"name":"phenomnomnominal","email":"craigspence0@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tsquery_2.1.0_1537267431110_0.338428473174204"},"_hasShrinkwrap":false,"readme":"# TSQuery\n\n[![npm version](https://img.shields.io/npm/v/@phenomnomnominal/tsquery.svg)](https://img.shields.io/npm/v/@phenomnomnominal/tsquery.svg)\n\nTSQuery is a port of the ESQuery API for TypeScript! TSQuery allows you to query a TypeScript AST for patterns of syntax using a CSS style selector system. \n\n## Demos:\n\n[ESQuery demo](https://estools.github.io/esquery/) - note that the demo requires JavaScript code, not TypeScript\n[TSQuery demo](https://tsquery-playground.firebaseapp.com) by [Uri Shaked](https://github.com/urish)\n\n## Installation\n\n```sh\nnpm install @phenomnomnominal/tsquery --save-dev\n```\n\n## Examples\n\nSay we want to select all instances of an identifier with name \"Animal\", e.g. the identifier in the `class` declaration, and the identifier in the `extends` declaration.\n\nWe would do something like the following:\n\n```ts\nimport { ast, query } from '@phenomnomnominal/tsquery';\n\nconst typescript = `\n\nclass Animal {\n    constructor(public name: string) { }\n    move(distanceInMeters: number = 0) {\n        console.log(\\`\\${this.name} moved \\${distanceInMeters}m.\\`);\n    }\n}\n\nclass Snake extends Animal {\n    constructor(name: string) { super(name); }\n    move(distanceInMeters = 5) {\n        console.log(\"Slithering...\");\n        super.move(distanceInMeters);\n    }\n}\n\n`;\n\nconst ast = ast(typescript);\nconst nodes = query(ast, 'Identifier[name=\"Animal\"]');\nconsole.log(nodes.length); // 2\n```\n\n### Selectors\n\nThe following selectors are supported:\n\n* AST node type: `ForStatement` (see [common node types](#common-ast-node-types))\n* [wildcard](http://dev.w3.org/csswg/selectors4/#universal-selector): `*`\n* [attribute existence](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr]`\n* [attribute value](http://dev.w3.org/csswg/selectors4/#attribute-selectors): `[attr=\"foo\"]` or `[attr=123]`\n* attribute regex: `[attr=/foo.*/]`\n* attribute conditions: `[attr!=\"foo\"]`, `[attr>2]`, `[attr<3]`, `[attr>=2]`, or `[attr<=3]`\n* nested attribute: `[attr.level2=\"foo\"]`\n* field: `FunctionDeclaration > Identifier.id`\n* [First](http://dev.w3.org/csswg/selectors4/#the-first-child-pseudo) or [last](http://dev.w3.org/csswg/selectors4/#the-last-child-pseudo) child: `:first-child` or `:last-child`\n* [nth-child](http://dev.w3.org/csswg/selectors4/#the-nth-child-pseudo) (no ax+b support): `:nth-child(2)`\n* [nth-last-child](http://dev.w3.org/csswg/selectors4/#the-nth-last-child-pseudo) (no ax+b support): `:nth-last-child(1)`\n* [descendant](http://dev.w3.org/csswg/selectors4/#descendant-combinators): `ancestor descendant`\n* [child](http://dev.w3.org/csswg/selectors4/#child-combinators): `parent > child`\n* [following sibling](http://dev.w3.org/csswg/selectors4/#general-sibling-combinators): `node ~ sibling`\n* [adjacent sibling](http://dev.w3.org/csswg/selectors4/#adjacent-sibling-combinators): `node + adjacent`\n* [negation](http://dev.w3.org/csswg/selectors4/#negation-pseudo): `:not(ForStatement)`\n* [matches-any](http://dev.w3.org/csswg/selectors4/#matches): `:matches([attr] > :first-child, :last-child)`\n* [has](https://drafts.csswg.org/selectors-4/#has-pseudo): `IfStatement:has([name=\"foo\"])`\n* class of AST node: `:statement`, `:expression`, `:declaration`, `:function`, or `:pattern`\n\n### Common AST node types\n\n* `Identifier` - any identifier (name of a function, class, variable, etc)\n* `IfStatement`, `ForStatement`, `WhileStatement`, `DoStatement` - control flow\n* `FunctionDeclaration`, `ClassDeclaration`, `ArrowFunction` - declarations\n* `VariableStatement` - var, const, let.\n* `ImportDeclaration` - any `import` statement\n* `StringLiteral` - any string\n* `TrueKeyword`, `FalseKeyword`, `NullKeyword`, `AnyKeyword` - various keywords\n* `CallExpression` - function call\n* `NumericLiteral` - any numeric constant\n* `NoSubstitutionTemplateLiteral`, `TemplateExpression` - template strings and expressions\n\n## API:\n\n### `ast`:\n\nParse a string of code into an Abstract Syntax Tree which can then be queried with TSQuery Selectors.\n\n```typescript\nimport { ast } from '@phenomnomnominal/tsquery';\n\nconst sourceFile = ast('const x = 1;');\n```\n\n### `includes`:\n\nCheck for `Nodes` within a given `string` of code or AST `Node` matching a `Selector`.\n\n```typescript\nimport { includes } from '@phenomnomnominal/tsquery';\n\nconst hasIdentifier = includes('const x = 1;', 'Identifier');\n```\n\n### `map`:\n\nTransform AST `Nodes` within a given `Node` matching a `Selector`. Can be used to do `Node`-based replacement or removal of parts of the input AST.\n\n```typescript\nimport { factory } from 'typescript';\nimport { map } from '@phenomnomnominal/tsquery';\n\nconst tree = ast('const x = 1;')\nconst updatedTree = map(tree, 'Identifier', () => factory.createIdentifier('y'));\n```\n\n### `match`:\n\nFind AST `Nodes` within a given AST `Node` matching a `Selector`.\n\n```typescript\nimport { ast, match } from '@phenomnomnominal/tsquery';\n\nconst tree = ast('const x = 1;')\nconst [xNode] = match(tree, 'Identifier');\n```\n\n### `parse`:\n\nParse a `string` into an [ESQuery](https://github.com/estools/esquery) `Selector`.\n\n```typescript\nimport { parse } from '@phenomnomnominal/tsquery';\n\nconst selector = parse(':matches([attr] > :first-child, :last-child)');\n```\n\n### `print`:\n\nPrint a given `Node` or `SourceFile` to a string, using the default TypeScript printer.\n\n```typescript\nimport { print } from '@phenomnomnominal/tsquery';\nimport { factory } from 'typescript';\n\n  // create synthetic node:\nconst node = factory.createArrowFunction(\n  // ...\n);\nconst code = print(node);\n```\n\n### `project`:\n\nGet all the `SourceFiles` included in a the TypeScript project described by a given config file.\n\n```typescript\nimport { project } from '@phenomnomnominal/tsquery';\n\nconst files = project('./tsconfig.json');\n```\n\n### `files`:\n\nGet all the file paths included ina the TypeScript project described by a given config file.\n\n```typescript\nimport { files } from '@phenomnomnominal/tsquery';\n\nconst filePaths = files('./tsconfig.json');\n```\n\n### `match`:\n\nFind AST `Nodes` within a given `string` of code or AST `Node` matching a `Selector`.\n\n```typescript\nimport {query } from '@phenomnomnominal/tsquery';\n\nconst [xNode] = query('const x = 1;', 'Identifier');\n```\n\n### `replace`:\n\nTransform AST `Nodes` within a given `Node` matching a `Selector`. Can be used to do string-based replacement or removal of parts of the input AST. The updated code will be printed with the TypeScript [`Printer`](https://github.com/microsoft/TypeScript-wiki/blob/main/Using-the-Compiler-API.md#creating-and-printing-a-typescript-ast), so you may need to run your own formatter on any output code.\n\n```typescript\nimport { replace } from '@phenomnomnominal/tsquery';\n\nconst updatedCode = replace('const x = 1;', 'Identifier', () => 'y'));\n```\n","publish_time":1537267431274,"_cnpm_publish_time":1537267431274,"dist-tags":{"latest":"6.2.0"}}