# transformer-query

> This is the proof-of-concept library of querying ast nodes with valid string.

Latest version **0.4.0** (published 2024-01-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install transformer-query
pnpm add transformer-query
yarn add transformer-query
bun add transformer-query
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2024-01-25 |
| First published | 2022-10-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 134.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | SieR |
| Maintainers | sier-vr |
| Keywords | typescript, ttypescript, transformer, query |

## Links

- npm: https://www.npmjs.com/package/transformer-query
- npm.io page: https://npm.io/package/transformer-query

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2024-01-25
- 0.3.3 — 2022-11-08
- 0.3.2 — 2022-11-08
- 0.3.1 — 2022-11-08
- 0.3.0 — 2022-11-08
- 0.2.1 — 2022-11-07
- 0.2.0 — 2022-11-07
- 0.1.2 — 2022-10-27
- 0.1.1 — 2022-10-27
- 0.1.0 — 2022-10-27

## README

# transformer-query

This is the proof-of-concept library of querying ast nodes with valid string. 

Thanks for ttypescript, this made it easy to develop this library.

# How to use

Install [ttypescript](https://github.com/cevek/ttypescript)

```
npm install ttypescript -D
```

And use ```ttsc``` instead of ```tsc```.

## (Optional) Register Transformer-Query Transform

**To use imported wildcard query, you should register transform.**

Just add this

```json
{
    ...
    "compilerOptions": {
        "plugins": { "transform": "transformer-query/lib/transform" }
    }
}
```

to your ```tsconfig.json```

That's it!

## Make Transform

```typescript
import { makeTransform } from "transformer-query";

export default makeTransform([
    (source, checker) => {
        ...
    }
]);

```

## Query

```typescript

import { q } from "transformer-query";

...

(source, checker) => {
    source.query(q`class ToTransform {}`)
}

...

```

### Query Wildcard

```typescript

import { q, Identifier } from "transformer-query";
import { MyClass } from "./MyClass";

...

(source, checker) => {
    source.query(q`class ${Identifier} extends ${MyClass} {}`)
}

...

```

**Note: To use Imported Wildcard, you should follow instruction on [above](#optional-register-transformer-query-transform)**

## Replacing

Transformer-Query provides five kinds of replace method.

Function Signatures

```typescript

replace(replacer: (node: ts.Node) => ts.Node): Source<T>;

replaceWith(toReplace: ts.Node): Source<T>;

replaceText(replacer: (node: ts.Node) => string): Source<T>;

replaceWithText(toReplace: string): Source<T>;

remove(): void;

```

To replace, just call replace method with call-chain.

Ex)

```typescript

...

(source, checker) => {
    source
        .query(q`class ${Identifier} {}`)
        .replaceWithText("class Transformed {}");
}

...

```

---
_Source: https://npm.io/package/transformer-query · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
