# ts-simple-ast-extra

> High level TypeScript Compiler API and refactor tools based on ts-morph (ex ts-simple-ast) library

Latest version **0.3.15** (published 2019-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-simple-ast-extra
pnpm add ts-simple-ast-extra
yarn add ts-simple-ast-extra
bun add ts-simple-ast-extra
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.15 |
| Published | 2019-10-06 |
| First published | 2018-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 209.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sebastian Gurin |
| Maintainers | cancerberosgx |
| Keywords | TypeScript, TypeScript Language Service, plugin, refactor |

## Links

- npm: https://www.npmjs.com/package/ts-simple-ast-extra
- Repository: https://github.com/cancerberoSgx/typescript-plugin-of-mine
- Homepage: https://github.com/cancerberoSgx/typescript-plugin-of-mine#readme
- Issues: https://github.com/cancerberoSgx/typescript-plugin-of-mine
- npm.io page: https://npm.io/package/ts-simple-ast-extra

## Dependencies (3)

- [ts-morph](https://npm.io/package/ts-morph.md) ^4.2.0
- [detect-indent](https://npm.io/package/detect-indent.md) ^6.0.0
- [misc-utils-of-mine-generic](https://npm.io/package/misc-utils-of-mine-generic.md) ^0.2.35

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.3.15 (latest) — 2019-10-06
- 0.3.14 — 2019-10-06
- 0.3.13 — 2019-10-06
- 0.3.12 — 2019-10-05
- 0.3.11 — 2019-08-28
- 0.3.10 — 2019-08-25
- 0.3.9 — 2019-08-25
- 0.3.8 — 2019-08-23
- 0.3.7 — 2019-08-23
- 0.3.6 — 2019-08-23
- 0.3.5 — 2019-08-23
- 0.3.4 — 2019-08-21
- 0.2.3 — 2019-08-17
- 0.2.2 — 2019-08-17
- 0.2.1 — 2019-08-16
- … 35 more at https://npm.io/package/ts-simple-ast-extra/versions

## README

# ts-simple-ast-extra

High level TypeScript Compiler API and TypeScript/JavaScript refactor APIs based on ts-morph (ex ts-simple-ast) library.

## Contents

<!-- toc -->

- [Summary](#summary)
- [Install](#install)
- [Usage](#usage)
- [Refactors](#refactors)
  * [addBracesToArrowFunctions](#addbracestoarrowfunctions)
  * [format](#format)
- [API docs](#api-docs)
- [CHANGELOG](#changelog)
- [TODO](#todo)
- [Related projects](#related-projects)

<!-- tocstop -->

## Summary

 * Browser support (out of the box)

 * Many APIs for project's **code refactors**. 
   * in general based on TypeScript built in code fixes and refactors
   * Easy to use.
   * Configurable
   * Composable
   * Have tests but use at your own risk

 * APIs useful to me that unfortunately are out of topic to pull them to in ts-morph like astPath or generalNode abstraction or 

 * utilities related with TypeScript Plugin development like abstract types, Tests Helpers, AST, repeated code, codefixes generic structure, etc

 * Access to not so public areas of TypeScript APIs or some encapsulated hacks

## Install

```
npm install ts-simple-ast-extra
```

## Usage

NOTE: Currently, although there is API documentation I would say the best source of documentation are the test. 

 * There are many different kind of APIs. Each file in src implements a "topic". 
 * Each file or "topic" has a test at `spec` folder using the same name. At the beggining there is alwasys a simple usage
`src/refactor` contain many interesting code refactors at the project level

## Refactors

In general they have the same API, you pass a SourceFile and the Project (they need access to the LanguageService):


### addBracesToArrowFunctions

```ts
import {Project, addBracesToArrowFunctions} from 'ts-simple-ast-extra'
const project = new Project()
const f = project.createSourceFile('f1.ts',  `
  const c = a => a+1
  export f = (b:number h: Date[])=>null
`)
addBracesToArrowFunctions(project, f)
console.log(f.getText())
/*
const c = a => { 
  return a + 1; 
} 
export f = (b:number h: Date[])=>{ 
  return null; 
}
*/
```

### format

```ts
import {Project, format} from 'ts-simple-ast-extra'
const project = new Project()
const file = project.createSourceFile('f2.ts',  `
function f(){
alert(1);
log(2,function(){
return 1+g(a=>{
return 2
}              )
}    );
}`)
const output = format({
  file,
  project,
  trailingSemicolons: 'never',
  indentSize: 2,
})
console.log(f.getText())
/*
function f() {
  alert(1)
  log(2, function() {
    return 1 + g(a => {
      return 2
    })
  })
}
*/
```

## API docs

[See API docs](https://cancerberosgx.github.io/typescript-plugins-of-mine/ts-simple-ast-extra/)

## CHANGELOG

[CHANGELOG.md](CHANGELOG.md)

## TODO

[TODO.md](TODO.md)

## Related projects

 * [../typescript-ast-util](typescript-ast-util) - similar objectives but independent on any library accessing directly TypeScript API

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